
    <i/                     ^    S SK r S SKrSSKJrJr  SSKJr  SSKJr  SSK	J
r
   " S S	\5      rg)
    N   )ParseExceptionParserErrorListener   )STIXPatternLexer)STIXPatternParser)InspectionListenerc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
Pattern
   zF
Represents a pattern in a "compiled" form, for more efficient reuse.
c                 0    U R                  U5      U l        g)zr
Compile a pattern.

:param pattern_str: The pattern to compile
:raises ParseException: If there is a parse error
N)_Pattern__do_parse_Pattern__parse_tree)selfpattern_strs     S/home/james-whalen/.local/lib/python3.13/site-packages/stix2patterns/v21/pattern.py__init__Pattern.__init__   s     !OOK8    c                 X    [        5       nU R                  U5        UR                  5       $ )z
Inspect a pattern.  This gives information regarding the sorts of
operations, content, etc in use in the pattern.

:return: Pattern information
)r	   walkpattern_data)r   	inspectors     r   inspectPattern.inspect   s'     '(			)%%''r   c                 j    [         R                  R                  R                  XR                  5        g)zWalk the parse tree, using the given listener.  The listener
should be a
stix2patterns.grammars.STIXPatternListener.STIXPatternListener (or
subclass) instance.N)antlr4ParseTreeWalkerDEFAULTr   r   )r   listeners     r   r   Pattern.walk$   s$    
 	&&++H6G6GHr   c                 8    UR                  U R                  5      $ )z
Walk the parse tree using the given visitor.

:param visitor: A visitor object (STIXPatternVisitor instance)
:return: The visitor's return value
)visitr   )r   visitors     r   r#   Pattern.visit+   s     }}T..//r   c                    [         R                  " U5      n[        U5      nUR                  5         [         R                  " U5      n[        U5      nUR                  5         [        5       nUR                  U5        [         R                  " 5       Ul	        [        UR                  5       H)  u  pxUS:X  d  M  UR                  U   UR                  U'   M+      UR                  5       n	U	$ ! [         R                  R                  R                    a^  n
U
R"                  S   nUR                  R%                  X[5        [&        R(                  " [+        UR,                  5      U5         Sn
A
gSn
A
ff = f)z
Parses the given pattern and returns the antlr parse tree.

:param pattern_str: The STIX pattern
:return: The parse tree
:raises ParseException: If there is a parse error
z	<INVALID>r   N)r   InputStreamr   removeErrorListenersCommonTokenStreamr   r   addErrorListenerBailErrorStrategy_errHandler	enumerateliteralNamessymbolicNamespatternerrorErrorsParseCancellationExceptionargsreportErrorsix
raise_fromr   error_message)r   r   in_lexertoken_streamparsererror_listenerilit_nametreeereal_excs               r   
__do_parsePattern.__do_parse4   s5      - %""$//6"<0##%,./ $557
 %V%8%89KA<')/)=)=a)@##A& :	%>>#D K||""== 	% vvayH **6<
 NN>.*F*FG#% %-	%s   C- -(E3AE..E3)__parse_treeN)__name__
__module____qualname____firstlineno____doc__r   r   r   r#   r   __static_attributes__ r   r   r   r   
   s!    9(I0=%r   r   )r   r6   
exceptionsr   r   grammars.STIXPatternLexerr   grammars.STIXPatternParserr   r   r	   objectr   rL   r   r   <module>rQ      s%     
 < 7 9 )g%f g%r   