| 292 | |
| 293 | @memoize |
| 294 | def alt(self) -> Optional[Alt]: |
| 295 | # alt: items '$' action | items '$' | items action | items |
| 296 | mark = self._mark() |
| 297 | if ( |
| 298 | (items := self.items()) |
| 299 | and |
| 300 | (literal := self.expect('$')) |
| 301 | and |
| 302 | (action := self.action()) |
| 303 | ): |
| 304 | return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = action ) |
| 305 | self._reset(mark) |
| 306 | if ( |
| 307 | (items := self.items()) |
| 308 | and |
| 309 | (literal := self.expect('$')) |
| 310 | ): |
| 311 | return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = None ) |
| 312 | self._reset(mark) |
| 313 | if ( |
| 314 | (items := self.items()) |
| 315 | and |
| 316 | (action := self.action()) |
| 317 | ): |
| 318 | return Alt ( items , action = action ) |
| 319 | self._reset(mark) |
| 320 | if ( |
| 321 | (items := self.items()) |
| 322 | ): |
| 323 | return Alt ( items , action = None ) |
| 324 | self._reset(mark) |
| 325 | return None |
| 326 | |
| 327 | @memoize |
| 328 | def items(self) -> Optional[NamedItemList]: |