11from __future__ import annotations
22
3- from typing import (TypeVar , cast , TypeAlias , Sequence , overload , Iterable , Callable )
3+ from typing import (TypeVar , cast , Sequence , overload , Iterable , Callable )
44
55from .nodes import *
66from .token_matcher import OpM , KwdM , Matcher , PatternT
7+ from ..common import region_union , RegionUnionArgT
78from ..error import BaseParseError , BaseLocatedError
89from ..lexer import Tokenizer
910from ..operators import UNARY_OPS , COMPARISONS , ASSIGN_OPS
@@ -525,27 +526,14 @@ def _parse_or_bool(self, idx: int) -> tuple[AnyNode, int]:
525526 return self ._parse_ltr_operator_level (idx , ('||' ,), self ._parse_and_bool )
526527
527528 def err (self , msg : str , loc : RegionUnionArgT ):
528- return LocatedCstError (msg , self .region_union (loc ), self .src )
529-
530- @classmethod
531- def region_union (cls , * args : RegionUnionArgT ):
532- regs = []
533- for loc in args :
534- if isinstance (loc , (Token , AnyNode )):
535- loc = loc .region # Token and AnyNode, both have `.region`
536- if isinstance (loc , StrRegion ):
537- regs .append (loc )
538- else :
539- assert not isinstance (loc , str )
540- regs .append (cls .region_union (* loc ))
541- return StrRegion .union (* regs )
529+ return LocatedCstError (msg , region_union (loc ), self .src )
542530
543531 @classmethod
544532 def node_from_children (cls , name_or_type : str | type [AnyNamedNode ],
545533 children : list [AnyNode ],
546534 region : RegionUnionArgT = None ,
547535 parent : Node = None , arity : int = None ):
548- region = cls . region_union (region if region is not None else children )
536+ region = region_union (region if region is not None else children )
549537 if isinstance (name_or_type , str ):
550538 klass = node_cls_from_name (name_or_type , children , arity )
551539 else :
@@ -555,9 +543,6 @@ def node_from_children(cls, name_or_type: str | type[AnyNamedNode],
555543
556544CstGen = TreeGen
557545
558- RegionUnionFlatT : TypeAlias = 'Token | AnyNode | StrRegion'
559- RegionUnionArgT : TypeAlias = 'RegionUnionFlatT | Sequence[RegionUnionFlatT]'
560-
561546
562547# operator precedence (most to least binding):
563548# 1. () [] {} (parens)
0 commit comments