Ñò
"z$Kc        	   @   s±  d  Z  d Z d d k Z d d k Z d d d d d d	 d
 g Z d e f d „  ƒ  YZ e ƒ  Z d „  Z d „  Z	 d „  Z
 d f  d „  ƒ  YZ d f  d „  ƒ  YZ d „  Z d f  d „  ƒ  YZ d
 f  d „  ƒ  YZ e a d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d f  d  „  ƒ  YZ e d! ƒ Z e d" ƒ Z d# e f d$ „  ƒ  YZ e i d%  d% d& f j  o d' „  e d( „ Z n d	 e f d) „  ƒ  YZ d* e f d+ „  ƒ  YZ d, e f d- „  ƒ  YZ  d. e  f d/ „  ƒ  YZ! d0 „  Z" e# d1 j ov d d k$ Z$ e i% ƒ  GHe i d2 d3 j  o d4 d5 GHd6 GHn6 e$ i& ƒ  \ Z' Z( e' d2 j o d4 d5 GHd7 e( GHn n d S(8   sM   Simple Parser

Simple Parser is a simple parser generator for Python.

Parsers are:
    - recursive descendent: the rules are easy to read and understand
    - written in pure Python: the rules are simple Python expressions

Parsers are made of Python classes and operators. A parser is a
Python expression that produces a callable object.

Example: a simple 4 operation calculator
----------------------------------------

>>> def calc_parser():
...     def applyall(x, fs):
...         for f in fs: x = f(x)
...         return x
...     num = R(r'\d+') / int
...     with Separator(r'\s+'):
...         expr = Rule()
...         atom = num | '(' & expr & ')'
...         fact = Rule()
...         fact |= atom
...         fact |= ('+' & fact) / (lambda x: +x)
...         fact |= ('-' & fact) / (lambda x: -x)
...         term = ( fact & ( ('*' & fact) / (lambda y: lambda x: x*y)
...                         | ('/' & fact) / (lambda y: lambda x: x/y)
...                         )[:]
...                ) * applyall
...         expr |= ( term & ( ('+' & term) / (lambda y: lambda x: x+y)
...                          | ('-' & term) / (lambda y: lambda x: x-y)
...                          )[:]
...                 ) * applyall
...     return expr
>>> calc1 = calc_parser()
>>> calc1("1 + 2+3")
6
>>> calc1("1 + (2*3)")
7
>>> calc1("1 - (2*3)")
-5

Example: another calculator using the SP language
-------------------------------------------------

>>> from operator import add, sub, mul, truediv as div, mod
>>> op2 = lambda f, y: lambda x: f(x, y)
>>> op1 = lambda f, x: f(0, x)
>>> def red(x, fs):
...     for f in fs: x = f(x)
...     return x
>>> calc2 = compile(r'''
...         number = number.r'\d+' : `int`;
...         addop = '+' `add` | '-' `sub` ;
...         mulop = '*' `mul` | '/' `div` | '%' `mod`;
...
...         separator: r'\s+';
...
...         !expr = term (addop term :: `op2`)* :: `red`;
...         term = fact (mulop fact :: `op2`)* :: `red`;
...         fact = addop fact :: `op1` | '(' expr ')' | number;
...     ''')
>>> calc2("1 + 2+3")
6
>>> calc2("1 + (2*3)")
7
>>> calc2("1 - (2*3)")
-5
s¢  
This file is part of Simple Parser.

