
V}Oc           @   s  d  Z  d d l Z d d l Z d d l m Z m Z d d l m Z m Z m	 Z	 m
 Z
 m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z m Z d d l m Z m Z m  Z  d e! f d	     YZ" d
 e! f d     YZ# d e! f d     YZ$ d e# e$ f d     YZ% d e# f d     YZ& d e! f d     YZ' d e' f d     YZ( d S(   s   ANTLR3 runtime packageiN(   t   runtime_versiont   runtime_version_str(   t   DEFAULT_CHANNELt   HIDDEN_CHANNELt   EOFt   EOR_TOKEN_TYPEt   INVALID_TOKEN_TYPE(   t   RecognitionExceptiont   MismatchedTokenExceptiont   MismatchedRangeExceptiont   MismatchedTreeNodeExceptiont   NoViableAltExceptiont   EarlyExitExceptiont   MismatchedSetExceptiont   MismatchedNotSetExceptiont   FailedPredicateExceptiont   BacktrackingFailedt   UnwantedTokenExceptiont   MissingTokenException(   t   CommonTokent	   EOF_TOKENt
   SKIP_TOKEN(   t   sett	   frozensett   reversedt   RecognizerSharedStatec           B   s   e  Z d  Z d   Z RS(   sH  
    The set of fields needed by an abstract recognizer to recognize input
    and recover from errors etc...  As a separate state object, it can be
    shared among multiple grammars; e.g., when one grammar imports another.

    These fields are publically visible but the actual state pointer per
    parser is protected.
    c         C   sy   g  |  _  t |  _ d |  _ d |  _ d  |  _ d |  _ d  |  _ d |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ d  S(   Nii    (   t	   followingt   Falset   errorRecoveryt   lastErrorIndext   backtrackingt   Nonet   ruleMemot   syntaxErrorst   tokent   tokenStartCharIndext   tokenStartLinet   tokenStartCharPositionInLinet   channelt   typet   text(   t   self(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   __init__:   s    												(   t   __name__t
   __module__t   __doc__R*   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   0   s   t   BaseRecognizerc           B   s  e  Z d  Z d Z d Z e Z e Z d- Z
 d. Z d Z d- d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d    Z& d!   Z' e( e'  Z' d"   Z) d#   Z* d$   Z+ d%   Z, d&   Z- d'   Z. d(   Z/ d)   Z0 d*   Z1 d+   Z2 d,   Z3 RS(/   s  
    @brief Common recognizer functionality.
    
    A generic recognizer that can handle recognizers generated from
    lexer, parser, and tree grammars.  This is all the parsing
    support code essentially; most of it is error recovery stuff and
    backtracking.
    iii   i    i   s   3.0.1c         C   s   d  |  _ | d  k r! t   } n  | |  _ |  j t k r[ t d |  j t |  j f   n@ |  j d k  r |  j t k r t d |  j t |  j f   n  d  S(   Ns   ANTLR version mismatch: The recognizer has been generated by V%s, but this runtime is V%s. Please use the V%s runtime or higher.i   i   i    sv   ANTLR version mismatch: The recognizer has been generated by V%s, but this runtime is V%s. Please use the V%s runtime.(   i   i   i    i    (	   R   t   inputR   t   _statet   antlr_versionR    t   RuntimeErrort   antlr_version_strR   (   R)   t   state(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR*      s"    		c         C   s   | |  _  d  S(   N(   R/   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   setInput   s    c         C   st   |  j  d k r d Sg  |  j  _ t |  j  _ d |  j  _ d |  j  _ d |  j  _ |  j  j d k	 rp i  |  j  _ n  d S(   sT   
        reset the parser's state; subclasses must rewinds the input stream
        Nii    (	   R0   R   R   R   R   R   R!   R   R    (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   reset   s    c         C   sx   |  j  |  } |  j j d  | k rD |  j j   t |  j _ | S|  j j d k r_ t  n  |  j	 | | |  } | S(   sD  
        Match current input symbol against ttype.  Attempt
        single token insertion or deletion error recovery.  If
        that fails, throw MismatchedTokenException.

        To turn off single token insertion or deletion error
        recovery, override recoverFromMismatchedToken() and have it
        throw an exception. See TreeParser.recoverFromMismatchedToken().
        This way any error in a rule will cause an exception and
        immediate exit from rule.  Rule would recover by resynchronizing
        to the set of symbols that can follow rule ref.
        i   i    (
   t   getCurrentInputSymbolR/   t   LAt   consumeR   R0   R   R   R   t   recoverFromMismatchedToken(   R)   R/   t   ttypet   followt   matchedSymbol(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   match   s    	c         C   s   t  |  j _ |  j j   d S(   s   Match the wildcard: in a symbolN(   R   R0   R   R/   R9   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   matchAny   s    c         C   s   | j  d  | k S(   Ni   (   R8   (   R)   R/   R;   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   mismatchIsUnwantedToken   s    c         C   s   | d  k r t St | k rc |  j   } | | B} t |  j j  d k rc | t t g  } qc n  | j d  | k s t | k r t	 St S(   Ni    i   (
   R   R   R   t!   computeContextSensitiveRuleFOLLOWt   lenR0   R   R   R8   t   True(   R)   R/   R<   t   viableTokensFollowingThisRule(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   mismatchIsMissingToken   s    
!c         C   sE   |  j  j r d S|  j  j d 7_ t |  j  _ |  j |  j |  d S(   st  Report a recognition problem.
            
        This method sets errorRecovery to indicate the parser is recovering
        not parsing.  Once in recovery mode, no errors are generated.
        To get out of recovery mode, the parser must successfully match
        a token (after a resync).  So it will go:

        1. error occurs
        2. enter recovery mode, report error
        3. consume until token found in resynch set
        4. try to resume parsing
        5. next match() will reset errorRecovery mode

        If you override, make sure to update syntaxErrors if you care about
        that.
        
        Ni   (   R0   R   R!   RC   t   displayRecognitionErrort
   tokenNames(   R)   t   e(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   reportError  s
    c         C   s:   |  j  |  } |  j | |  } |  j | d |  d  S(   Nt    (   t   getErrorHeadert   getErrorMessaget   emitErrorMessage(   R)   RG   RH   t   hdrt   msg(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRF   0  s    c         C   sl  t  | t  r_ d } | j t k r- d } n |  j | j } d |  j | j    | f } n	t  | t  r d } | j t k r d } n |  j | j } d | |  j | j  f } nt  | t	  rd } | j t k r d } n |  j | j } d |  j | j  d | } nOt  | t
  rld } | j t k rFd } n |  j | j } d | j | f } n t  | t  rd |  j | j  } n t  | t  rd	 |  j | j  } n t  | t  rd |  j | j  d
 t | j  } ns t  | t  r.d |  j | j  d
 t | j  } n: t  | t  r\d | j d | j d } n t |  } | S(   s  
        What error message should be generated for the various
        exception types?
        
        Not very object-oriented code, but I like having all error message
        generation within one method rather than spread among all of the
        exception classes. This also makes it much easier for the exception
        handling because the exception classes do not have to have pointers back
        to this object to access utility routines and so on. Also, changing
        the message for an exception type would be difficult because you
        would have to subclassing exception, but then somehow get ANTLR
        to make those kinds of exception objects instead of the default.
        This looks weird, but trust me--it makes the most sense in terms
        of flexibility.

        For grammar debugging, you will want to override this to add
        more information such as the stack frame with
        getRuleInvocationStack(e, this.getClass().getName()) and,
        for no viable alts, the decision description and state etc...

        Override this to change the message generated for one or more
        exception types.
        s	   <unknown>R   s    extraneous input %s expecting %ss   missing %s at %ss   mismatched input s    expecting s%   mismatched tree node: %s expecting %ss   no viable alternative at input s5   required (...)+ loop did not match anything at input s    expecting set s   rule s    failed predicate: {s   }?(   t
   isinstanceR   t	   expectingR   RG   t   getTokenErrorDisplayt   getUnexpectedTokenR   R"   R   R
   t   nodeR   R   R   t   reprR   R   t   ruleNamet   predicateTextt   str(   R)   RH   RG   t	   tokenNameRO   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRL   6  sT    			!	**c         C   s
   |  j  j S(   s.  
        Get number of recognition errors (lexer, parser, tree parser).  Each
        recognizer tracks its own number.  So parser and lexer each have
        separate count.  Does not count the spurious errors found between
        an error and next valid token match

        See also reportError()
	(   R0   R!   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getNumberOfSyntaxErrors  s    	c         C   s   d | j  | j f S(   sY   
        What is the error header, normally line/character position information?
        s
   line %d:%d(   t   linet   charPositionInLine(   R)   RH   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRK     s    c         C   sK   | j  } | d k rA | j t k r- d } qA d | j d } n  t |  S(   s  
        How should a token be displayed in an error message? The default
        is to display just the text, but during development you might
        want to have a lot of information spit out.  Override in that case
        to use t.toString() (which, for CommonToken, dumps everything about
        the token). This is better than forcing you to override a method in
        your token objects because you don't have to go modify your lexer
        so that it creates a new Java type.
        s   <EOF>t   <t   >N(   R(   R   R'   R   RU   (   R)   t   tt   s(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRR     s    		c         C   s   t  j j | d  d S(   s6   Override this method to change where error messages gos   
N(   t   syst   stderrt   write(   R)   RO   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRM     s    c         C   sk   |  j  j | j   k r% | j   n  | j   |  j  _ |  j   } |  j   |  j | |  |  j   d S(   sb  
        Recover from an error found on the input stream.  This is
        for NoViableAlt and mismatched symbol exceptions.  If you enable
        single token insertion and deletion, this will usually not
        handle mismatched symbol exceptions but there could be a mismatched
        token that the match() routine could not recover from.
        N(   R0   R   t   indexR9   t   computeErrorRecoverySett   beginResynct   consumeUntilt	   endResync(   R)   R/   t   ret	   followSet(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   recover  s    
c         C   s   d S(   s   
        A hook to listen in on the token consumption during error recovery.
        The DebugParser subclasses this to fire events to the listenter.
        N(    (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRf     s    c         C   s   d S(   s   
        A hook to listen in on the token consumption during error recovery.
        The DebugParser subclasses this to fire events to the listenter.
        N(    (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRh     s    c         C   s   |  j  t  S(   s  
        Compute the error recovery set for the current rule.  During
        rule invocation, the parser pushes the set of tokens that can
        follow that rule reference on the stack; this amounts to
        computing FIRST of what follows the rule reference in the
        enclosing rule. This local follow set only includes tokens
        from within the rule; i.e., the FIRST computation done by
        ANTLR stops at the end of a rule.

        EXAMPLE

        When you find a "no viable alt exception", the input is not
        consistent with any of the alternatives for rule r.  The best
        thing to do is to consume tokens until you see something that
        can legally follow a call to r *or* any rule that called r.
        You don't want the exact set of viable next tokens because the
        input might just be missing a token--you might consume the
        rest of the input looking for one of the missing tokens.

        Consider grammar:

        a : '[' b ']'
          | '(' b ')'
          ;
        b : c '^' INT ;
        c : ID
          | INT
          ;

        At each rule invocation, the set of tokens that could follow
        that rule is pushed on a stack.  Here are the various "local"
        follow sets:

        FOLLOW(b1_in_a) = FIRST(']') = ']'
        FOLLOW(b2_in_a) = FIRST(')') = ')'
        FOLLOW(c_in_b) = FIRST('^') = '^'

        Upon erroneous input "[]", the call chain is

        a -> b -> c

        and, hence, the follow context stack is:

        depth  local follow set     after call to rule
          0         \<EOF>                    a (from main())
          1          ']'                     b
          3          '^'                     c

        Notice that ')' is not included, because b would have to have
        been called from a different context in rule a for ')' to be
        included.

        For error recovery, we cannot consider FOLLOW(c)
        (context-sensitive or otherwise).  We need the combined set of
        all context-sensitive FOLLOW sets--the set of all tokens that
        could follow any reference in the call chain.  We need to
        resync to one of those tokens.  Note that FOLLOW(c)='^' and if
        we resync'd to that token, we'd consume until EOF.  We need to
        sync to context-sensitive FOLLOWs for a, b, and c: {']','^'}.
        In this case, for input "[]", LA(1) is in this set so we would
        not consume anything and after printing an error rule c would
        return normally.  It would not find the required '^' though.
        At this point, it gets a mismatched token error and throws an
        exception (since LA(1) is not in the viable following token
        set).  The rule exception handler tries to recover, but finds
        the same recovery set and doesn't consume anything.  Rule b
        exits normally returning to rule a.  Now it finds the ']' (and
        with the successful match exits errorRecovery mode).

        So, you cna see that the parser walks up call chain looking
        for the token that was a member of the recovery set.

        Errors are not generated in errorRecovery mode.

        ANTLR's error recovery mechanism is based upon original ideas:

        "Algorithms + Data Structures = Programs" by Niklaus Wirth

        and

        "A note on error recovery in recursive descent parsers":
        http://portal.acm.org/citation.cfm?id=947902.947905

        Later, Josef Grosch had some good ideas:

        "Efficient and Comfortable Error Recovery in Recursive Descent
        Parsers":
        ftp://www.cocolab.com/products/cocktail/doca4.ps/ell.ps.zip

        Like Grosch I implemented local FOLLOW sets that are combined
        at run-time upon error to avoid overhead during parsing.
        (   t   combineFollowsR   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRe     s    ^c         C   s   |  j  t  S(   s&	  
        Compute the context-sensitive FOLLOW set for current rule.
        This is set of token types that can follow a specific rule
        reference given a specific call chain.  You get the set of
        viable tokens that can possibly come next (lookahead depth 1)
        given the current call chain.  Contrast this with the
        definition of plain FOLLOW for rule r:

         FOLLOW(r)={x | S=>*alpha r beta in G and x in FIRST(beta)}

        where x in T* and alpha, beta in V*; T is set of terminals and
        V is the set of terminals and nonterminals.  In other words,
        FOLLOW(r) is the set of all tokens that can possibly follow
        references to r in *any* sentential form (context).  At
        runtime, however, we know precisely which context applies as
        we have the call chain.  We may compute the exact (rather
        than covering superset) set of following tokens.

        For example, consider grammar:

        stat : ID '=' expr ';'      // FOLLOW(stat)=={EOF}
             | "return" expr '.'
             ;
        expr : atom ('+' atom)* ;   // FOLLOW(expr)=={';','.',')'}
        atom : INT                  // FOLLOW(atom)=={'+',')',';','.'}
             | '(' expr ')'
             ;

        The FOLLOW sets are all inclusive whereas context-sensitive
        FOLLOW sets are precisely what could follow a rule reference.
        For input input "i=(3);", here is the derivation:

        stat => ID '=' expr ';'
             => ID '=' atom ('+' atom)* ';'
             => ID '=' '(' expr ')' ('+' atom)* ';'
             => ID '=' '(' atom ')' ('+' atom)* ';'
             => ID '=' '(' INT ')' ('+' atom)* ';'
             => ID '=' '(' INT ')' ';'

        At the "3" token, you'd have a call chain of

          stat -> expr -> atom -> expr -> atom

        What can follow that specific nested ref to atom?  Exactly ')'
        as you can see by looking at the derivation of this specific
        input.  Contrast this with the FOLLOW(atom)={'+',')',';','.'}.

        You want the exact viable token set when recovering from a
        token mismatch.  Upon token mismatch, if LA(1) is member of
        the viable next token set, then you know there is most likely
        a missing token in the input stream.  "Insert" one by just not
        throwing an exception.
        (   Rl   RC   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRA   Z  s    7c         C   s{   t    } xk t t t |  j j    D]K \ } } | | O} | r( t | k ro | d k rp | j t  qp qs Pq( q( W| S(   Ni    (   R   R   t   listt	   enumerateR0   R   R   t   remove(   R)   t   exactRj   t   idxt   localFollowSet(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRl     s    	+
c         C   s   d } |  j | |  ro t | |  } |  j   | j   |  j   |  j |  |  j |  } | j   | S|  j | |  r |  j	 | | | |  } t
 | | |  } |  j |  | St | |  } |  d S(   sn  Attempt to recover from a single missing or extra token.

        EXTRA TOKEN

        LA(1) is not what we are looking for.  If LA(2) has the right token,
        however, then assume LA(1) is some extra spurious token.  Delete it
        and LA(2) as if we were doing a normal match(), which advances the
        input.

        MISSING TOKEN

        If current token is consistent with what could come after
        ttype then it is ok to 'insert' the missing token, else throw
        exception For example, Input 'i=(3;' is clearly missing the
        ')'.  When the parser returns from the nested call to expr, it
        will have call chain:

          stat -> expr -> atom

        and it will be trying to match the ')' at this point in the
        derivation:

             => ID '=' '(' INT ')' ('+' atom)* ';'
                                ^
        match() will see that ';' doesn't match ')' and report a
        mismatched token error.  To recover, it sees that LA(1)==';'
        is in the set of tokens that can follow the ')' token
        reference in rule atom.  It can assume that you forgot the ')'.
        N(   R   R@   R   Rf   R9   Rh   RI   R7   RE   t   getMissingSymbolR   R   (   R)   R/   R;   R<   RH   R=   t   inserted(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR:     s"    



c         C   s?   |  j  | |  r5 |  j |  |  j | | t |  S|  d S(   s   Not currently usedN(   RE   RI   Rs   R   (   R)   R/   RH   R<   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   recoverFromMismatchedSet  s    c         C   s   d S(   s  
        Match needs to return the current input symbol, which gets put
        into the label for the associated token ref; e.g., x=ID.  Token
        and tree parsers need to return different objects. Rather than test
        for input stream type or change the IntStream interface, I use
        a simple method to ask the recognizer to tell me what the current
        input symbol is.

        This is ignored for lexers.
        N(   R   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR7     s    c         C   s   d S(   sQ  Conjure up a missing token during error recovery.

        The recognizer attempts to recover from single missing
        symbols. But, actions might refer to that missing symbol.
        For example, x=ID {f($x);}. The action clearly assumes
        that there has been an identifier matched previously and that
        $x points at that token. If that token is missing, but
        the next token in the stream is what we want we assume that
        this token is missing and we keep going. Because we
        have to return some token to replace the missing token,
        we have to conjure one up. This method gives the user control
        over the tokens returned for missing tokens. Mostly,
        you will want to create something special for identifier
        tokens. For literals such as '{' and ',', the default
        action in the parser or tree parser works. It simply creates
        a CommonToken of the appropriate type. The text will be the token.
        If you change what tokens must be created by the lexer,
        override this method to create the appropriate tokens.
        N(   R   (   R)   R/   RH   t   expectedTokenTypeR<   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRs     s    c         C   sr   t  | t t f  s' t | g  } n  | j d  } x5 | t k rm | | k rm | j   | j d  } q9 Wd S(   s   
        Consume tokens until one matches the given token or token set

        tokenTypes can be a single token type or a set of token types
        
        i   N(   RP   R   R   R8   R   R9   (   R)   R/   t
   tokenTypesR;   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRg   +  s    
c         C   s   |  j  |  j  S(   sG  
        Return List<String> of the rules in your parser instance
        leading up to a call to this method.  You could override if
        you want more details such as the file/line info of where
        in the parser java code a rule is invoked.

        This is very useful for error messages and for context-sensitive
        error recovery.

        You must be careful, if you subclass a generated recognizers.
        The default implementation will only search the module of self
        for rules, but the subclass will not contain any rules.
        You probably want to override this method to look like

        def getRuleInvocationStack(self):
            return self._getRuleInvocationStack(<class>.__module__)

        where <class> is the class of the generated recognizer, e.g.
        the superclass of self.
        (   t   _getRuleInvocationStackR,   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getRuleInvocationStack<  s    c         C   s   g  } x t  t j    D]n } | d j } t j |  } | d k rM q n  | j | k rb q n  | j d k rw q n  | j | j  q W| S(   sJ  
        A more general version of getRuleInvocationStack where you can
        pass in, for example, a RecognitionException to get it's rule
        stack trace.  This routine is shared with all recognizers, hence,
        static.

        TODO: move to a utility class or something; weird having lexer call
        this
        i    t	   nextTokens   <module>N(   s	   nextTokens   <module>(	   R   t   inspectt   stackt   f_codet	   getmoduleR   R+   t   co_namet   append(   t   clst   modulet   rulest   framet   codet   codeMod(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRx   U  s    c         C   s
   |  j  j S(   N(   R0   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getBacktrackingLevelz  s    c         C   s   | |  j  _ d  S(   N(   R0   R   (   R)   t   n(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   setBacktrackingLevel}  s    c         C   s
   |  j  j S(   s4   Return whether or not a backtracking attempt failed.(   R0   t   failed(   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s   |  j  S(   s   For debugging and other purposes, might want the grammar name.
        
        Have ANTLR generate an implementation for this method.
        (   t   grammarFileName(   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getGrammarFileName  s    c         C   s
   t   d  S(   N(   t   NotImplementedError(   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getSourceName  s    c         C   s*   | d k r d Sg  | D] } | j ^ q S(   sw   A convenience method for use most often with template rewrites.

        Convert a List<Token> to List<String>
        N(   R   R(   (   R)   t   tokensR"   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt	   toStrings  s    c         C   sB   | |  j  j k r% i  |  j  j | <n  |  j  j | j | |  j  S(   sg  
        Given a rule number and a start token index number, return
        MEMO_RULE_UNKNOWN if the rule has not parsed input starting from
        start index.  If this rule has parsed input starting from the
        start index before, then return where the rule stopped parsing.
        It returns the index of the last token matched by the rule.
        (   R0   R    t   gett   MEMO_RULE_UNKNOWN(   R)   t	   ruleIndext   ruleStartIndex(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getRuleMemoization  s    	c         C   sX   |  j  | | j    } | |  j k r+ t S| |  j k rC t  n | j | d  t S(   s  
        Has this rule already parsed input at the current index in the
        input stream?  Return the stop token index or MEMO_RULE_UNKNOWN.
        If we attempted but failed to parse properly before, return
        MEMO_RULE_FAILED.

        This method has a side-effect: if we have seen this input for
        this rule and successfully parsed before, then seek ahead to
        1 past the stop token matched for this rule last time.
        i   (   R   Rd   R   R   t   MEMO_RULE_FAILEDR   t   seekRC   (   R)   R/   R   t	   stopIndex(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   alreadyParsedRule  s    	c         C   sO   | r | j    d } n	 |  j } | |  j j k rK | |  j j | | <n  d S(   si   
        Record whether or not this rule parsed the input at this position
        successfully.
        i   N(   Rd   R   R0   R    (   R)   R/   R   R   t   successt   stopTokenIndex(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   memoize  s
    	c         C   s]   t  j j d | | f  |  j j d k rI t  j j d |  j j  n  t  j j d  d  S(   Ns   enter %s %si    s    backtracking=%ss   
(   Ra   t   stdoutRc   R0   R   (   R)   RV   R   t   inputSymbol(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   traceIn  s    c         C   s   t  j j d | | f  |  j j d k rI t  j j d |  j j  n  |  j j rh t  j j d  n t  j j d  t  j j d  d  S(   Ns
   exit %s %si    s    backtracking=%ss    faileds
    succeededs   
(   Ra   R   Rc   R0   R   R   (   R)   RV   R   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   traceOut  s    N(   i   i    i   i    (4   R+   R,   R-   R   R   R   t   DEFAULT_TOKEN_CHANNELR   t   HIDDENR   RG   R1   R3   R*   R5   R6   R>   R?   R@   RE   RI   RF   RL   RZ   RK   RR   RM   Rk   Rf   Rh   Re   RA   Rl   R:   Ru   R7   Rs   Rg   Ry   Rx   t   classmethodR   R   R   R   R   R   R   R   R   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR.   ~   s^   "									i										a	:		A			(			"												t   TokenSourcec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sk  
    @brief Abstract baseclass for token producers.
    
    A source of tokens must provide a sequence of tokens via nextToken()
    and also must reveal it's source of characters; CommonToken's text is
    computed from a CharStream; it only store indices into the char stream.

    Errors from the lexer are never passed to the parser.  Either you want
    to keep going or you do not upon token recognition error.  If you do not
    want to continue lexing then you do not want to continue parsing.  Just
    throw an exception not under RecognitionException and Java will naturally
    toss you all the way out of the recognizers.  If you want to continue
    lexing then you should not throw an exception to the parser--it has already
    requested a token.  Keep lexing until you get a valid one.  Just report
    errors and keep going, looking for a valid token.
    c         C   s
   t   d S(   s   Return a Token object from your input stream (usually a CharStream).
        
        Do not fail/return upon lexing error; keep chewing on the characters
        until you get a good one; errors are not passed through to the parser.
        N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRz     s    c         C   s   |  S(   s   The TokenSource is an interator.

        The iteration will not include the final EOF token, see also the note
        for the next() method.

        (    (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   __iter__  s    c         C   s4   |  j    } | d k s' | j t k r0 t  n  | S(   s   Return next token or raise StopIteration.

        Note that this will raise StopIteration when hitting the EOF token,
        so EOF will not be part of the iteration.
        
        N(   Rz   R   R'   R   t   StopIteration(   R)   R"   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   next  s    	(   R+   R,   R-   Rz   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s   	
	t   Lexerc           B   s   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d d  Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z e e e  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s'  
    @brief Baseclass for generated lexer classes.
    
    A lexer is recognizer that draws input symbols from a character stream.
    lexer grammars result in a subclass of this object. A Lexer object
    uses simplified match() and error recovery mechanisms in the interest
    of speed.
    c         C   s*   t  j |  |  t j |   | |  _ d  S(   N(   R.   R*   R   R/   (   R)   R/   R4   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR*   /  s    c         C   s   t  j |   |  j d  k	 r/ |  j j d  n  |  j d  k rB d  Sd  |  j _ t |  j _ t	 |  j _
 d |  j _ d |  j _ d |  j _ d  |  j _ d  S(   Ni    i(   R.   R6   R/   R   R   R0   R"   R   R'   R   R&   R#   R$   R%   R(   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR6   7  s    c         C   s!  xd |  j _ t |  j _ |  j j   |  j _ |  j j |  j _	 |  j j
 |  j _ d |  j _ |  j j d  t k r| t SyO |  j   |  j j d k r |  j   n |  j j t k r w n  |  j j SWq t k
 r } |  j |  |  j |  q t k
 r} |  j |  q Xq d S(   sb   
        Return a token from this source; i.e., match a token on the char
        stream.
        i   N(   R   R0   R"   R   R&   R/   Rd   R#   R\   R%   R[   R$   R(   R8   R   R   t   mTokenst   emitR   R   RI   Rk   R   (   R)   Ri   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRz   L  s*    
c         C   s   t  |  j _ d S(   sG  
        Instruct the lexer to skip creating a token for current lexer rule
        and look for another token.  nextToken() knows to keep looking when
        a lexer rule finishes with token set to SKIP_TOKEN.  Recall that
        if token==null at end of any token rule, it creates one for you
        and emits it.
        N(   R   R0   R"   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   skipp  s    	c         C   s
   t   d S(   s<   This is the lexer entry point that sets instance var 'token'N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   |  s    c         C   s    d |  _ |  j   | |  _ d S(   s'   Set the char stream and reset the lexerN(   R   R/   R6   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   setCharStream  s    	
c         C   s   |  j  j   S(   N(   R/   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s   | d k r t d |  j d |  j j d |  j j d |  j j d |  j   d  } |  j j | _	 |  j j
 | _
 |  j j | _ n  | |  j _ | S(   s  
        The standard method called to automatically emit a token at the
        outermost lexical rule.  The token object should point into the
        char buffer start..stop.  If there is a text override in 'text',
        use that to set the token's text.  Override this method to emit
        custom Token objects.

        If you are building trees, then you should also override
        Parser or TreeParser.getMissingSymbol().
        R/   R'   R&   t   startt   stopi   N(   R   R   R/   R0   R'   R&   R#   t   getCharIndexR$   R[   R(   R%   R\   R"   (   R)   R"   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    	c         C   s  t  | t  r x | D]t } |  j j d  t |  k r} |  j j d k rU t  n  t | |  j  } |  j	 |  |  n  |  j j
   q Wnn |  j j d  | k r |  j j d k r t  n  t t |  |  j  } |  j	 |  |  n  |  j j
   d  S(   Ni   i    (   RP   t
   basestringR/   R8   t   ordR0   R   R   R   Rk   R9   t   unichr(   R)   R`   t   ct   mte(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR>     s     				c         C   s   |  j  j   d  S(   N(   R/   R9   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR?     s    c         C   s   |  j  j d  | k  s0 |  j  j d  | k r |  j j d k rK t  n  t t |  t |  |  j   } |  j |  |  n  |  j  j   d  S(   Ni   i    (	   R/   R8   R0   R   R   R	   R   Rk   R9   (   R)   t   at   bt   mre(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt
   matchRange  s    0	!	c         C   s
   |  j  j S(   N(   R/   R[   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getLine  s    c         C   s
   |  j  j S(   N(   R/   R\   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getCharPositionInLine  s    c         C   s   |  j  j   S(   s8   What is the index of the current character of lookahead?(   R/   Rd   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s?   |  j  j d k	 r |  j  j S|  j j |  j  j |  j   d  S(   sd   
        Return the text matched so far for the current token or any
        text override.
        i   N(   R0   R(   R   R/   t	   substringR#   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getText  s
    
		c         C   s   | |  j  _ d S(   si   
        Set the complete text of this token; it wipes any previous
        changes to the text.
        N(   R0   R(   (   R)   R(   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   setText  s    c         C   s   |  j  |  j |  d  S(   N(   RF   RG   (   R)   RH   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRI     s    c         C   sm  d  } t | t  rB d |  j | j  d |  j | j  } n't | t  rj d |  j | j  } n t | t  r d |  j | j  } n t | t  r d |  j | j  d t	 | j  } n t | t
  rd |  j | j  d t	 | j  } ne t | t  rTd |  j | j  d |  j | j  d |  j | j  } n t j |  | |  } | S(   Ns   mismatched character s    expecting s#   no viable alternative at character s9   required (...)+ loop did not match anything at character s    expecting set s   ..(   R   RP   R   t   getCharErrorDisplayR   RQ   R   R   R   RU   R   R	   R   R   R.   RL   (   R)   RH   RG   RO   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRL   	  s"    -**Ac         C   s   | t  k r d } n  t |  S(   Ns   <EOF>(   R   RU   (   R)   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   4  s    	c         C   s   |  j  j   d S(   s2  
        Lexers can normally match any char in it's vocabulary after matching
        a token, so do the easy thing and just kill a character and hope
        it all works out.  You can instead use the rule invocation stack
        to do sophisticated error recovery if you are in a fragment rule.
        N(   R/   R9   (   R)   Ri   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRk   :  s    c         C   sE   d |  j  j d  |  j   |  j   f } t j |  | | |  d  S(   Ns   %s line=%d:%si   (   R/   t   LTR   R   R.   R   (   R)   RV   R   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   E  s    	c         C   sE   d |  j  j d  |  j   |  j   f } t j |  | | |  d  S(   Ns   %s line=%d:%si   (   R/   R   R   R   R.   R   (   R)   RV   R   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   N  s    	N(   R+   R,   R-   R   R*   R6   Rz   R   R   R   R   R   R>   R?   R   R   R   R   R   R   t   propertyR(   RI   RL   R   Rk   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   %  s0   		$														+				t   Parserc           B   sb   e  Z d  Z d
 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(   s8   
    @brief Baseclass for generated parser classes.
    c         C   s!   t  j |  |  |  j |  d  S(   N(   R.   R*   t   setTokenStream(   R)   t   lexerR4   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR*   ]  s    c         C   s3   t  j |   |  j d  k	 r/ |  j j d  n  d  S(   Ni    (   R.   R6   R/   R   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR6   c  s    c         C   s   | j  d  S(   Ni   (   R   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR7   i  s    c         C   s   | t  k r d } n d |  j | d } t d | d |  } | j d  } | j t  k ro | j d  } n  | d  k	 r | j | _ | j | _ n  t | _	 | S(   Ns   <missing EOF>s	   <missing R^   R'   R(   i   i(
   R   RG   R   R   R'   R   R[   R\   R   R&   (   R)   R/   RH   Rv   R<   t	   tokenTextR_   t   current(    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyRs   m  s    		c         C   s    d |  _ |  j   | |  _ d S(   s)   Set the token stream and reset the parserN(   R   R/   R6   (   R)   R/   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   ~  s    	
c         C   s   |  j  S(   N(   R/   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getTokenStream  s    c         C   s   |  j  j   S(   N(   R/   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s&   t  j |  | | |  j j d   d  S(   Ni   (   R.   R   R/   R   (   R)   RV   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s&   t  j |  | | |  j j d   d  S(   Ni   (   R.   R   R/   R   (   R)   RV   R   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    N(   R+   R,   R-   R   R*   R6   R7   Rs   R   R   R   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR   X  s   							t   RuleReturnScopec           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   sS   
    Rules can return start/stop info as well as possible trees and templates.
    c         C   s   d S(   s   Return the start token or tree.N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getStart  s    c         C   s   d S(   s   Return the stop token or tree.N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getStop  s    c         C   s   d S(   s&   Has a value potentially if output=AST.N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getTree  s    c         C   s   d S(   s+   Has a value potentially if output=template.N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   getTemplate  s    (   R+   R,   R-   R   R   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s
   			t   ParserRuleReturnScopec           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  
    Rules that return more than a single value must return an object
    containing all the values.  Besides the properties defined in
    RuleLabelScope.predefinedRulePropertiesScope there may be user-defined
    return values.  This class simply defines the minimum properties that
    are always defined and methods to access the others that might be
    available depending on output option such as template and tree.

    Note text is not an actual property of the return value, it is computed
    from start and stop using the input stream's toString() method.  I
    could add a ctor to this so that we can pass in and store the input
    stream, but I'm not sure we want to do that.  It would seem to be undefined
    to get the .text property anyway if the rule matches tokens from multiple
    input streams.

    I do not use getters for fields of objects that are used simply to
    group values such as this aggregate.  The getters/setters are there to
    satisfy the superclass interface.
    c         C   s   d  |  _ d  |  _ d  S(   N(   R   R   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR*     s    	c         C   s   |  j  S(   N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    c         C   s   |  j  S(   N(   R   (   R)   (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s    (   R+   R,   R-   R*   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyR     s   		()   R-   Ra   R{   t   antlr3R    R   t   antlr3.constantsR   R   R   R   R   t   antlr3.exceptionsR   R   R	   R
   R   R   R   R   R   R   R   R   t   antlr3.tokensR   R   R   t   antlr3.compatR   R   R   t   objectR   R.   R   R   R   R   R   (    (    (    s[   /afs/athena.mit.edu/user/x/a/xavid/.local/lib/python2.7/site-packages/antlr3/recognizers.pyt   <module>   s$    (RN   u5 4>