Simple Parser is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Simple Parser is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Simple Parser.  If not, see <http://www.gnu.org/licenses/>.
iÿÿÿÿNt   Rt   Kt   Ct   Att   Dt   Rulet	   Separatort   _Cachesc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   |  i  | ƒ d  S(   N(   t   append(   t   selft   cache(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   addf   s    c         C   s   x |  D] } | i  ƒ  q Wd  S(   N(   t   clear(   R	   R
   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   h   s     (   t   __name__t
   __module__R   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   e   s   	c           C   s   t  i ƒ  d S(   sB   clears the SP internal caches

    >>> clean(); sum(len(cache) for cache in _caches) == 0
    True
    >>> with Separator(' '): p = K('A') | 'B'
    >>> p('A')
    nil
    >>> p('B')
    nil
    >>> sum(len(cache) for cache in _caches) > 0
    True
    >>> clean(); sum(len(cache) for cache in _caches) == 0
    True
    N(   t   _cachesR   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   cleanm   s    c            sA   h  ‰  ‡ ‡  f d †  } ˆ i  | _  ˆ i | _ t i ˆ  ƒ | S(   sU    creates a memoized parser method

        arguments self, s and i are memoized.
    c            sT   y ˆ |  | | f } Wn6 t  j
 o* ˆ  |  | | ƒ } ˆ |  | | f <n X| S(   N(   t   KeyError(   R	   t   st   it   r(   t   fR
   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   _f„   s
    ((   t   __doc__R   R   R   (   R   R   (    (   R
   R   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   _memoize_self_s_i~   s    c            sA   h  ‰  ‡ ‡  f d †  } ˆ i  | _  ˆ i | _ t i ˆ  ƒ | S(   s„    creates a memoized parser method

        arguments self, s and i are memoized.
        The error argument (e) is not indexed.
    c            sW   y ˆ |  | | f } Wn9 t  j
 o- ˆ  |  | | | ƒ } ˆ |  | | f <n X| S(   N(   R   (   R	   R   R   t   eR   (   R   R
   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   –   s
    +(   R   R   R   R   (   R   R   (    (   R
   R   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   _memoize_self_s_i_e�   s    t   _posc           B   s    e  Z d  Z d „  Z d „  Z RS(   s'    computes the position in a string
    c         C   sE   | |  _  | i d d | ƒ d |  _ | | i d d | ƒ |  _ d  S(   Ns   
i    i   (   t   indext   countt   linet   rfindt   column(   R	   R   R   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __init__¤   s    	c         C   s   d |  i  |  i f S(   Ns   [%d:%d](   R   R    (   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __str__¨   s    (   R   R   R   R!   R"   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   ¡   s   	t   _errc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s8    stores the maximal position of the detected errors
    c         G   s   | |  _  t | ƒ |  _ d  S(   N(   R   t   tuplet   ts(   R	   R   R%   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   ®   s    	c            sd   ˆ  i  | i  j o ˆ  Sˆ  i  | i  j  o | St ˆ  i  ˆ  i t ‡  f d †  | i Dƒ ƒ Œ Sd  S(   Nc         3   s-   x& |  ] } | ˆ  i  j o	 | Vq q Wd  S(   N(   R%   (   t   .0t   t(   R	   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pys	   <genexpr>¸   s   	 (   R   R#   R%   R$   (   R	   t   other(    (   R	   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   max²   s
    c         C   s�   t  | |  i ƒ } d | i | i f } x[ |  i D]P } | i d ƒ o | d } n | i d ƒ o | d  } n | d | 7} q2 Wt | ƒ S(   sÝ   returns a message with the location of the error

        >>> num = R('\d+')
        >>> ident = R('\w+')
        >>> begin = 'begin'
        >>> with Separator('\s+'):
        ...     s = begin & ( num | ident )
        >>> s('18')
        Traceback (most recent call last):
            ....
        SyntaxError: [1:1] expected: begin
        >>> s('begin +18')
        Traceback (most recent call last):
            ....
        SyntaxError: [1:7] expected: \d+ \w+
        s   [%d:%d] expected:s   \bi   iþÿÿÿt    (   R   R   R   R    R%   t
   startswitht   endswitht   SyntaxError(   R	   R   t   pt   msgR'   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR/   º   s    
   (   R   R   R   R!   R)   R/   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR#   ª   s   		c         C   sD   t  |  t ƒ o |  St  |  t ƒ o t |  ƒ St d |  ƒ ‚ d S(   sx   converts 'obj' to a parser object

    A parser is not changed:
    >>> word = K('Ham') | K('Spam')
    >>> id(_p(word)) == id(word)
    True

    A string is translated into a single Keyword parser.
    >>> num = _p(r'\d+')
    >>> num.parse("42 43", 0, _err(0))[:2]
    (fail, 0)
    >>> num.parse(r"\d+ 42 43", 0, _err(0))[:2]
    (nil, 3)
    >>> kw = _p('foo')
    >>> kw.parse("foo bar", 0, _err(0))[:2]
    (nil, 3)
    >>> kw.parse("foobar", 0, _err(0))[:2]
    (fail, 0)

    Other types raise an exception:
    >>> _p(None)
    Traceback (most recent call last):
        ...
    TypeError: None is not a valid parser
    s   %s is not a valid parserN(   t
   isinstancet   Parsert   strR   t	   TypeError(   t   obj(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   _pÓ   s
      R1   c           B   sŒ   e  Z d  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z e i d
 d j  o
 e Z n d „  Z RS(   s¿   A parser shall have a parse method that:
        - trims separator before and after parsing (to allow different
            separators in a single parser)
        - recursively calls the child parsers
        - returns a tuple (value, index, error) in case of success
            if value is nil, it will be later ignored
        - returns a tuple (fail, "initial index", error) in case of failure
        error is the latest error detected.
    c         C   s   t  |  _ d  S(   N(   t
   _separatort	   separator(   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   ü   s    c         C   s   |  i  | d ƒ } |  i | | t | ƒ ƒ \ } } } |  i  | | ƒ } | t j p | t | ƒ j  o | i | ƒ ‚ n | S(   sY   removes separators before and after parsing and returns the object parsed

        >>> with Separator(r'\s+'):
        ...     num = R('\d+') / int
        ...     num[:]("   42  43     ")
        [42, 43]

        raises a SyntaxError exception when the string can not be parsed:
        >>> num("\nSpam")
        Traceback (most recent call last):
            ...
        SyntaxError: [2:1] expected: \d+

        or when their are remaining stuff not parseable:
        >>> num("\n\n42\n...")
        Traceback (most recent call last):
            ...
        SyntaxError: [4:1] expected:
        i    (   t   skipsept   parseR#   t   failt   lenR/   (   R	   R   R   t   xR   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __call__   s    $ c         C   sa   |  i  d j o | SxE t o= |  i  i | | t | ƒ ƒ \ } } } | t j o | Sq Wd S(   sœ    removes separators from a string

        >>> with Separator(r'\s'):
        ...     p = Parser()
        >>> p.skipsep("   spam   ", 0)
        3
        N(   R7   t   Nonet   TrueR9   R#   R:   (   R	   R   R   t   sepR   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR8     s    	  ' c         C   s   t  |  | ƒ S(   sÖ    returns a sequence parser

        >>> with Separator(" "): ab = R("a") & "b"
        >>> ab.parse("a b c", 0, _err(0))[:2]
        ('a', 4)
        >>> ab.parse("b a c", 0, _err(0))[:2]
        (fail, 0)
        (   t   And(   R	   R(   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __and__)  s    	c         C   s   t  | |  ƒ S(   sÖ    returns a sequence parser

        >>> with Separator(" "): ab = "a" & R("b")
        >>> ab.parse("a b c", 0, _err(0))[:2]
        ('b', 4)
        >>> ab.parse("b a c", 0, _err(0))[:2]
        (fail, 0)
        (   RA   (   R	   R(   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __rand__4  s    	c         C   s   t  |  | ƒ S(   s   returns an alternative parser

        >>> with Separator(" "): ab = R("a") | "b"
        >>> ab.parse("a b c", 0, _err(0))[:2]
        ('a', 2)
        >>> ab.parse("b a c", 0, _err(0))[:2]
        (nil, 2)
        >>> ab.parse("c a b", 0, _err(0))[:2]
        (fail, 0)
        (   t   Or(   R	   R(   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __or__?  s    c         C   s   t  | |  ƒ S(   s   returns an alternative parser

        >>> with Separator(" "): ab = "a" | R("b")
        >>> ab.parse("a b c", 0, _err(0))[:2]
        (nil, 2)
        >>> ab.parse("b a c", 0, _err(0))[:2]
        ('b', 2)
        >>> ab.parse("c a b", 0, _err(0))[:2]
        (fail, 0)
        (   RD   (   R	   R(   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __ror__L  s    c         C   s   t  |  | i | i | i ƒ S(   s_   returns a repetition parser

        Repetition is a slice:
            - start is the minimal occurrence number (default is 0)
            - stop is the maximal occurrence number (default is infinite)
            - step is the separator between each object (default is no separator)

        >>> with Separator('\s'):
        ...     item = R(r'\d+') / int
        >>> item[:].parse("1 2 3 4", 0, _err(0))[:2]
        ([1, 2, 3, 4], 7)
        >>> item[:2].parse("1 2 3 4", 0, _err(0))[:2]
        ([1, 2], 4)
        >>> item[::","].parse("1, 2, 3, 4", 0, _err(0))[:2]
        ([1, 2, 3, 4], 10)
        (   t   Rept   startt   stopt   step(   R	   t   slice(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __getitem__Y  s    c         C   s   t  |  | ƒ S(   sŠ   returns a parser that applies a function to the result of another parser

        The argument of the function is a single object.

        >>> sum = lambda xy: xy[0]+xy[1]
        >>> num = R(r'\d+') / int               # parses an integer
        >>> add = (num & '+' & num) / sum       # returns the sum of two integers
        >>> add.parse("1+2+4", 0, _err(0))[:2]
        (3, 3)
        (   t   Apply(   R	   t   func(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __truediv__l  s    i    i   c         C   s   t  |  | ƒ S(   sÐ   returns a parser that applies a function to the result of another parser

        The arguments of the function are in a list or a tuple,
        each item being given to the function as a separate argument.

        >>> sum = lambda x,y: x+y
        >>> num = R(r'\d+') / int               # parses an integer
        >>> add = (num & '+' & num) * sum       # returns the sum of two integers
        >>> add.parse("1+2+4", 0, _err(0))[:2]
        (3, 3)
        (   t	   ApplyStar(   R	   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __mul__|  s    (   R   R   R   R!   R=   R   R8   RB   RC   RE   RF   RL   RO   t   syst   version_infot   __div__RQ   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR1   ñ   s   									 
c           B   s5   e  Z d  Z d d „ Z d „  Z d d d d „ Z RS(   s˜   defines the current separator

    A classical usage is to define tokens outside a separator block
    and rules inside a separator block (for instance to discard spaces and comments).
    The separator is defined by a parser or a single string containing a regular expression.

    It is designed to be used within a 'with' block:

    >>> num = R(r'\d+')
    >>> nums = num[:]
    >>> nums.parse(" 42 43 ", 0, _err(0))[:2] # matches nothing at the very beginning of the input
    ([], 0)
    >>> with Separator(r'\s'):
    ...     nums = num[:]
    >>> nums.parse(" 42 43 ", 0, _err(0))[:2] # can match numbers after discarding spaces
    (['42', '43'], 7)
    c         C   sJ   t  | t ƒ o t | ƒ } n | d  j	 o t | ƒ } n | |  _ d  S(   N(   R0   R2   R    R>   R5   t   parser(   R	   RU   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   �  s
      c         C   s   t  |  _ |  i a  d  S(   N(   R6   t   previous_parserRU   (   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt	   __enter__¢  s    	c         C   s   |  i  a d  S(   N(   RV   R6   (   R	   t   typet   valuet	   traceback(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __exit__§  s    N(   R   R   R   R>   R!   RW   R[   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   Š  s   	c           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   sH   is a single token parser

    The token is defined by a regular expression.
    The token returns the string matched by the regular expression.

    >>> t = R(r'ham|spam')
    >>> with Separator(r'\s'): t[:]("ham ham spam")
    ['ham', 'ham', 'spam']

    If the regular expression defines groups, the parser returns
    a tuple of these groups.

    >>> t = R('<(\d+)-(\d+)>')
    >>> t("<42-43>")
    ('42', '43')

    If the regular expression defines only one group, the parser
    returns the value of this group.

    >>> t = R('<(\d+)-\d+>')
    >>> t("<42-43>")
    '42'
    i    c         C   s6   t  i |  ƒ | p | |  _ t i | | ƒ |  _ d  S(   N(   R1   R!   t   patternt   ret   compile(   R	   R\   t   flagst   name(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   Æ  s    c   	      C   sÙ   |  i  | | ƒ } |  i i | | ƒ } | p# t | | i t | |  i ƒ ƒ f S| i d ƒ } | i o1 | i	 ƒ  } t
 | ƒ d j o | d } q¡ n | } |  i  | | t
 | ƒ ƒ } | | | i t | ƒ ƒ f S(   Ni    i   (   R8   R]   t   matchR:   R)   R#   R\   t   groupt	   lastindext   groupsR;   (	   R	   R   R   R   t   i1t   tokent   matchedRY   t   rest(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   Ë  s     #
 N(   R   R   R   R>   R!   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR    ­  s   c           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s²   is a keyword parser

    Works a bit as R.

    If the pattern is a keyword (\w+)
    word boundaries are expected around the token.
    >>> t = K('ham') & C('ok')
    >>> with Separator(r'\s'): t[:].parse("ham ham hammm", 0, _err(0))[:2]
    (['ok', 'ok'], 8)

    Otherwise the pattern is escaped.
    >>> t = K('++') & C('pp')
    >>> with Separator(r'\s'): t[:].parse("++ ++ +++", 0, _err(0))[:2]
    (['pp', 'pp', 'pp'], 8)
    i    c         C   s`   t  i |  ƒ | p | |  _ | i ƒ  o d | } n t i | ƒ } t i | | ƒ |  _ d  S(   Ns   \b%s\b(   R1   R!   R\   t   isalnumR]   t   escapeR^   (   R	   R\   R_   R`   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   é  s     c         C   sM   t  i |  | | | ƒ \ } } } | t j o t | | f St | | f Sd  S(   N(   R    R9   R:   t   nil(   R	   R   R   R   R4   Rh   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   ð  s    ! N(   R   R   R   R>   R!   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   Ø  s   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s™    is a constant parser

    C parses nothing, simply returns a constant.

    >>> c = C('foo')
    >>> c.parse("spam", 0, _err(0))[:2]
    ('foo', 0)
    c         C   s   t  i |  ƒ | |  _ d  S(   N(   R1   R!   t   val(   R	   Rl   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   ÿ  s    c         C   s1   |  i  | | ƒ } |  i | | i t | ƒ ƒ f S(   N(   R8   Rl   R)   R#   (   R	   R   R   R   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9     s    (   R   R   R   R!   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   õ  s   	c           B   s   e  Z d  Z d „  Z RS(   sV   returns the current position

    >>> with Separator('\s'): p = K('a')[:] & At() & 'b'
    >>> p = p * (lambda a, p: (p.index, p.line, p.column))
    >>> p('b')
    (0, 1, 1)
    >>> p('\nb')
    (1, 2, 1)
    >>> p('a b')
    (2, 1, 3)
    >>> p('a\nb')
    (2, 2, 1)
    >>> p('a a b')
    (4, 1, 5)
    >>> p('a\na\nb')
    (4, 3, 1)
    c         C   s7   |  i  | | ƒ } t | | ƒ | | i t | ƒ ƒ f S(   N(   R8   R   R)   R#   (   R	   R   R   R   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9     s    (   R   R   R   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR     s   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sb   parses something and replaces the value by 'nil'

    Used to discard some items returned by a sequence parser.
    The sequence parser will ignore 'nil' items.

    >>> num = R(r'\d+') / int
    >>> expr = R(r'\(') & num & R(r'\)')
    >>> expr("(42)")
    ('(', 42, ')')

    >>> expr = D(R(r'\(')) & num & D(R(r'\)'))
    >>> expr("(42)")
    42
    c         C   s    t  i |  ƒ t | ƒ |  _ d  S(   N(   R1   R!   R5   RU   (   R	   RU   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   .  s    c         C   s‹   |  i  | | ƒ } |  i i | | | ƒ \ } } } | t j o t | | i t | ƒ ƒ f S|  i  | | ƒ } t | | i t | ƒ ƒ f S(   N(   R8   RU   R9   R:   R)   R#   Rk   (   R	   R   R   R   Rh   R<   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   2  s    ! (   R   R   R   R!   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR     s   	RA   c           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   s5   parses a sequence.

    Takes parsers as arguments.
    If these arguments are also sequences, the sequence is flatten.
    And(And(x,y),z) <=> And(x,And(y,z)) <=> And(x,y,z)
    or (x & y) & z <=> x & (y & z) <=> x & y & z

    The sequence returns a tuple containing the values returned by the subparsers.
    >>> s = R('a') & R('b') & R('c')
    >>> s("abc")
    ('a', 'b', 'c')
    >>> s = (R('a') & R('b')) & R('c')
    >>> s("abc")
    ('a', 'b', 'c')
    >>> s = R('a') & (R('b') & R('c'))
    >>> s("abc")
    ('a', 'b', 'c')

    Arguments may return 'nil'. Their values will be ignored.
    >>> s = R('a') & D(R('b')) & R('c')
    >>> s("abc")
    ('a', 'c')

    If the sequence returns only one argument, it is not returned in a tuple.
    >>> s = D(R('a')) & D(R('b')) & R('c')
    >>> s("abc")
    'c'
    c         G   sh   t  i |  ƒ g  |  _ xK | D]C } t | t ƒ o |  i i | i ƒ q |  i i t | ƒ ƒ q Wd  S(   N(   R1   R!   t   itemsR0   RA   t   extendR   R5   (   R	   t   parsersRU   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   W  s    	  c         C   sú   g  } |  i  | | ƒ } x‰ |  i D]~ } | i | | | ƒ \ } } } | t j o t | | i t | ƒ ƒ f S| t j	 o | i | ƒ n |  i  | | ƒ } q" Wt | ƒ d j o! | d | | i t | ƒ ƒ f St	 | ƒ | | i t | ƒ ƒ f S(   Ni   i    (
   R8   Rm   R9   R:   R)   R#   Rk   R   R;   R$   (   R	   R   R   R   t   tokensRh   t   itemRf   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   ^  s    
    !(   R   R   R   R!   R   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRA   9  s   	t
   _Singletonc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R`   (   R	   R`   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   k  s    c         C   s   |  i  S(   N(   R`   (   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __repr__l  s    (   R   R   R!   Rs   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRr   j  s   	Rk   R:   RD   c           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   s…   parses an alternative.

    Takes parsers as arguments.
    If these arguments are also alternatives, the alternative is flatten.
    Or(Or(x,y),z) <=> Or(x,Or(y,z)) <=> Or(x,y,z)
    or (x | y) | z <=> x | (y | z) <=> x | y | z

    The alternative returns the value returns by the first longest matching subparser.
    >>> s = R('a') | R('b') | R('c')
    >>> s("b")
    'b'
    >>> s = (R('a') | R('b')) | R('c')
    >>> s("b")
    'b'
    >>> s = R('a') | (R('b') | R('c'))
    >>> s("b")
    'b'
    >>> s = R('a')[:] | R('b')[:]
    >>> s('aa')
    ['a', 'a']
    >>> s('bb')
    ['b', 'b']
    >>> s('')
    []
    >>> s('ba')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:2] expected: b
    >>> s = R('a')[:] & C('branch 1') | R('a')[:] & R('b')[:] & C('branch 2')
    >>> s('aa')
    (['a', 'a'], 'branch 1')
    >>> s('aab')
    (['a', 'a'], ['b'], 'branch 2')
    c         G   sh   t  i |  ƒ g  |  _ xK | D]C } t | t ƒ o |  i i | i ƒ q |  i i t | ƒ ƒ q Wd  S(   N(   R1   R!   Rm   R0   RD   Rn   R   R5   (   R	   Ro   RU   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   ”  s    	  c   	      C   sÝ   |  i  | | ƒ } | i t | ƒ ƒ } g  } xz |  i D]o } | i | | | ƒ \ } } } | t j	 o> |  i  | | ƒ } | i t | ƒ ƒ } | i | | f ƒ q7 q7 W| o t | d d „  ƒ| f St | | f Sd  S(   Nt   keyc         S   s   |  d  S(   i   (    (   R'   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   <lambda>¨  s    (   R8   R)   R#   Rm   R9   R:   R   (	   R	   R   R   R   Re   t   matchesRq   Rf   Rh   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   ›  s    
 (   R   R   R   R!   R   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRD   p  s   "	i   i   c         C   s   |  S(    (    (   R<   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRu   ®  s    c            s   | ‡  f d †  |  Dƒ ƒ d S(   Nc         3   s%   x |  ] } ˆ  | ƒ | f Vq Wd  S(   N(    (   R&   R<   (   Rt   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pys	   <genexpr>¯  s   	 i   (    (   t   xsRt   R)   (    (   Rt   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR)   ®  s    c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sH   returns an empty parser that can be later enriched.

    Used to define recursive rules.
    The symbol can be used even before the rule is defined.
    Alternatives are added by the |= operator.

    >>> As = Rule()
    >>> A = R('A')
    >>> As |= A & As
    >>> As |= C(())
    >>> As("AAA")
    ('A', ('A', ('A', ())))
    c         C   s   t  i |  ƒ d  |  _ d  S(   N(   R1   R!   R>   RU   (   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   À  s    c         C   s<   |  i  d  j o t | ƒ |  _  n t |  i  | ƒ |  _  |  S(   N(   RU   R>   R5   RD   (   R	   RU   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __ior__Ä  s     c         C   s‹   |  i  | | ƒ } |  i i | | | ƒ \ } } } | t j o t | | i t | ƒ ƒ f S|  i  | | ƒ } | | | i t | ƒ ƒ f S(   N(   R8   RU   R9   R:   R)   R#   (   R	   R   R   R   Re   R<   Rh   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   É  s    ! (   R   R   R   R!   Rx   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   ±  s   		RG   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   parses repetitions.

    Arguments:
        min is the minimal number of iterations (default is 0)
        max is the maximal number of iterations (default is infinite)
        step is the separator parser (default is none)

    Classical repetition can be coded this way:
        A* <=> A[:] (zero or more A)
        A+ <=> A[1:] (one or more A)
        A? <=> A[:1] (zero or one A)

    >>> A = R('A')
    >>> As = A[:]
    >>> As('')
    []
    >>> As('A')
    ['A']
    >>> As('AAA')
    ['A', 'A', 'A']

    >>> As = A[1:]
    >>> As('')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:1] expected: A
    >>> As('A')
    ['A']
    >>> As('AAA')
    ['A', 'A', 'A']

    >>> As = A[:1]
    >>> As('')
    []
    >>> As('A')
    ['A']
    >>> As('AAA')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:2] expected:

    The separator provides a convenient way to parse comma separated lists for instance.
    >>> t = R(r'\w')
    >>> lst = t[::',']
    >>> lst("a,b,c")
    ['a', 'b', 'c']
    c         C   s’   t  i |  ƒ | |  _ | d  j o
 d } n | d  j o
 d } n | |  _ | |  _ | d  j o |  i |  _ n |  i |  _ t	 | ƒ |  _
 d  S(   Ni    iÿÿÿÿ(   R1   R!   RU   R>   t   minR)   t   _parse_no_sepR9   t   _parse_with_sepR5   R@   (   R	   RU   Ry   R)   R@   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!     s    	 
 
		 c         C   só   g  } d } |  i  | | ƒ } x¶ | |  i j o¥ | d 7} |  i i | | | ƒ \ } } } | t j oJ | |  i j o t | | i t | ƒ ƒ f S| | | i t | ƒ ƒ f S| i | ƒ |  i  | | ƒ } q! W| | | i t | ƒ ƒ f S(   Ni    i   (   R8   R)   RU   R9   R:   Ry   R#   R   (   R	   R   R   R   Rm   t   nRh   Rq   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRz     s     
! c   	      C   s  |  i  | | ƒ } |  i i | | | ƒ \ } } } | t j o\ d |  i j o t | | i t | ƒ ƒ f S|  i  | | ƒ } g  | | i t | ƒ ƒ f S| g } d } |  i  | | ƒ } x@| |  i j o/| d 7} |  i i | | | ƒ \ } } } | t j oJ | |  i j o t | | i t | ƒ ƒ f S| | | i t | ƒ ƒ f S|  i  | | ƒ } |  i i | | | ƒ \ } } } | t j oJ | |  i j o t | | i t | ƒ ƒ f S| | | i t | ƒ ƒ f S| i | ƒ |  i  | | ƒ } qÀ W| | | i t | ƒ ƒ f S(   Ni   (	   R8   RU   R9   R:   Ry   R)   R#   R@   R   (	   R	   R   R   R   Rh   Rq   Rm   R|   R@   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR{     s6    ! 	 
! ! (   R   R   R   R!   Rz   R{   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRG   Ð  s   /		RM   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s   applies a function to the result of a parser

    The function has one argument.

    >>> num = Apply(R(r'\d+'), int)
    >>> a = Apply(num, int)
    >>> a("42")
    42

    >>> a = Apply(num&','&num&','&num, (lambda xs: xs[0]+xs[1]+xs[2]))
    >>> a("1,2,3")
    6
    c         C   s)   t  i |  ƒ t | ƒ |  _ | |  _ d  S(   N(   R1   R!   R5   RU   RN   (   R	   RU   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   C  s    c         C   s”   |  i  | | ƒ } |  i i | | | ƒ \ } } } | t j o t | | i t | ƒ ƒ f S|  i  | | ƒ } |  i | ƒ | | i t | ƒ ƒ f S(   N(   R8   RU   R9   R:   R)   R#   RN   (   R	   R   R   R   Re   Rf   Rh   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   H  s    ! (   R   R   R   R!   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRM   4  s   	RP   c           B   s   e  Z d  Z d „  Z RS(   s7   applies a function to the result of some parsers

    The function may have several arguments.

    >>> num = Apply(R(r'\d+'), int)
    >>> a = ApplyStar(num&','&num&','&num, (lambda x,y,z: x+y+z))
    >>> a("1,2,3")
    6

    >>> a = ApplyStar(num[::','], (lambda *xs: sum(xs)))
    >>> a("1,2,3")
    6
    c         C   s”   |  i  | | ƒ } |  i i | | | ƒ \ } } } | t j o t | | i t | ƒ ƒ f S|  i  | | ƒ } |  i | Œ  | | i t | ƒ ƒ f S(   N(   R8   RU   R9   R:   R)   R#   RN   (   R	   R   R   R   Re   Rf   Rh   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR9   ^  s    ! (   R   R   R   R9   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRP   O  s   c   $   
      s=  d dI d „  ƒ  Y} d dJ d „  ƒ  Y} d dK d „  ƒ  Y} d dL d „  ƒ  Y} d	 dM d
 „  ƒ  Y} d dN d „  ƒ  Y} d dO d „  ƒ  Y} d dP d „  ƒ  Y} d dQ d „  ƒ  Y}	 d dR d „  ƒ  Y}
 d dS d „  ƒ  Y} d dT d „  ƒ  Y} d dU d „  ƒ  Y} d dV d „  ƒ  Y} d dW d „  ƒ  Y} d | f d  „  ƒ  Y} d! | f d" „  ƒ  Y} d# | f d$ „  ƒ  Y} d% dX d& „  ƒ  Y‰  d' dY ‡  f d( †  ƒ  Y} t  d) t i d* d+ ƒ| } d, } t  d- | t i d* d. ƒ| } t  d/ | t i d* d0 ƒ| } t  d1 d* d2 ƒ| } t d3 ƒ } | i ƒ  zút ƒ  } t ƒ  } t ƒ  } t ƒ  } t ƒ  } | | B| B| Bd4 | @d5 @Bd6 t | ƒ  ƒ @B} | | d7 @| O} | | d8 @| O} | | d9 @| O} | d: | @d; @| @d< @d7 @| O} | d: | @d; @| @d< @d8 @|	 O} | | O} | | | @|
 | BO} | | d= @| @| | BO} | | d> @| @| | BO} | | O} | | d? @| @| | BO} | d@ @| @dA @| }  dB | d@ @| @dA @| @}! | t dC ƒ d> @| @dA @| O} t dD ƒ dE Bd? Bd8 B}" | t dF ƒ d> @| dG dG |" … @dA @| O} |! |  B| B| }# WdG | i	 ƒ  X|# |  ƒ i
 t i dH ƒ ƒ S(Z   sî   defines a parser from a grammar

    Token definition
    ----------------

    >>> test = compile('''
    ...     name = r'\w+' ;
    ...     !S = name ;
    ... ''')
    >>> test('foo')
    'foo'
    >>> test(':foo')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:1] expected: \w+

    With specific lexer options:
    >>> test = compile('''
    ...     lexer: VERBOSE, IGNORECASE;
    ...     string = r" ' ( [^']* ) ' ";
    ...     lexer: IGNORECASE;
    ...     begin = "begin";
    ...     !S = string | begin;
    ... ''')
    >>> test("'this is a string'")
    'this is a string'
    >>> test("BeGiN")
    nil

    Keyword definition
    ------------------

    >>> test = compile('''
    ...     kw = 'begin' ;
    ...     !S = kw ;
    ... ''')
    >>> test('begin')
    nil
    >>> test('end')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:1] expected: begin

    Position computation
    --------------------

    >>> test = compile('''
    ...     separator: r'\s+';
    ...     !S = 'a'* @ 'b' :: `lambda a, p: (p.index, p.line, p.column)`;
    ... ''')
    >>> test('b')
    (0, 1, 1)
    >>> test('\nb')
    (1, 2, 1)
    >>> test('a b')
    (2, 1, 3)
    >>> test('a\nb')
    (2, 2, 1)
    >>> test('a a b')
    (4, 1, 5)
    >>> test('a\na\nb')
    (4, 3, 1)

    Repetitions
    -----------

    >>> test = compile('''
    ...     separator: ' ' ;
    ...     item = r'\w+' ;
    ...     !S = item* ;
    ... ''')
    >>> test(' ')
    []
    >>> test(' abc ')
    ['abc']
    >>> test(' abc def ')
    ['abc', 'def']
    >>> test(' abc def ghi')
    ['abc', 'def', 'ghi']

    >>> test = compile('''
    ...     separator: ' ' ;
    ...     item = r'\w+' ;
    ...     !S = item+ ;
    ... ''')
    >>> test(' ')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:2] expected: \w+
    >>> test(' abc ')
    ['abc']
    >>> test(' abc def ')
    ['abc', 'def']
    >>> test(' abc def ghi')
    ['abc', 'def', 'ghi']

    >>> test = compile('''
    ...     separator: ' ' ;
    ...     item = r'\w+' ;
    ...     !S = item? ;
    ... ''')
    >>> test(' ')
    []
    >>> test(' abc ')
    ['abc']
    >>> test(' abc def ')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:6] expected:

    >>> test = compile('''
    ...     separator: ' ';
    ...     item = r'\w+';
    ...     !S = [item / ',']*;
    ... ''')
    >>> test(' ')
    []
    >>> test('a')
    ['a']
    >>> test('a, b')
    ['a', 'b']
    >>> test('a, b, c')
    ['a', 'b', 'c']

    >>> test = compile('''
    ...     separator: ' ';
    ...     item = r'\w+';
    ...     !S = [item / ',']+;
    ... ''')
    >>> test(' ')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:2] expected: \w+
    >>> test('a')
    ['a']
    >>> test('a, b')
    ['a', 'b']
    >>> test('a, b, c')
    ['a', 'b', 'c']

    Sequences and Alternatives
    --------------------------

    >>> test = compile('''
    ...     separator: ' ' ;
    ...     A = 'A' 'A' `1` | 'A' 'B' `2` ;
    ...     A = 'A' 'C' `3` ;
    ...     !S = A ;
    ... ''')
    >>> test('A A')
    1
    >>> test('A B')
    2
    >>> test('A C')
    3
    >>> test('A D')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:3] expected: A B C

    Inline Python functions or objects
    ----------------------------------

    >>> test = compile('''
    ...     separator: ' ';
    ...     number = r'\d+' : `int` ;
    ...     couple = '(' number ',' number ')' `"a string"`
    ...              :: `lambda x,y,s: "%s: <%d,%d>"%(s,x,y)` ;
    ...     !S = couple ;
    ... ''')
    >>> test('(18, 42)')
    'a string: <18,42>'

    Rules and axiom
    ---------------

    >>> test = compile('''
    ...     separator: ' ';
    ...     !axiom = rule1 | rule2 ;
    ...     rule1 = 'A' `"rule 1 - branch 1"` ;
    ...     rule1 = 'B' `"rule 1 - branch 2"` ;
    ...     rule2 = 'A' 'A' `"rule 2 - branch 1"` ;
    ...     rule2 = 'A' 'B' `"rule 2 - branch 2"` ;
    ... ''')
    >>> test('A')
    'rule 1 - branch 1'
    >>> test('B')
    'rule 1 - branch 2'
    >>> test('A A')
    'rule 2 - branch 1'
    >>> test('A B')
    'rule 2 - branch 2'
    >>> test('A C')
    Traceback (most recent call last):
        ...
    SyntaxError: [1:3] expected: A B

    t   _Identc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R`   (   R	   R`   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   .  s    c         S   s   | |  i  S(   N(   R`   (   R	   t   symbs(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   gen/  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR}   -  s   	t   _Rec           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | d d !|  _  |  _ d  S(   Ni   iÿÿÿÿ(   R`   t   expr(   R	   R`   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   2  s    c         S   s   t  |  i d | i d |  i ƒS(   NR_   R`   (   R    R�   t   lexerR`   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   3  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR€   1  s   	t   _Kwc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | d d !|  _  |  _ d  S(   Ni   iÿÿÿÿ(   R`   Rl   (   R	   R`   Rl   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   6  s    c         S   s   t  |  i d | i d |  i ƒS(   NR_   R`   (   R   Rl   R‚   R`   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   7  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRƒ   5  s   	t   _Atc           B   s   e  Z d  „  Z RS(   c         S   s   t  ƒ  S(   N(   R   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   :  s    (   R   R   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR„   9  s   t   _Rep0Nc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R�   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   =  s    c         S   s   |  i  i | ƒ S(   N(   R�   R   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   >  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR…   <  s   	t   _Rep1Nc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R�   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   A  s    c         S   s   |  i  i | ƒ d S(   Ni   (   R�   R   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   B  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR†   @  s   	t   _Rep01c           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R�   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   E  s    c         S   s   |  i  i | ƒ d  S(   Ni   (   R�   R   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   F  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR‡   D  s   	t	   _RepSep0Nc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   R�   R@   (   R	   R�   R@   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   I  s    c         S   s)   |  i  i | ƒ d  d  |  i i | ƒ … S(   N(   R�   R   R@   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   J  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRˆ   H  s   	t	   _RepSep1Nc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   R�   R@   (   R	   R�   R@   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   M  s    c         S   s)   |  i  i | ƒ d d  |  i i | ƒ … S(   Ni   (   R�   R   R@   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   N  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR‰   L  s   	t   _Andc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   t   At   B(   R	   R‹   RŒ   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   Q  s    c         S   s    |  i  i | ƒ |  i i | ƒ @S(   N(   R‹   R   RŒ   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   R  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRŠ   P  s   	t   _Orc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   R‹   RŒ   (   R	   R‹   RŒ   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   U  s    c         S   s    |  i  i | ƒ |  i i | ƒ BS(   N(   R‹   R   RŒ   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   V  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR�   T  s   	t   _Funcc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         S   s   | d d !|  _  d  S(   Ni   iÿÿÿÿ(   R�   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   Y  s    c         S   s   t  |  i | ƒ ƒ S(   N(   R   t   genpy(   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   Z  s    c         S   s   | i  |  i ƒ S(   N(   t   evalR�   (   R	   R~   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR�   [  s    (   R   R   R!   R   R�   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRŽ   X  s   		t   _Applyc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   R�   RN   (   R	   R�   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   ^  s    c         S   s,   |  i  i | ƒ } |  i i | ƒ } | | S(   N(   R�   R   RN   R�   (   R	   R~   R�   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   _  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR‘   ]  s   	t	   _ApplyAllc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   R�   RN   (   R	   R�   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   e  s    c         S   s,   |  i  i | ƒ } |  i i | ƒ } | | S(   N(   R�   R   RN   R�   (   R	   R~   R�   RN   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   f  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR’   d  s   	t   _Rulec           B   s    e  Z e Z d  „  Z d „  Z RS(   c         S   s   | | |  _  |  _ d  S(   N(   t   identR�   (   R	   R”   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   m  s    c         S   s*   | |  i  i } | |  i i | ƒ O} d  S(   N(   R”   R`   R�   R   (   R	   R~   t   rule(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   n  s    (   R   R   t   Falset   isaxiomR!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR“   k  s   	t   _Axiomc           B   s   e  Z e Z RS(    (   R   R   R?   R—   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR˜   r  s   t
   _Separatorc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   R�   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   v  s    c         S   s&   |  i  i | ƒ } t | ƒ i ƒ  d  S(   N(   R�   R   R   RW   (   R	   R~   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   w  s    (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR™   u  s   	t   _Lexerc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   | |  _  d  S(   N(   t   opts(   R	   R›   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   |  s    c         S   sf   d | _  xV |  i D]K } t t | i ƒ } t | t ƒ p t d | ƒ ‚ n | i  | O_  q Wd  S(   Ni    s   re.%s is not an integer(   R‚   R›   t   getattrR]   R`   R0   t   intR3   (   R	   R~   t   optRl   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   }  s    	
 (   R   R   R!   R   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRš   {  s   	t   _Symbsc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         S   s.   h  |  _  | i |  _ | i |  _ d |  _ d  S(   Ni    (   R~   t	   f_globalst   globalst   f_localst   localsR‚   (   R	   t   frame(    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   †  s    	c         S   s   t  |  i ƒ S(   N(   t   iterR~   (   R	   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   __iter__‹  s    c         S   s?   y |  i  | } Wn' t j
 o t ƒ  } |  i  | <n X| S(   N(   R~   R   R   (   R	   R`   R   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRL   Œ  s
    c         S   s   t  | |  i |  i ƒ S(   N(   R�   R¡   R£   (   R	   R�   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR�   ’  s    (   R   R   R!   R¦   RL   R�   (    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyRŸ   …  s   			t   _Grammarc              s    e  Z d  „  Z ‡  f d †  Z RS(   c         S   s   | |  _  d  S(   N(   t   rules(   R	   R¨   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR!   –  s    c            s  ˆ | ƒ ‰  t  d  ƒ } | i ƒ  z% x |  i D] } | i ˆ  ƒ q/ WWd  | i ƒ  Xt ‡  f d †  ˆ  Dƒ ƒ } | o# t d d i t	 | ƒ ƒ ƒ ‚ n t d „  |  i Dƒ ƒ } t
 | ƒ d j o t d ƒ ‚ n t
 | ƒ d j o t d d i | ƒ ƒ ‚ n ˆ  | i ƒ  S(	   Nc         3   s1   x* |  ]# } ˆ  | i  d  j o	 | Vq q Wd  S(   N(   RU   R>   (   R&   R`   (   R~   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pys	   <genexpr>   s   	 s   Undefined symbols: %ss   , c         s   s-   x& |  ] } | i  o | i i Vq q Wd  S(   N(   R—   R”   R`   (   R&   R•   (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pys	   <genexpr>¢  s   	 i    s   No axiomi   s   Too many axioms: %s(   R   R>   RW   R¨   R   R[   t   sett	   NameErrort   joint   sortedR;   t   pop(   R	   R¤   R7   R•   t   emptyt   axioms(   RŸ   (   R~   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR   —  s"    

  #  (   R   R   R!   R   (    (   RŸ   (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR§   •  s   	s	   [a-z_]\w*R`   R”   sQ   
        " [^"\
]* (?: \. [^"\
]* )* "
    |   ' [^'\
]* (?: \. [^'\
]* )* '
    s   (?:(\w+)\.)?r(%s)t   regexprs   (?:(\w+)\.)?(%s)t   strings   `[^`]+`RN   s   \s+|#.*t   (t   )t   @t   *t   +t   ?t   [t   /t   ]s   ::t   :t   |t   =t   ;t   !R7   t    t   ,R‚   Ni   (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (    (   R    R]   t   It   VERBOSER   RW   R   R   R   R[   R   RR   t	   _getframe($   t   sourceR}   R€   Rƒ   R„   R…   R†   R‡   Rˆ   R‰   RŠ   R�   RŽ   R‘   R’   R“   R˜   R™   Rš   R§   R”   t   _stringR°   R±   RN   R7   t   expr_ort   expr_andt   expr_rept	   expr_funct   optionRq   R•   t   axiomt   lexsept   grammar(    (   RŸ   s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyR^   e  sj    È
  
					/""

 -t   __main__i    i   Rµ   iF   s%   Python 3 is required to run the testss   All %d tests succeeded()   R   t   __license__R]   RR   t   __all__t   listR   R   R   R   R   R   R#   R5   R1   R   R>   R6   R    R   R   R   R   RA   Rr   Rk   R:   RD   RS   R)   R   RG   RM   RP   R^   R   t   doctestt   stript   testmodt   failure_countt
   test_count(    (    (    s2   C:\Documents and Settings\grk\Desktop\asmblr\sp.pyt   <module>L   sV   					)	™!+1=d	ÿ k			