Ejemplo n.º 1
0
class BibTeXGrammar(Grammar):
    r"""Parser for a BibTeX source file.
    """
    text = Forward()
    source_hash__ = "f070f9a8eaff76cdd1669dcb63d8b8f3"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'(?i)%[^\n]*\n'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    EOF = NegativeLookahead(RegExp('(?i).'))
    WS = Alternative(Series(Lookahead(RegExp('(?i)[ \\t]*%')), wsp__), RegExp('(?i)[ \\t]+'))
    ESC = Series(Lookbehind(RegExp('(?i)\\\\')), RegExp('(?i)[%&_]'))
    CONTENT_STRING = OneOrMore(Alternative(RegExp('(?i)[^{}%&_ \\t]+'), ESC, WS))
    COMMA_TERMINATED_STRING = ZeroOrMore(Alternative(RegExp('(?i)[^,%&_ \\t]+'), ESC, WS))
    NO_BLANK_STRING = Series(OneOrMore(Alternative(RegExp('(?i)[^ \\t\\n,%&_]+'), ESC)), wsp__)
    WORD = Series(RegExp('(?i)\\w+'), wsp__)
    text.set(ZeroOrMore(Alternative(CONTENT_STRING, Series(Series(Text("{"), wsp__), text, Series(Text("}"), wsp__)))))
    plain_content = Synonym(COMMA_TERMINATED_STRING)
    content = Alternative(Series(Series(Text("{"), wsp__), text, Series(Text("}"), wsp__)), plain_content)
    field = Synonym(WORD)
    key = Synonym(NO_BLANK_STRING)
    type = Synonym(WORD)
    entry = Series(RegExp('(?i)@'), type, Series(Text("{"), wsp__), key, ZeroOrMore(Series(Series(Text(","), wsp__), field, Series(Text("="), wsp__), content, mandatory=2)), Option(Series(Text(","), wsp__)), Series(Text("}"), wsp__), mandatory=6)
    comment = Series(Series(Text("@Comment{"), wsp__), text, Series(Text("}"), wsp__), mandatory=2)
    pre_code = ZeroOrMore(Alternative(RegExp('(?i)[^"%]+'), RegExp('(?i)%.*\\n')))
    preamble = Series(Series(Text("@Preamble{"), wsp__), RegExp('(?i)"'), pre_code, RegExp('(?i)"'), wsp__, Series(Text("}"), wsp__), mandatory=5)
    bibliography = Series(ZeroOrMore(Alternative(preamble, comment, entry)), wsp__, EOF)
    root__ = bibliography
class ArithmeticRightRecursiveGrammar(Grammar):
    r"""Parser for an ArithmeticRightRecursive source file.
    """
    expression = Forward()
    term = Forward()
    source_hash__ = "c26bf1eb08a888559f192b19514bc772"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    VARIABLE = Series(RegExp('[A-Za-z]'), dwsp__)
    NUMBER = Series(RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?'), dwsp__)
    NEGATIVE = RegExp('[-]')
    POSITIVE = RegExp('[+]')
    group = Series(Series(Drop(Text("(")), dwsp__), expression,
                   Series(Drop(Text(")")), dwsp__))
    sign = Alternative(POSITIVE, NEGATIVE)
    factor = Series(Option(sign), Alternative(NUMBER, VARIABLE, group))
    div = Series(factor, Series(Drop(Text("/")), dwsp__), term)
    mul = Series(factor, Series(Drop(Text("*")), dwsp__), term)
    add = Series(term, Series(Drop(Text("+")), dwsp__), expression)
    sub = Series(term, Series(Drop(Text("-")), dwsp__), expression)
    term.set(Alternative(mul, div, factor))
    expression.set(Alternative(add, sub, term))
    root__ = expression
Ejemplo n.º 3
0
class ArithmeticSimpleGrammar(Grammar):
    r"""Parser for an ArithmeticSimple source file.
    """
    expression = Forward()
    source_hash__ = "b71be6a6745f20dda18beebbda77902b"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    VARIABLE = Series(RegExp('[A-Za-z]'), dwsp__)
    NUMBER = Series(RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?'), dwsp__)
    NEGATIVE = RegExp('[-]')
    POSITIVE = RegExp('[+]')
    div = Series(Text("/"), dwsp__)
    mul = Series(Text("*"), dwsp__)
    sub = Series(Text("-"), dwsp__)
    add = Series(Text("+"), dwsp__)
    group = Series(Series(Drop(Text("(")), dwsp__), expression, Series(Drop(Text(")")), dwsp__))
    sign = Alternative(POSITIVE, NEGATIVE)
    factor = Series(Option(sign), Alternative(NUMBER, VARIABLE, group))
    term = Series(factor, ZeroOrMore(Series(Alternative(div, mul), factor)))
    expression.set(Series(term, ZeroOrMore(Series(Alternative(add, sub), term))))
    root__ = expression
Ejemplo n.º 4
0
class yamlGrammar(Grammar):
    r"""Parser for a yaml source file.
    """
    element = Forward()
    value = Forward()
    source_hash__ = "77a7148de4df4673628ba878d0c12d19"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'(?:\/\/|#).*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    EOF = NegativeLookahead(RegExp('.'))
    EXP = Option(Series(Alternative(Text("E"), Text("e")), Option(Alternative(Text("+"), Text("-"))), RegExp('[0-9]+')))
    FRAC = Option(Series(Text("."), RegExp('[0-9]+')))
    INT = Alternative(Series(Option(Text("-")), RegExp('[0-9]')), RegExp('[1-9][0-9]+'))
    HEX = RegExp('[0-9a-fA-F]')
    ESCAPE = Alternative(RegExp('\\\\[/bnrt\\\\]'), Series(RegExp('\\\\u'), HEX, HEX, HEX, HEX))
    CHARACTERS = ZeroOrMore(Alternative(RegExp('[^"\\\\]+'), ESCAPE))
    null = Series(Text("null"), dwsp__)
    bool = Alternative(Series(RegExp('true'), dwsp__), Series(RegExp('false'), dwsp__))
    number = Series(INT, FRAC, EXP, dwsp__)
    string = Series(Text('"'), CHARACTERS, Text('"'), dwsp__)
    array = Series(Series(Drop(Text("[")), dwsp__), Option(Series(value, ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), value)))), Series(Drop(Text("]")), dwsp__))
    member = Series(string, Series(Drop(Text(":")), dwsp__), element)
    object = Series(Series(Drop(Text("{")), dwsp__), Option(Series(member, ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), member)))), Series(Drop(Text("}")), dwsp__))
    value.set(Alternative(object, array, string, number, bool, null))
    element.set(Synonym(value))
    json = Series(dwsp__, element, EOF)
    root__ = json
Ejemplo n.º 5
0
class LameArithmeticGrammar(Grammar):
    r"""Parser for a LameArithmetic source file.
    """
    expr = Forward()
    term = Forward()
    source_hash__ = "d68d04adb34c7294d6508a62e1c269d9"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r''
    comment_rx__ = RX_NEVER_MATCH
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    factor = Series(RegExp('[0-9]+'), wsp__)
    term.set(
        Alternative(
            Series(
                term,
                Alternative(Series(Text("*"), wsp__),
                            Series(Text("/"), wsp__)), factor), factor))
    expr.set(
        Alternative(
            Series(
                expr,
                Alternative(Series(Text("+"), wsp__),
                            Series(Text("-"), wsp__)), term), term))
    formula = Series(Option(Series(RegExp(''), wsp__)), expr)
    root__ = formula
Ejemplo n.º 6
0
class ArithmeticGrammar(Grammar):
    r"""Parser for an Arithmetic source file.
    """
    expression = Forward()
    source_hash__ = "63317dae9799e961704579764f281fcd"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    VARIABLE = Series(RegExp('[A-Za-z]'), dwsp__)
    NUMBER = Series(RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?'), dwsp__)
    NEGATIVE = RegExp('[-]')
    POSITIVE = RegExp('[+]')
    DIV = Series(Text("/"), dwsp__)
    MUL = Series(Text("*"), dwsp__)
    MINUS = Series(Text("-"), dwsp__)
    PLUS = Series(Text("+"), dwsp__)
    group = Series(Series(Drop(Text("(")), dwsp__), expression,
                   Series(Drop(Text(")")), dwsp__))
    sign = Alternative(POSITIVE, NEGATIVE)
    factor = Series(Option(sign), Alternative(NUMBER, VARIABLE, group),
                    ZeroOrMore(Alternative(VARIABLE, group)))
    term = Series(factor, ZeroOrMore(Series(Alternative(DIV, MUL), factor)))
    expression.set(
        Series(term, ZeroOrMore(Series(Alternative(PLUS, MINUS), term))))
    root__ = expression
Ejemplo n.º 7
0
class jsonGrammar(Grammar):
    r"""Parser for a json source file.
    """
    _element = Forward()
    source_hash__ = "69d5b7e2833481a1db43787199960580"
    disposable__ = re.compile('_[A-Za-z]+|[A-Z]+')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'(?:\/\/|#).*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    _EOF = NegativeLookahead(RegExp('.'))
    EXP = Option(
        Series(Alternative(Text("E"), Text("e")),
               Option(Alternative(Text("+"), Text("-"))), RegExp('[0-9]+')))
    DOT = Text(".")
    FRAC = Option(Series(DOT, RegExp('[0-9]+')))
    NEG = Text("-")
    INT = Series(Option(NEG),
                 Alternative(RegExp('[1-9][0-9]+'), RegExp('[0-9]')))
    HEX = RegExp('[0-9a-fA-F][0-9a-fA-F]')
    UNICODE = Series(Series(Drop(Text("\\u")), dwsp__), HEX, HEX)
    ESCAPE = Alternative(RegExp('\\\\[/bnrt\\\\]'), UNICODE)
    PLAIN = RegExp('[^"\\\\]+')
    _CHARACTERS = ZeroOrMore(Alternative(PLAIN, ESCAPE))
    null = Series(Text("null"), dwsp__)
    false = Series(Text("false"), dwsp__)
    true = Series(Text("true"), dwsp__)
    _bool = Alternative(true, false)
    number = Series(INT, FRAC, EXP, dwsp__)
    string = Series(Text('"'), _CHARACTERS, Text('"'), dwsp__, mandatory=1)
    array = Series(Series(Drop(Text("[")), dwsp__),
                   Option(
                       Series(
                           _element,
                           ZeroOrMore(
                               Series(Series(Drop(Text(",")), dwsp__),
                                      _element)))),
                   Series(Drop(Text("]")), dwsp__),
                   mandatory=2)
    member = Series(string,
                    Series(Drop(Text(":")), dwsp__),
                    _element,
                    mandatory=1)
    object = Series(Series(Drop(Text("{")), dwsp__),
                    member,
                    ZeroOrMore(
                        Series(Series(Drop(Text(",")), dwsp__),
                               member,
                               mandatory=1)),
                    Series(Drop(Text("}")), dwsp__),
                    mandatory=3)
    _element.set(Alternative(object, array, string, number, _bool, null))
    json = Series(dwsp__, _element, _EOF)
    root__ = json
Ejemplo n.º 8
0
class ArithmeticRightRecursiveGrammar(Grammar):
    r"""Parser for an ArithmeticRightRecursive source file.
    """
    element = Forward()
    expression = Forward()
    tail = Forward()
    term = Forward()
    source_hash__ = "34a84d77ec6f6b92070f9e4fd0a5d3ca"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    VARIABLE = RegExp('[a-dj-z]')
    NUMBER = RegExp('(?:0|(?:[1-9]\\d*))(?:\\.\\d+)?')
    MINUS = RegExp('-')
    PLUS = RegExp('\\+')
    i = Text("i")
    e = Text("e")
    pi = Alternative(Text("pi"), Text("π"))
    special = Alternative(pi, e)
    number = Synonym(NUMBER)
    log = Series(Series(Drop(Text('log(')), dwsp__), expression, Text(")"), mandatory=1)
    tan = Series(Series(Drop(Text('tan(')), dwsp__), expression, Text(")"), mandatory=1)
    cos = Series(Series(Drop(Text('cos(')), dwsp__), expression, Text(")"), mandatory=1)
    sin = Series(Series(Drop(Text('sin(')), dwsp__), expression, Text(")"), mandatory=1)
    function = Alternative(sin, cos, tan, log)
    group = Series(Text("("), expression, Text(")"), mandatory=1)
    tail_value = Alternative(special, function, VARIABLE, group)
    tail_pow = Series(tail_value, Option(i), Text("^"), element)
    tail_elem = Alternative(tail_pow, tail_value)
    value = Series(Alternative(number, tail_value), Option(i))
    sign = Alternative(PLUS, MINUS)
    add = Series(term, Series(Drop(Text("+")), dwsp__), expression)
    pow = Series(value, Text("^"), Option(sign), element)
    seq = Series(tail_elem, tail)
    sub = Series(term, Series(Drop(Text("-")), dwsp__), expression)
    factor = Series(Option(sign), Alternative(Series(Option(element), tail), element), dwsp__)
    div = Series(factor, Series(Drop(Text("/")), dwsp__), term)
    mul = Series(factor, Series(Drop(Text("*")), dwsp__), term)
    element.set(Alternative(pow, value))
    tail.set(Series(Alternative(seq, tail_elem), Option(i)))
    term.set(Alternative(mul, div, factor))
    expression.set(Alternative(add, sub, term))
    root__ = expression
Ejemplo n.º 9
0
class neuGrammar(Grammar):
    r"""Parser for a neu source file.
    """
    source_hash__ = "1d30885075846ae11867008e6c2647de"
    anonymous__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    EOF = NegativeLookahead(RegExp('.'))
    WORD = Series(RegExp('\\w+'), wsp__)
    document = Series(wsp__, ZeroOrMore(WORD), EOF, mandatory=2)
    root__ = document
Ejemplo n.º 10
0
class atfGrammar(Grammar):
    r"""Parser for an atf source file.
    """
    source_hash__ = "4ae7748240bfd917fc406c93eb9214f7"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'#.*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    EOF = NegativeLookahead(RegExp('.'))
    WORD = Series(RegExp('\\w+'), wsp__)
    document = Series(wsp__, ZeroOrMore(WORD), EOF, mandatory=2)
    root__ = document
Ejemplo n.º 11
0
class LyrikGrammar(Grammar):
    r"""Parser for a Lyrik source file.
    """
    source_hash__ = "26385fa0fbbe6e28b8b15d563a5407c9"
    disposable__ = re.compile('JAHRESZAHL$|ZEICHENFOLGE$|ENDE$|LEERRAUM$|ziel$|wortfolge$')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r''
    comment_rx__ = RX_NEVER_MATCH
    WHITESPACE__ = r'[\t ]*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    ENDE = Drop(NegativeLookahead(RegExp('.')))
    JAHRESZAHL = RegExp('\\d\\d\\d\\d')
    LEERRAUM = Drop(RegExp('\\s+'))
    LEERZEILEN = RegExp('\\n(?:[ \\t]*\\n)+')
    L = RegExp(' +')
    ZW = RegExp('\\n')
    ZEICHENFOLGE = RegExp('[^ \\n<>]+')
    NAME = RegExp('\\w+\\.?')
    WORT = RegExp('\\w+')
    TEXT = Synonym(ZEICHENFOLGE)
    zeile = Series(dwsp__, TEXT, ZeroOrMore(Series(L, TEXT)), dwsp__)
    vers = Synonym(zeile)
    strophe = Series(vers, OneOrMore(Series(ZW, vers)))
    text = Series(strophe, ZeroOrMore(Series(LEERZEILEN, strophe)))
    titel = Synonym(zeile)
    gedicht = Series(titel, LEERZEILEN, text, mandatory=2)
    serie = Series(NegativeLookahead(Series(titel, vers, ZW, vers)), dwsp__, zeile, ZeroOrMore(Series(ZW, zeile)))
    ziel = Series(ZEICHENFOLGE, dwsp__)
    verknüpfung = Series(Series(Drop(Text("<")), dwsp__), ziel, Series(Drop(Text(">")), dwsp__))
    wortfolge = Series(WORT, ZeroOrMore(Series(L, WORT)), dwsp__)
    jahr = Series(JAHRESZAHL, dwsp__)
    ortsname = Synonym(wortfolge)
    ort = Series(ortsname, Option(verknüpfung))
    untertitel = Synonym(wortfolge)
    werktitel = Synonym(wortfolge)
    werk = Series(werktitel, Option(Series(Series(Drop(Text(".")), dwsp__), untertitel, mandatory=1)), Option(verknüpfung))
    name = Series(NAME, ZeroOrMore(Series(L, NAME)), dwsp__)
    autor = Series(name, Option(verknüpfung))
    bibliographisches = Series(autor, Series(Drop(Text(",")), dwsp__), Option(Series(ZW, dwsp__)), werk, Series(Drop(Text(",")), dwsp__), Option(Series(ZW, dwsp__)), ort, Series(Drop(Text(",")), dwsp__), Option(Series(ZW, dwsp__)), jahr, Series(Drop(Text(".")), dwsp__), mandatory=1)
    Dokument = Series(Option(LEERRAUM), bibliographisches, LEERZEILEN, Option(serie), OneOrMore(Series(LEERZEILEN, gedicht)), Option(LEERRAUM), ENDE, mandatory=1)
    root__ = Dokument
Ejemplo n.º 12
0
class XMLSnippetGrammar(Grammar):
    r"""Parser for a XMLSnippet source file.
    """
    element = Forward()
    source_hash__ = "ebb52cf647bba2d2f543c86dd3590dbe"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r''
    comment_rx__ = RX_NEVER_MATCH
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    EOF = NegativeLookahead(RegExp('.'))
    S = RegExp('\\s+')
    Char = RegExp(
        '\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]'
    )
    Chars = RegExp(
        '(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF])+'
    )
    CharRef = Alternative(
        Series(Drop(Text('&#')), RegExp('[0-9]+'), Drop(Text(';'))),
        Series(Drop(Text('&#x')), RegExp('[0-9a-fA-F]+'), Drop(Text(';'))))
    CommentChars = RegExp(
        '(?:(?!-)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    PIChars = RegExp(
        '(?:(?!\\?>)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    IgnoreChars = RegExp(
        '(?:(?!(?:<!\\[)|(?:\\]\\]>))(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    CData = RegExp(
        '(?:(?!\\]\\]>)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    CharData = RegExp('(?:(?!\\]\\]>)[^<&])+')
    PubidChars = RegExp(
        "(?:\\x20|\\x0D|\\x0A|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])+")
    PubidCharsSingleQuoted = RegExp(
        '(?:\\x20|\\x0D|\\x0A|[a-zA-Z0-9]|[-()+,./:=?;!*#@$_%])+')
    CDSect = Series(Drop(Text('<![CDATA[')), CData, Drop(Text(']]>')))
    NameStartChar = RegExp(
        '(?x)_|:|[A-Z]|[a-z]\n                   |[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]\n                   |[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]\n                   |[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]\n                   |[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]\n                   |[\\U00010000-\\U000EFFFF]'
    )
    NameChars = RegExp(
        '(?x)(?:_|:|-|\\.|[A-Z]|[a-z]|[0-9]\n                   |\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]\n                   |[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]\n                   |[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]\n                   |[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]\n                   |[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]\n                   |[\\U00010000-\\U000EFFFF])+'
    )
    Comment = Series(Drop(Text('<!--')),
                     ZeroOrMore(Alternative(CommentChars, RegExp('-(?!-)'))),
                     Drop(Text('-->')))
    Name = Series(NameStartChar, Option(NameChars))
    PITarget = Series(NegativeLookahead(RegExp('X|xM|mL|l')), Name)
    PI = Series(Drop(Text('<?')), PITarget, Option(Series(dwsp__, PIChars)),
                Drop(Text('?>')))
    Misc = OneOrMore(Alternative(Comment, PI, S))
    Names = Series(Name, ZeroOrMore(Series(RegExp(' '), Name)))
    Nmtoken = Synonym(NameChars)
    Nmtokens = Series(Nmtoken, ZeroOrMore(Series(RegExp(' '), Nmtoken)))
    PEReference = Series(Drop(Text('%')), Name, Drop(Text(';')))
    EntityRef = Series(Drop(Text('&')), Name, Drop(Text(';')))
    Reference = Alternative(EntityRef, CharRef)
    PubidLiteral = Alternative(
        Series(Drop(Text('"')), Option(PubidChars), Drop(Text('"'))),
        Series(Drop(Text("\'")), Option(PubidCharsSingleQuoted),
               Drop(Text("\'"))))
    SystemLiteral = Alternative(
        Series(Drop(Text('"')), RegExp('[^"]*'), Drop(Text('"'))),
        Series(Drop(Text("\'")), RegExp("[^']*"), Drop(Text("\'"))))
    AttValue = Alternative(
        Series(Drop(Text('"')),
               ZeroOrMore(Alternative(RegExp('[^<&"]+'), Reference)),
               Drop(Text('"'))),
        Series(Drop(Text("\'")),
               ZeroOrMore(Alternative(RegExp("[^<&']+"), Reference)),
               Drop(Text("\'"))))
    EntityValue = Alternative(
        Series(
            Drop(Text('"')),
            ZeroOrMore(Alternative(RegExp('[^%&"]+'), PEReference, Reference)),
            Drop(Text('"'))),
        Series(
            Drop(Text("\'")),
            ZeroOrMore(Alternative(RegExp("[^%&']+"), PEReference, Reference)),
            Drop(Text("\'"))))
    content = Series(
        Option(CharData),
        ZeroOrMore(
            Series(Alternative(element, Reference, CDSect, PI, Comment),
                   Option(CharData))))
    Attribute = Series(Name,
                       dwsp__,
                       Drop(Text('=')),
                       dwsp__,
                       AttValue,
                       mandatory=2)
    TagName = Capture(Synonym(Name))
    emptyElement = Series(Drop(Text('<')), Name,
                          ZeroOrMore(Series(dwsp__, Attribute)), dwsp__,
                          Drop(Text('/>')))
    ETag = Series(Drop(Text('</')),
                  Pop(TagName),
                  dwsp__,
                  Drop(Text('>')),
                  mandatory=1)
    STag = Series(Drop(Text('<')), TagName,
                  ZeroOrMore(Series(dwsp__, Attribute)), dwsp__,
                  Drop(Text('>')))
    VersionNum = RegExp('[0-9]+\\.[0-9]+')
    intSubset = RegExp('(?:(?!\\][^\\]])[^<&])+')
    ExternalID = Series(Drop(Text('SYSTEM')), S, SystemLiteral, mandatory=1)
    doctypedecl = Series(
        Drop(Text('<!DOCTYPE')), dwsp__, Name,
        Option(Series(dwsp__, ExternalID)), dwsp__,
        Option(Series(Drop(Text('[')), intSubset, Drop(Text(']')), dwsp__)),
        Drop(Text('>')))
    No = Text('no')
    Yes = Text('yes')
    SDDecl = Series(
        dwsp__, Drop(Text('standalone')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(
            Alternative(Series(Drop(Text("\'")), Yes),
                        Series(No, Drop(Text("\'")))),
            Alternative(Series(Drop(Text('"')), Yes),
                        Series(No, Drop(Text('"'))))))
    EncName = RegExp('[A-Za-z][A-Za-z0-9._\\-]*')
    EncodingDecl = Series(
        dwsp__, Drop(Text('encoding')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(Series(Drop(Text("\'")), EncName, Drop(Text("\'"))),
                    Series(Drop(Text('"')), EncName, Drop(Text('"')))))
    VersionInfo = Series(
        dwsp__, Drop(Text('version')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(Series(Drop(Text("\'")), VersionNum, Drop(Text("\'"))),
                    Series(Drop(Text('"')), VersionNum, Drop(Text('"')))))
    XMLDecl = Series(Drop(Text('<?xml')), VersionInfo, Option(EncodingDecl),
                     Option(SDDecl), dwsp__, Drop(Text('?>')))
    prolog = Series(Option(Series(dwsp__, XMLDecl)), Option(Misc),
                    Option(Series(doctypedecl, Option(Misc))))
    element.set(
        Alternative(emptyElement, Series(STag, content, ETag, mandatory=1)))
    document = Series(prolog, element, Option(Misc), EOF)
    root__ = document
Ejemplo n.º 13
0
class ts2dataclassGrammar(Grammar):
    r"""Parser for a ts2dataclass source file.
    """
    _literal = Forward()
    _type = Forward()
    declaration = Forward()
    declarations_block = Forward()
    index_signature = Forward()
    types = Forward()
    source_hash__ = "5f9e38899e4238611532f9504cd149f0"
    disposable__ = re.compile(
        'INT$|NEG$|FRAC$|DOT$|EXP$|EOF$|_type$|_literal$|_name$|_array_ellipsis$|_top_level_assignment$|_top_level_literal$'
    )
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r'(?:\/\/.*)|(?:\/\*(?:.|\n)*?\*\/)'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    EOF = Drop(NegativeLookahead(RegExp('.')))
    EXP = Option(
        Series(Alternative(Text("E"), Text("e")),
               Option(Alternative(Text("+"), Text("-"))), RegExp('[0-9]+')))
    DOT = Text(".")
    FRAC = Option(Series(DOT, RegExp('[0-9]+')))
    NEG = Text("-")
    INT = Series(Option(NEG),
                 Alternative(RegExp('[1-9][0-9]+'), RegExp('[0-9]')))
    identifier = Series(RegExp('(?!\\d)\\w+'), dwsp__)
    variable = Series(identifier, ZeroOrMore(Series(Text("."), identifier)))
    basic_type = Series(
        Alternative(Text("object"), Text("array"), Text("string"),
                    Text("number"), Text("boolean"),
                    Series(Text("null"), Text("integer")), Text("uinteger")),
        dwsp__)
    _name = Alternative(
        identifier,
        Series(Series(Drop(Text('"')), dwsp__), identifier,
               Series(Drop(Text('"')), dwsp__)))
    association = Series(_name, Series(Drop(Text(":")), dwsp__), _literal)
    object = Series(
        Series(Drop(Text("{")), dwsp__),
        Option(
            Series(
                association,
                ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__),
                                  association)))),
        Series(Drop(Text("}")), dwsp__))
    array = Series(
        Series(Drop(Text("[")), dwsp__),
        Option(
            Series(
                _literal,
                ZeroOrMore(Series(Series(Drop(Text(",")),
                                         dwsp__), _literal)))),
        Series(Drop(Text("]")), dwsp__))
    string = Alternative(Series(RegExp('"[^"\\n]*"'), dwsp__),
                         Series(RegExp("'[^'\\n]*'"), dwsp__))
    number = Series(INT, FRAC, EXP, dwsp__)
    type_parameter = Series(Series(Drop(Text("<")), dwsp__), identifier,
                            Series(Drop(Text(">")), dwsp__))
    _top_level_literal = Drop(Synonym(_literal))
    _array_ellipsis = Drop(
        Series(
            _literal,
            Drop(
                ZeroOrMore(
                    Drop(Series(Series(Drop(Text(",")), dwsp__), _literal))))))
    assignment = Series(variable, Series(Drop(Text("=")), dwsp__), _literal,
                        Series(Drop(Text(";")), dwsp__))
    _top_level_assignment = Drop(Synonym(assignment))
    const = Series(Option(Series(Drop(Text("export")), dwsp__)),
                   Series(Drop(Text("const")), dwsp__),
                   declaration,
                   Series(Drop(Text("=")), dwsp__),
                   Alternative(_literal, identifier),
                   Series(Drop(Text(";")), dwsp__),
                   mandatory=2)
    item = Series(identifier,
                  Option(Series(Series(Drop(Text("=")), dwsp__), _literal)))
    enum = Series(Option(Series(Drop(Text("export")), dwsp__)),
                  Series(Drop(Text("enum")), dwsp__),
                  Option(identifier),
                  Series(Drop(Text("{")), dwsp__),
                  item,
                  ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), item)),
                  Series(Drop(Text("}")), dwsp__),
                  mandatory=3)
    namespace = Series(Option(Series(Drop(Text("export")), dwsp__)),
                       Series(Drop(Text("namespace")), dwsp__),
                       identifier,
                       Series(Drop(Text("{")), dwsp__),
                       ZeroOrMore(const),
                       Series(Drop(Text("}")), dwsp__),
                       mandatory=2)
    map_signature = Series(index_signature, Series(Drop(Text(":")), dwsp__),
                           types)
    mapped_type = Series(Series(Drop(Text("{")), dwsp__), map_signature,
                         Option(Series(Drop(Text(";")), dwsp__)),
                         Series(Drop(Text("}")), dwsp__))
    type_tuple = Series(
        Series(Drop(Text("[")), dwsp__), _type,
        ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), _type)),
        Series(Drop(Text("]")), dwsp__))
    array_of = Series(
        Alternative(
            basic_type,
            Series(Series(Drop(Text("(")), dwsp__), types,
                   Series(Drop(Text(")")), dwsp__)), identifier),
        Series(Drop(Text("[]")), dwsp__))
    extends = Series(
        Series(Drop(Text("extends")), dwsp__), identifier,
        ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), identifier)))
    type_alias = Series(Option(Series(Drop(Text("export")), dwsp__)),
                        Series(Drop(Text("type")), dwsp__),
                        identifier,
                        Series(Drop(Text("=")), dwsp__),
                        types,
                        Series(Drop(Text(";")), dwsp__),
                        mandatory=2)
    interface = Series(Option(Series(Drop(Text("export")), dwsp__)),
                       Series(Drop(Text("interface")), dwsp__),
                       identifier,
                       Option(type_parameter),
                       Option(extends),
                       declarations_block,
                       mandatory=2)
    optional = Series(Text("?"), dwsp__)
    qualifier = Series(Text("readonly"), dwsp__)
    _literal.set(Alternative(number, string, array, object))
    _type.set(
        Alternative(
            array_of, basic_type, identifier,
            Series(Series(Drop(Text("(")), dwsp__), types,
                   Series(Drop(Text(")")), dwsp__)), mapped_type,
            declarations_block, type_tuple, _literal))
    types.set(
        Series(_type, ZeroOrMore(Series(Series(Drop(Text("|")), dwsp__),
                                        _type))))
    index_signature.set(
        Series(
            Series(Drop(Text("[")), dwsp__), identifier,
            Alternative(
                Series(Drop(Text(":")), dwsp__),
                Series(Series(Drop(Text("in")), dwsp__),
                       Series(Drop(Text("keyof")), dwsp__))), _type,
            Series(Drop(Text("]")), dwsp__)))
    declaration.set(
        Series(Option(qualifier), identifier, Option(optional),
               Option(Series(Series(Drop(Text(":")), dwsp__), types))))
    declarations_block.set(
        Series(
            Series(Drop(Text("{")), dwsp__),
            Option(
                Series(
                    declaration,
                    ZeroOrMore(
                        Series(Series(Drop(Text(";")), dwsp__), declaration)),
                    Option(
                        Series(Series(Drop(Text(";")), dwsp__),
                               map_signature)),
                    Option(Series(Drop(Text(";")), dwsp__)))),
            Series(Drop(Text("}")), dwsp__)))
    document = Series(
        dwsp__,
        ZeroOrMore(
            Alternative(interface, type_alias, namespace, enum, const,
                        Series(declaration, Series(Drop(Text(";")), dwsp__)),
                        _top_level_assignment, _array_ellipsis,
                        _top_level_literal)), EOF)
    root__ = TreeReduction(document, CombinedParser.MERGE_TREETOPS)
Ejemplo n.º 14
0
class json_fail_tolerantGrammar(Grammar):
    r"""Parser for a json_fail_tolerant source file.
    """
    _element = Forward()
    source_hash__ = "42cb00a4f8192986733859d4709c5b37"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    error_messages__ = {
        'member':
        [(re.compile(r'[\'`´]'),
          'String values must be enclosed by double-quotation marks: "..."!')],
        'string':
        [(re.compile(r'\\'),
          'Illegal escape sequence "{1}" Allowed values are \\\\/, \\\\\\\\, \\\\b, \\\\n, \\\\r, \\\\t, or \\\\u.'
          ), (re.compile(r'(?=)'), 'Illegal character "{1}" in string.')],
        '_OBJECT_SEPARATOR': [(re.compile(r'(?!,)'), 'Missing separator ","')],
        '_ARRAY_SEPARATOR': [(re.compile(r'(?!,)'), 'Missing separator ","')]
    }
    skip_rules__ = {'string': [re.compile(r'(?=")')]}
    resume_rules__ = {
        'object': [re.compile(r'(?:[^{}]|(?:\{.*\}))*\}\s*')],
        'array': [re.compile(r'(?:[^\[\]]|(?:\[.*\]))*\]\s*')],
        'member': [re.compile(r'(?=(?:"[^"\n]+"\s*:)|\}|,)')],
        '_OBJECT_SEPARATOR': [re.compile(r'(?=)')],
        '_ARRAY_SEPARATOR': [re.compile(r'(?=)')]
    }
    COMMENT__ = r'(?:\/\/|#).*'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    _ARRAY_SEPARATOR = Series(NegativeLookahead(Text("]")),
                              Lookahead(Text(",")),
                              Option(Series(Drop(Text(",")), dwsp__)),
                              mandatory=1)
    _OBJECT_SEPARATOR = Series(NegativeLookahead(Text("}")),
                               Lookahead(Text(",")),
                               Option(Series(Drop(Text(",")), dwsp__)),
                               mandatory=1)
    _EOF = NegativeLookahead(RegExp('.'))
    EXP = Option(
        Series(Alternative(Text("E"), Text("e")),
               Option(Alternative(Text("+"), Text("-"))), RegExp('[0-9]+')))
    DOT = Text(".")
    FRAC = Option(Series(DOT, RegExp('[0-9]+')))
    NEG = Text("-")
    INT = Series(Option(NEG),
                 Alternative(RegExp('[0-9]'), RegExp('[1-9][0-9]+')))
    HEX = RegExp('[0-9a-fA-F][0-9a-fA-F]')
    UNICODE = Series(Series(Drop(Text("\\u")), dwsp__), HEX, HEX)
    ESCAPE = Alternative(RegExp('\\\\[/bnrt\\\\]'), UNICODE)
    PLAIN = RegExp('[^"\\\\]+')
    _CHARACTERS = ZeroOrMore(Alternative(PLAIN, ESCAPE))
    null = Series(Text("null"), dwsp__)
    bool = Alternative(Series(RegExp('true'), dwsp__),
                       Series(RegExp('false'), dwsp__))
    number = Series(INT, FRAC, EXP, dwsp__)
    string = Series(Text('"'), _CHARACTERS, Text('"'), dwsp__, mandatory=1)
    array = Series(
        Series(Drop(Text("[")), dwsp__),
        Option(
            Series(_element,
                   ZeroOrMore(Series(_ARRAY_SEPARATOR, _element,
                                     mandatory=1)))),
        Series(Drop(Text("]")), dwsp__))
    member = Series(string,
                    Series(Drop(Text(":")), dwsp__),
                    _element,
                    mandatory=1)
    object = Series(Series(Drop(Text("{")), dwsp__),
                    member,
                    ZeroOrMore(Series(_OBJECT_SEPARATOR, member, mandatory=1)),
                    Series(Drop(Text("}")), dwsp__),
                    mandatory=3)
    _element.set(Alternative(object, array, string, number, bool, null))
    json = Series(dwsp__, _element, _EOF)
    root__ = json
Ejemplo n.º 15
0
class XMLGrammar(Grammar):
    r"""Parser for a XML source file.
    """
    choice = Forward()
    cp = Forward()
    element = Forward()
    extSubsetDecl = Forward()
    ignoreSectContents = Forward()
    source_hash__ = "11b281a4c3d083094c84f69ae5da6f28"
    disposable__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r''
    comment_rx__ = RX_NEVER_MATCH
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    EOF = NegativeLookahead(RegExp('.'))
    S = RegExp('\\s+')
    Char = RegExp(
        '\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]'
    )
    Chars = RegExp(
        '(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF])+'
    )
    CharRef = Alternative(
        Series(Drop(Text('&#')), RegExp('[0-9]+'), Drop(Text(';'))),
        Series(Drop(Text('&#x')), RegExp('[0-9a-fA-F]+'), Drop(Text(';'))))
    CommentChars = RegExp(
        '(?:(?!-)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    PIChars = RegExp(
        '(?:(?!\\?>)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    IgnoreChars = RegExp(
        '(?:(?!(?:<!\\[)|(?:\\]\\]>))(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    CData = RegExp(
        '(?:(?!\\]\\]>)(?:\\x09|\\x0A|\\x0D|[\\u0020-\\uD7FF]|[\\uE000-\\uFFFD]|[\\U00010000-\\U0010FFFF]))+'
    )
    CharData = RegExp('(?:(?!\\]\\]>)[^<&])+')
    PubidChars = RegExp(
        "(?:\\x20|\\x0D|\\x0A|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])+")
    PubidCharsSingleQuoted = RegExp(
        '(?:\\x20|\\x0D|\\x0A|[a-zA-Z0-9]|[-()+,./:=?;!*#@$_%])+')
    CDSect = Series(Drop(Text('<![CDATA[')), CData, Drop(Text(']]>')))
    NameStartChar = RegExp(
        '(?x)_|:|[A-Z]|[a-z]\n                   |[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]\n                   |[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]\n                   |[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]\n                   |[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]\n                   |[\\U00010000-\\U000EFFFF]'
    )
    NameChars = RegExp(
        '(?x)(?:_|:|-|\\.|[A-Z]|[a-z]|[0-9]\n                   |\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]\n                   |[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]\n                   |[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]\n                   |[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]\n                   |[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]\n                   |[\\U00010000-\\U000EFFFF])+'
    )
    Comment = Series(Drop(Text('<!--')),
                     ZeroOrMore(Alternative(CommentChars, RegExp('-(?!-)'))),
                     Drop(Text('-->')))
    Name = Series(NameStartChar, Option(NameChars))
    PITarget = Series(NegativeLookahead(RegExp('X|xM|mL|l')), Name)
    PI = Series(Drop(Text('<?')), PITarget, Option(Series(dwsp__, PIChars)),
                Drop(Text('?>')))
    Misc = OneOrMore(Alternative(Comment, PI, S))
    Names = Series(Name, ZeroOrMore(Series(RegExp(' '), Name)))
    Nmtoken = Synonym(NameChars)
    Nmtokens = Series(Nmtoken, ZeroOrMore(Series(RegExp(' '), Nmtoken)))
    PEReference = Series(Drop(Text('%')), Name, Drop(Text(';')))
    EntityRef = Series(Drop(Text('&')), Name, Drop(Text(';')))
    Reference = Alternative(EntityRef, CharRef)
    PubidLiteral = Alternative(
        Series(Drop(Text('"')), Option(PubidChars), Drop(Text('"'))),
        Series(Drop(Text("\'")), Option(PubidCharsSingleQuoted),
               Drop(Text("\'"))))
    SystemLiteral = Alternative(
        Series(Drop(Text('"')), RegExp('[^"]*'), Drop(Text('"'))),
        Series(Drop(Text("\'")), RegExp("[^']*"), Drop(Text("\'"))))
    AttValue = Alternative(
        Series(Drop(Text('"')),
               ZeroOrMore(Alternative(RegExp('[^<&"]+'), Reference)),
               Drop(Text('"'))),
        Series(Drop(Text("\'")),
               ZeroOrMore(Alternative(RegExp("[^<&']+"), Reference)),
               Drop(Text("\'"))))
    EntityValue = Alternative(
        Series(
            Drop(Text('"')),
            ZeroOrMore(Alternative(RegExp('[^%&"]+'), PEReference, Reference)),
            Drop(Text('"'))),
        Series(
            Drop(Text("\'")),
            ZeroOrMore(Alternative(RegExp("[^%&']+"), PEReference, Reference)),
            Drop(Text("\'"))))
    content = Series(
        Option(CharData),
        ZeroOrMore(
            Series(Alternative(element, Reference, CDSect, PI, Comment),
                   Option(CharData))))
    Attribute = Series(Name,
                       dwsp__,
                       Drop(Text('=')),
                       dwsp__,
                       AttValue,
                       mandatory=2)
    TagName = Capture(Synonym(Name))
    emptyElement = Series(Drop(Text('<')), Name,
                          ZeroOrMore(Series(dwsp__, Attribute)), dwsp__,
                          Drop(Text('/>')))
    ETag = Series(Drop(Text('</')),
                  Pop(TagName),
                  dwsp__,
                  Drop(Text('>')),
                  mandatory=1)
    STag = Series(Drop(Text('<')), TagName,
                  ZeroOrMore(Series(dwsp__, Attribute)), dwsp__,
                  Drop(Text('>')))
    EncName = RegExp('[A-Za-z][A-Za-z0-9._\\-]*')
    NDataDecl = Series(Drop(Text('NData')), S, Name, mandatory=1)
    PublicID = Series(Drop(Text('PUBLIC')), S, PubidLiteral, mandatory=1)
    ExternalID = Alternative(
        Series(Drop(Text('SYSTEM')), S, SystemLiteral, mandatory=1),
        Series(Drop(Text('PUBLIC')),
               S,
               PubidLiteral,
               S,
               SystemLiteral,
               mandatory=1))
    NotationDecl = Series(Drop(Text('<!NOTATION')),
                          S,
                          Name,
                          dwsp__,
                          Alternative(ExternalID, PublicID),
                          dwsp__,
                          Drop(Text('>')),
                          mandatory=1)
    PEDef = Alternative(EntityValue, ExternalID)
    EntityDef = Alternative(EntityValue, Series(ExternalID, Option(NDataDecl)))
    PEDecl = Series(Drop(Text('<!ENTITY')),
                    S,
                    Drop(Text('%')),
                    S,
                    Name,
                    S,
                    PEDef,
                    dwsp__,
                    Drop(Text('>')),
                    mandatory=3)
    GEDecl = Series(Drop(Text('<!ENTITY')),
                    S,
                    Name,
                    S,
                    EntityDef,
                    dwsp__,
                    Drop(Text('>')),
                    mandatory=3)
    EntityDecl = Alternative(GEDecl, PEDecl)
    FIXED = Series(Option(Series(Drop(Text('#FIXED')), S)), AttValue)
    IMPLIED = Text('#IMPLIED')
    REQUIRED = Text('#REQUIRED')
    DefaultDecl = Alternative(REQUIRED, IMPLIED, FIXED)
    Enumeration = Series(
        Drop(Text('(')), dwsp__, Nmtoken,
        ZeroOrMore(Series(dwsp__, Drop(Text('|')), dwsp__, Nmtoken)), dwsp__,
        Drop(Text(')')))
    NotationType = Series(
        Drop(Text('NOTATION')), S, Drop(Text('(')), dwsp__, Name,
        ZeroOrMore(Series(dwsp__, Drop(Text('|')), dwsp__, Name)), dwsp__,
        Drop(Text(')')))
    EnumeratedType = Alternative(NotationType, Enumeration)
    NMTOKENS = Text('NMTOKENS')
    NMTOKEN = Text('NMTOKEN')
    ENTITIES = Text('ENTITIES')
    ENTITY = Text('ENTITY')
    IDREFS = Text('IDREFS')
    IDREF = Text('IDREF')
    ID = Text('ID')
    TokenizedType = Alternative(IDREFS, IDREF, ID, ENTITY, ENTITIES, NMTOKENS,
                                NMTOKEN)
    StringType = Text('CDATA')
    AttType = Alternative(StringType, TokenizedType, EnumeratedType)
    AttDef = Series(Name, dwsp__, AttType, S, DefaultDecl, mandatory=2)
    AttlistDecl = Series(Drop(Text('<!ATTLIST')),
                         S,
                         Name,
                         ZeroOrMore(Series(dwsp__, AttDef)),
                         dwsp__,
                         Drop(Text('>')),
                         mandatory=1)
    seq = Series(Drop(Text('(')), dwsp__, cp,
                 ZeroOrMore(Series(dwsp__, Drop(Text(',')), dwsp__, cp)),
                 dwsp__, Drop(Text(')')))
    VersionNum = RegExp('[0-9]+\\.[0-9]+')
    VersionInfo = Series(
        dwsp__, Drop(Text('version')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(Series(Drop(Text("\'")), VersionNum, Drop(Text("\'"))),
                    Series(Drop(Text('"')), VersionNum, Drop(Text('"')))))
    children = Series(
        Alternative(choice, seq),
        Option(Alternative(Drop(Text('?')), Drop(Text('*')), Drop(Text('+')))))
    Mixed = Alternative(
        Series(Drop(Text('(')), dwsp__, Drop(Text('#PCDATA')),
               ZeroOrMore(Series(dwsp__, Drop(Text('|')), dwsp__, Name)),
               dwsp__, Drop(Text(')*'))),
        Series(Drop(Text('(')), dwsp__, Drop(Text('#PCDATA')), dwsp__,
               Drop(Text(')'))))
    ANY = Text('ANY')
    EMPTY = Text('EMPTY')
    contentspec = Alternative(EMPTY, ANY, Mixed, children)
    elementdecl = Series(Drop(Text('<!ELEMENT')),
                         S,
                         Name,
                         dwsp__,
                         contentspec,
                         dwsp__,
                         Drop(Text('>')),
                         mandatory=1)
    EncodingDecl = Series(
        dwsp__, Drop(Text('encoding')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(Series(Drop(Text("\'")), EncName, Drop(Text("\'"))),
                    Series(Drop(Text('"')), EncName, Drop(Text('"')))))
    TextDecl = Series(Drop(Text('<?xml')), Option(VersionInfo), EncodingDecl,
                      dwsp__, Drop(Text('?>')))
    extParsedEnt = Series(Option(TextDecl), content)
    ignoreSect = Series(Drop(Text('<![')), dwsp__, Drop(Text('IGNORE')),
                        dwsp__, Drop(Text('[')), ignoreSectContents,
                        Drop(Text(']]>')))
    includeSect = Series(Drop(Text('<![')), dwsp__, Drop(Text('INCLUDE')),
                         dwsp__, Drop(Text('[')), extSubsetDecl,
                         Drop(Text(']]>')))
    conditionalSect = Alternative(includeSect, ignoreSect)
    Yes = Text('yes')
    extSubset = Series(Option(TextDecl), extSubsetDecl)
    markupdecl = Alternative(elementdecl, AttlistDecl, EntityDecl,
                             NotationDecl, PI, Comment)
    DeclSep = Alternative(PEReference, S)
    intSubset = ZeroOrMore(Alternative(markupdecl, DeclSep))
    doctypedecl = Series(Drop(Text('<!DOCTYPE')),
                         dwsp__,
                         Name,
                         Option(Series(dwsp__, ExternalID)),
                         dwsp__,
                         Option(
                             Series(Drop(Text('[')), intSubset,
                                    Drop(Text(']')), dwsp__)),
                         Drop(Text('>')),
                         mandatory=2)
    No = Text('no')
    SDDecl = Series(
        dwsp__, Drop(Text('standalone')), dwsp__, Drop(Text('=')), dwsp__,
        Alternative(
            Alternative(Series(Drop(Text("\'")), Yes),
                        Series(No, Drop(Text("\'")))),
            Alternative(Series(Drop(Text('"')), Yes),
                        Series(No, Drop(Text('"'))))))
    XMLDecl = Series(Drop(Text('<?xml')), VersionInfo, Option(EncodingDecl),
                     Option(SDDecl), dwsp__, Drop(Text('?>')))
    prolog = Series(Option(Series(dwsp__, XMLDecl)), Option(Misc),
                    Option(Series(doctypedecl, Option(Misc))))
    element.set(
        Alternative(emptyElement, Series(STag, content, ETag, mandatory=1)))
    cp.set(
        Series(
            Alternative(Name, choice, seq),
            Option(
                Alternative(Drop(Text('?')), Drop(Text('*')),
                            Drop(Text('+'))))))
    choice.set(
        Series(Drop(Text('(')), dwsp__,
               OneOrMore(Series(dwsp__, Drop(Text('|')), dwsp__, cp)), dwsp__,
               Drop(Text(')'))))
    ignoreSectContents.set(
        Series(
            IgnoreChars,
            ZeroOrMore(
                Series(Drop(Text('<![')), ignoreSectContents,
                       Drop(Text(']]>')), IgnoreChars))))
    extSubsetDecl.set(
        ZeroOrMore(Alternative(markupdecl, conditionalSect, DeclSep)))
    document = Series(prolog, element, Option(Misc), EOF)
    root__ = document
Ejemplo n.º 16
0
class LaTeXGrammar(Grammar):
    r"""Parser for a LaTeX source file.
    """
    _block_environment = Forward()
    _text_element = Forward()
    block = Forward()
    paragraph = Forward()
    param_block = Forward()
    tabular_config = Forward()
    source_hash__ = "d443c74c1540aca5ee7ed767a0da896e"
    disposable__ = re.compile('_\\w+')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    error_messages__ = {
        'end_generic_block':
        [(re.compile(r'(?=)'),
          "A block environment must be followed by a linefeed, not by: {1}")],
        'item':
        [(re.compile(r'(?=)'), '\\item without proper content, found: {1}')]
    }
    COMMENT__ = r'%.*'
    comment_rx__ = re.compile(COMMENT__)
    comment__ = RegExp(comment_rx__)
    WHITESPACE__ = r'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
    whitespace__ = Whitespace(WHITESPACE__)
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    EOF = RegExp('(?!.)')
    _BACKSLASH = Drop(RegExp('[\\\\]'))
    _LB = Drop(RegExp('\\s*?\\n|$'))
    NEW_LINE = Series(Drop(RegExp('[ \\t]*')), Option(comment__),
                      Drop(RegExp('\\n')))
    _GAP = Drop(Series(RegExp('[ \\t]*(?:\\n[ \\t]*)+\\n'), dwsp__))
    _WSPC = Drop(OneOrMore(Drop(Alternative(comment__, Drop(RegExp('\\s+'))))))
    _PARSEP = Drop(
        Series(Drop(ZeroOrMore(Drop(Series(whitespace__, comment__)))), _GAP,
               Drop(Option(_WSPC))))
    S = Series(Lookahead(Drop(RegExp('[% \\t\\n]'))), NegativeLookahead(_GAP),
               wsp__)
    LFF = Alternative(Series(NEW_LINE, Option(_WSPC)), EOF)
    _LETTERS = RegExp('\\w+')
    CHARS = RegExp('[^\\\\%$&\\{\\}\\[\\]\\s\\n\'`"]+')
    _TEXT_NOPAR = RegExp(
        '(?:[^\\\\%$&\\{\\}\\[\\]\\(\\)\\n]+(?:\\n(?![ \\t]*\\n))?)+')
    _TEXT = RegExp('(?:[^\\\\%$&\\{\\}\\[\\]\\n\'`"]+(?:\\n(?![ \\t]*\\n))?)+')
    _TAG = RegExp('[\\w=?.:\\-%&\\[\\] /]+')
    _COLON = Text(":")
    _HASH = Text("#")
    _PATHSEP = RegExp('/(?!\\*)')
    _PATH = RegExp('[\\w=~?.,%&\\[\\]-]+')
    UNIT = RegExp('(?!\\d)\\w+')
    _FRAC = RegExp('\\.[0-9]+')
    _INTEGER = RegExp('-?(?:(?:[1-9][0-9]+)|[0-9])')
    _NAME = RegExp('(?!\\d)\\w+\\*?')
    NAME = Capture(Synonym(_NAME))
    IDENTIFIER = Synonym(_NAME)
    _QUALIFIED = Series(
        IDENTIFIER,
        ZeroOrMore(
            Series(NegativeLookbehind(_BACKSLASH), Drop(RegExp('[:.-]')),
                   IDENTIFIER)))
    LINEFEED = RegExp('[\\\\][\\\\]')
    BRACKETS = RegExp('[\\[\\]]')
    SPECIAL = RegExp('[$&_/\\\\\\\\]')
    QUOTEMARK = RegExp('"[`\']?|``?|\'\'?')
    UMLAUT = RegExp(
        '\\\\(?:(?:"[AOUaou])|(?:\'[aeiou])|(?:`[aeiou])|(?:[\\^][aeiou]))')
    ESCAPED = RegExp('\\\\(?:(?:[#%$&_/{} \\n])|(?:~\\{\\s*\\}))')
    TXTCOMMAND = RegExp('\\\\text\\w+')
    CMDNAME = Series(RegExp('\\\\@?(?:(?![\\d_])\\w)+'), dwsp__)
    WARN_Komma = Series(Text(","), dwsp__)
    esc_char = Text(",")
    number = Series(_INTEGER, Option(_FRAC))
    magnitude = Series(number, Option(UNIT))
    info_value = Series(_TEXT_NOPAR, ZeroOrMore(Series(S, _TEXT_NOPAR)))
    info_key = Series(Drop(Text("/")), _NAME)
    info_assoc = Series(
        info_key, dwsp__,
        Option(
            Series(Series(Drop(Text("(")), dwsp__),
                   info_value,
                   Series(Drop(Text(")")), dwsp__),
                   mandatory=1)))
    _info_block = Series(Series(Drop(Text("{")), dwsp__),
                         ZeroOrMore(info_assoc),
                         Series(Drop(Text("}")), dwsp__),
                         mandatory=1)
    value = Alternative(magnitude, _LETTERS, CMDNAME, param_block, block)
    key = Synonym(_QUALIFIED)
    flag = Alternative(_QUALIFIED, magnitude)
    association = Series(key, dwsp__, Series(Drop(Text("=")), dwsp__), value,
                         dwsp__)
    parameters = Series(
        Alternative(association, flag),
        ZeroOrMore(
            Series(NegativeLookbehind(_BACKSLASH),
                   Series(Drop(Text(",")), dwsp__),
                   Alternative(association, flag))), Option(WARN_Komma))
    sequence = Series(
        Option(_WSPC),
        OneOrMore(
            Series(Alternative(paragraph, _block_environment),
                   Option(Alternative(_PARSEP, S)))))
    block_of_paragraphs = Series(Series(Drop(Text("{")), dwsp__),
                                 Option(sequence),
                                 Series(Drop(Text("}")), dwsp__),
                                 mandatory=2)
    special = Alternative(Drop(Text("\\-")),
                          Series(Drop(RegExp('\\\\')), esc_char), UMLAUT,
                          QUOTEMARK)
    _structure_name = Drop(
        Alternative(Drop(Text("subsection")), Drop(Text("section")),
                    Drop(Text("chapter")), Drop(Text("subsubsection")),
                    Drop(Text("paragraph")), Drop(Text("subparagraph")),
                    Drop(Text("item"))))
    _env_name = Drop(
        Alternative(
            Drop(Text("enumerate")), Drop(Text("itemize")),
            Drop(Text("description")),
            Drop(Text("figure")), Drop(Text("quote")), Drop(Text("quotation")),
            Drop(Text("tabular")),
            Drop(
                Series(Drop(Text("displaymath")),
                       Drop(Option(Drop(Text("*")))))),
            Drop(Series(Drop(Text("equation")),
                        Drop(Option(Drop(Text("*")))))),
            Drop(Series(Drop(Text("eqnarray")),
                        Drop(Option(Drop(Text("*"))))))))
    blockcmd = Series(
        _BACKSLASH,
        Alternative(
            Series(
                Alternative(Series(Drop(Text("begin{")), dwsp__),
                            Series(Drop(Text("end{")), dwsp__)), _env_name,
                Series(Drop(Text("}")), dwsp__)),
            Series(_structure_name, Lookahead(Drop(Text("{")))),
            Drop(Text("[")), Drop(Text("]"))))
    no_command = Alternative(
        Series(Drop(Text("\\begin{")), dwsp__),
        Series(Drop(Text("\\end{")), dwsp__),
        Series(_BACKSLASH, _structure_name, Lookahead(Drop(Text("{")))))
    text = Series(
        OneOrMore(Alternative(_TEXT, special)),
        ZeroOrMore(Series(S, OneOrMore(Alternative(_TEXT, special)))))
    cfg_text = ZeroOrMore(
        Alternative(Series(dwsp__, text), CMDNAME, SPECIAL, block))
    config = Series(Series(Drop(Text("[")), dwsp__),
                    Alternative(
                        Series(parameters,
                               Lookahead(Series(Drop(Text("]")), dwsp__))),
                        cfg_text),
                    Series(Drop(Text("]")), dwsp__),
                    mandatory=1)
    item = Series(Series(Drop(Text("\\item")), dwsp__),
                  Option(config),
                  sequence,
                  mandatory=2)
    _block_content = Series(
        Option(Alternative(_PARSEP, S)),
        ZeroOrMore(
            Series(Alternative(_block_environment, _text_element, paragraph),
                   Option(Alternative(_PARSEP, S)))))
    heading = Synonym(block)
    _pth = OneOrMore(Alternative(_PATH, ESCAPED))
    target = Series(
        _pth,
        ZeroOrMore(
            Series(NegativeLookbehind(Drop(RegExp('s?ptth'))), _COLON, _pth)),
        Option(
            Series(
                Alternative(
                    Series(Option(_BACKSLASH), _HASH),
                    Series(NegativeLookbehind(Drop(RegExp('s?ptth'))),
                           _COLON)), _TAG)))
    path = Series(_pth, _PATHSEP)
    protocol = RegExp('\\w+://(?!\\*)')
    urlstring = Series(Option(protocol), ZeroOrMore(path), Option(target))
    href = Series(Series(Drop(Text("\\href{")), dwsp__), urlstring,
                  Series(Drop(Text("}")), dwsp__), block)
    url = Series(Series(Drop(Text("\\url{")), dwsp__), urlstring,
                 Series(Drop(Text("}")), dwsp__))
    ref = Series(
        Alternative(Series(Drop(Text("\\ref{")), dwsp__),
                    Series(Drop(Text("\\pageref{")), dwsp__)), CHARS,
        Series(Drop(Text("}")), dwsp__))
    label = Series(Series(Drop(Text("\\label{")), dwsp__), CHARS,
                   Series(Drop(Text("}")), dwsp__))
    hypersetup = Series(Series(Drop(Text("\\hypersetup")), dwsp__),
                        param_block)
    pdfinfo = Series(Series(Drop(Text("\\pdfinfo")), dwsp__), _info_block)
    documentclass = Series(Series(Drop(Text("\\documentclass")), dwsp__),
                           Option(config), block)
    column_nr = Synonym(_INTEGER)
    cline = Series(Series(Drop(Text("\\cline{")), dwsp__), column_nr,
                   Series(Drop(Text("-")), dwsp__), column_nr,
                   Series(Drop(Text("}")), dwsp__))
    hline = Series(Text("\\hline"), dwsp__)
    multicolumn = Series(Series(Drop(Text("\\multicolumn")), dwsp__),
                         Series(Drop(Text("{")), dwsp__), column_nr,
                         Series(Drop(Text("}")), dwsp__), tabular_config,
                         block_of_paragraphs)
    caption = Series(Series(Drop(Text("\\caption")), dwsp__), block)
    includegraphics = Series(Series(Drop(Text("\\includegraphics")), dwsp__),
                             Option(config), block)
    footnote = Series(Series(Drop(Text("\\footnote")), dwsp__),
                      block_of_paragraphs)
    citep = Series(
        Alternative(Series(Drop(Text("\\citep")), dwsp__),
                    Series(Drop(Text("\\cite")), dwsp__)), Option(config),
        block)
    citet = Series(Series(Drop(Text("\\citet")), dwsp__), Option(config),
                   block)
    generic_command = Alternative(
        Series(NegativeLookahead(no_command), CMDNAME,
               ZeroOrMore(Series(dwsp__, Alternative(config, block)))),
        Series(Drop(Text("{")),
               CMDNAME,
               _block_content,
               Drop(Text("}")),
               mandatory=3))
    assignment = Series(
        NegativeLookahead(no_command), CMDNAME, Series(Drop(Text("=")),
                                                       dwsp__),
        Alternative(Series(number, Option(UNIT)), block, CHARS))
    text_command = Alternative(TXTCOMMAND, ESCAPED, BRACKETS)
    _known_command = Alternative(citet, citep, footnote, includegraphics,
                                 caption, multicolumn, hline, cline,
                                 documentclass, pdfinfo, hypersetup, label,
                                 ref, href, url, item)
    _command = Alternative(_known_command, text_command, assignment,
                           generic_command)
    _inline_math_text = RegExp('[^$]*')
    _im_bracket = Series(Drop(Text("\\(")),
                         _inline_math_text,
                         Drop(Text("\\)")),
                         mandatory=1)
    _im_dollar = Series(Drop(Text("$")),
                        _inline_math_text,
                        Drop(Text("$")),
                        mandatory=1)
    inline_math = Alternative(_im_dollar, _im_bracket)
    end_environment = Series(Drop(RegExp('\\\\end{')),
                             Pop(NAME),
                             Drop(RegExp('}')),
                             mandatory=1)
    begin_environment = Series(Drop(RegExp('\\\\begin{')),
                               NAME,
                               Drop(RegExp('}')),
                               mandatory=1)
    _end_inline_env = Synonym(end_environment)
    _begin_inline_env = Alternative(
        Series(NegativeLookbehind(_LB), begin_environment),
        Series(begin_environment, NegativeLookahead(LFF)))
    generic_inline_env = Series(_begin_inline_env,
                                dwsp__,
                                paragraph,
                                NegativeLookahead(_PARSEP),
                                _end_inline_env,
                                mandatory=4)
    _known_inline_env = Synonym(inline_math)
    _inline_environment = Alternative(_known_inline_env, generic_inline_env)
    _line_element = Alternative(text, _inline_environment, _command, block)
    SubParagraph = Series(Series(Drop(Text("\\subparagraph")), dwsp__),
                          heading, Option(sequence))
    hide_from_toc = Series(Text("*"), dwsp__)
    SubParagraphs = OneOrMore(Series(Option(_WSPC), SubParagraph))
    Paragraph = Series(Series(Drop(Text("\\paragraph")), dwsp__), heading,
                       ZeroOrMore(Alternative(sequence, SubParagraphs)))
    cfg_separator = Alternative(Drop(Text("|")),
                                Series(Drop(Text("!")), block))
    cfg_unit = Series(Drop(Text("{")), number, UNIT, Drop(Text("}")))
    cfg_celltype = RegExp('[lcrp]')
    frontpages = Synonym(sequence)
    rb_down = Series(Series(Drop(Text("[")), dwsp__), number, UNIT, dwsp__,
                     Series(Drop(Text("]")), dwsp__))
    rb_up = Series(Series(Drop(Text("[")), dwsp__), number, UNIT, dwsp__,
                   Series(Drop(Text("]")), dwsp__))
    rb_offset = Series(Series(Drop(Text("{")), dwsp__), number, UNIT, dwsp__,
                       Series(Drop(Text("}")), dwsp__))
    raisebox = Series(Series(Drop(Text("\\raisebox")), dwsp__), rb_offset,
                      Option(rb_up), Option(rb_down), block)
    tabular_cell = Alternative(
        Series(raisebox, Option(Alternative(S, _PARSEP))),
        ZeroOrMore(Series(_line_element, Option(Alternative(S, _PARSEP)))))
    tabular_row = Series(
        Alternative(multicolumn, tabular_cell),
        ZeroOrMore(
            Series(Series(Drop(Text("&")), dwsp__),
                   Alternative(multicolumn, tabular_cell))),
        Alternative(
            Series(Series(Drop(Text("\\\\")), dwsp__),
                   Alternative(hline, ZeroOrMore(cline)), Option(_PARSEP)),
            Lookahead(Drop(Text("\\end{tabular}")))))
    tabular = Series(Series(Drop(Text("\\begin{tabular}")), dwsp__),
                     tabular_config,
                     ZeroOrMore(Alternative(tabular_row, _WSPC)),
                     Series(Drop(Text("\\end{tabular}")), dwsp__),
                     mandatory=3)
    no_numbering = Text("*")
    _block_math = RegExp(
        '(?:[^\\\\]*[\\\\]?(?!end\\{(?:eqnarray|equation|displaymath)\\*?\\}|\\])\\s*)*'
    )
    eqnarray = Series(Drop(Text("\\begin{eqnarray")),
                      Option(no_numbering),
                      Series(Drop(Text("}")), dwsp__),
                      _block_math,
                      Drop(Text("\\end{eqnarray")),
                      Option(Drop(Text("*"))),
                      Series(Drop(Text("}")), dwsp__),
                      mandatory=3)
    equation = Series(Drop(Text("\\begin{equation")),
                      Option(no_numbering),
                      Series(Drop(Text("}")), dwsp__),
                      _block_math,
                      Drop(Text("\\end{equation")),
                      Option(Drop(Text("*"))),
                      Series(Drop(Text("}")), dwsp__),
                      mandatory=3)
    _dmath_short_form = Series(Series(Drop(Text("\\[")), dwsp__),
                               _block_math,
                               Series(Drop(Text("\\]")), dwsp__),
                               mandatory=1)
    _dmath_long_form = Series(Drop(Text("\\begin{displaymath")),
                              Option(no_numbering),
                              Series(Drop(Text("}")), dwsp__),
                              _block_math,
                              Drop(Text("\\end{displaymath")),
                              Option(Drop(Text("*"))),
                              Series(Drop(Text("}")), dwsp__),
                              mandatory=3)
    displaymath = Alternative(_dmath_long_form, _dmath_short_form)
    verbatim_text = RegExp('(?:(?!\\\\end{verbatim})[\\\\]?[^\\\\]*)*')
    verbatim = Series(Series(Drop(Text("\\begin{verbatim}")), dwsp__),
                      verbatim_text,
                      Series(Drop(Text("\\end{verbatim}")), dwsp__),
                      mandatory=2)
    quotation = Alternative(
        Series(Series(Drop(Text("\\begin{quotation}")), dwsp__),
               sequence,
               Series(Drop(Text("\\end{quotation}")), dwsp__),
               mandatory=2),
        Series(Series(Drop(Text("\\begin{quote}")), dwsp__),
               sequence,
               Series(Drop(Text("\\end{quote}")), dwsp__),
               mandatory=2))
    figure = Series(Series(Drop(Text("\\begin{figure}")), dwsp__),
                    sequence,
                    Series(Drop(Text("\\end{figure}")), dwsp__),
                    mandatory=2)
    Paragraphs = OneOrMore(Series(Option(_WSPC), Paragraph))
    _itemsequence = Series(
        Option(_WSPC),
        ZeroOrMore(Series(Alternative(item, _command), Option(_WSPC))))
    description = Series(Series(Drop(Text("\\begin{description}")), dwsp__),
                         _itemsequence,
                         Series(Drop(Text("\\end{description}")), dwsp__),
                         mandatory=2)
    enumerate = Series(Series(Drop(Text("\\begin{enumerate}")), dwsp__),
                       _itemsequence,
                       Series(Drop(Text("\\end{enumerate}")), dwsp__),
                       mandatory=2)
    itemize = Series(Series(Drop(Text("\\begin{itemize}")), dwsp__),
                     _itemsequence,
                     Series(Drop(Text("\\end{itemize}")), dwsp__),
                     mandatory=2)
    end_generic_block = Series(end_environment,
                               Alternative(
                                   LFF,
                                   Series(dwsp__, Lookahead(Drop(Text("}"))))),
                               mandatory=1)
    begin_generic_block = Series(Lookbehind(_LB), begin_environment)
    generic_block = Series(begin_generic_block,
                           ZeroOrMore(Alternative(sequence, item)),
                           end_generic_block,
                           mandatory=2)
    math_block = Alternative(equation, eqnarray, displaymath)
    _known_environment = Alternative(itemize, enumerate, description, figure,
                                     tabular, quotation, verbatim, math_block)
    _has_block_start = Drop(
        Alternative(Drop(Text("\\begin{")), Drop(Text("\\["))))
    preamble = OneOrMore(Series(Option(_WSPC), _command))
    SubSubSection = Series(Drop(Text("\\subsubsection")),
                           Option(hide_from_toc), heading,
                           ZeroOrMore(Alternative(sequence, Paragraphs)))
    Index = Series(Option(_WSPC), Series(Drop(Text("\\printindex")), dwsp__))
    Bibliography = Series(Option(_WSPC),
                          Series(Drop(Text("\\bibliography")), dwsp__),
                          heading)
    SubSubSections = OneOrMore(Series(Option(_WSPC), SubSubSection))
    SubSection = Series(
        Drop(Text("\\subsection")), Option(hide_from_toc), heading,
        ZeroOrMore(Alternative(sequence, SubSubSections, Paragraphs)))
    SubSections = OneOrMore(Series(Option(_WSPC), SubSection))
    Section = Series(
        Drop(Text("\\section")), Option(hide_from_toc), heading,
        ZeroOrMore(Alternative(sequence, SubSections, Paragraphs)))
    Sections = OneOrMore(Series(Option(_WSPC), Section))
    Chapter = Series(Drop(Text("\\chapter")), Option(hide_from_toc), heading,
                     ZeroOrMore(Alternative(sequence, Sections, Paragraphs)))
    Chapters = OneOrMore(Series(Option(_WSPC), Chapter))
    document = Series(Option(_WSPC),
                      Series(Drop(Text("\\begin{document}")), dwsp__),
                      frontpages,
                      Alternative(Chapters, Sections),
                      Option(Bibliography),
                      Option(Index),
                      Option(_WSPC),
                      Series(Drop(Text("\\end{document}")), dwsp__),
                      Option(_WSPC),
                      EOF,
                      mandatory=2)
    param_block.set(
        Series(Series(Drop(Text("{")), dwsp__), Option(parameters),
               Series(Drop(Text("}")), dwsp__)))
    block.set(
        Series(Series(Drop(Text("{")), dwsp__),
               _block_content,
               Drop(Text("}")),
               mandatory=2))
    _text_element.set(Alternative(_line_element, LINEFEED))
    paragraph.set(
        OneOrMore(Series(NegativeLookahead(blockcmd), _text_element,
                         Option(S))))
    tabular_config.set(
        Series(Series(Drop(Text("{")), dwsp__),
               OneOrMore(
                   Alternative(Series(cfg_celltype, Option(cfg_unit)),
                               cfg_separator, Drop(RegExp(' +')))),
               Series(Drop(Text("}")), dwsp__),
               mandatory=2))
    _block_environment.set(
        Alternative(Series(Lookahead(_has_block_start), _known_environment),
                    generic_block))
    latexdoc = Series(preamble, document, mandatory=1)
    root__ = TreeReduction(latexdoc, CombinedParser.MERGE_TREETOPS)
Ejemplo n.º 17
0
class XML_W3C_SPECGrammar(Grammar):
    r"""Parser for a XML_W3C_SPEC source file.
    """
    AttValue = Forward()
    Attribute = Forward()
    CDSect = Forward()
    Char = Forward()
    CharData = Forward()
    CharRef = Forward()
    Comment = Forward()
    DeclSep = Forward()
    EntityValue = Forward()
    Eq = Forward()
    ExternalID = Forward()
    Name = Forward()
    NameChar = Forward()
    NameStartChar = Forward()
    Nmtoken = Forward()
    PI = Forward()
    PubidLiteral = Forward()
    S = Forward()
    SystemLiteral = Forward()
    TextDecl = Forward()
    VersionInfo = Forward()
    content = Forward()
    cp = Forward()
    element = Forward()
    extSubsetDecl = Forward()
    ignoreSectContents = Forward()
    markupdecl = Forward()
    source_hash__ = "09175b3165ddc1481814046dc639de56"
    anonymous__ = re.compile('..(?<=^)')
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    COMMENT__ = r''
    comment_rx__ = RX_NEVER_MATCH
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    PublicID = Series(Text('PUBLIC'), S, PubidLiteral)
    NotationDecl = Series(Text('<!NOTATION'), S, Name, S,
                          Alternative(ExternalID, PublicID), Option(S),
                          Text('>'), RegExp('[VC: Unique Notation Name]'))
    EncName = Series(
        RegExp('[A-Za-z]'),
        ZeroOrMore(Alternative(RegExp('[A-Za-z0-9._]'), Text('-'))))
    EncodingDecl = Series(
        S, Text('encoding'), Eq,
        Alternative(Series(Text('"'), EncName, Text('"')),
                    Series(Text("\'"), EncName, Text("\'"))))
    extParsedEnt = Series(Option(TextDecl), content)
    TextDecl.set(
        Series(Text('<?xml'), Option(VersionInfo), EncodingDecl, Option(S),
               Text('?>')))
    NDataDecl = Series(S, Text('NDATA'), S, Name)
    ExternalID.set(
        Alternative(Series(Text('SYSTEM'), S, SystemLiteral),
                    Series(Text('PUBLIC'), S, PubidLiteral, S, SystemLiteral)))
    PEDef = Alternative(EntityValue, ExternalID)
    EntityDef = Alternative(EntityValue, Series(ExternalID, Option(NDataDecl)))
    PEDecl = Series(Text('<!ENTITY'), S, Text('%'), S, Name, S, PEDef,
                    Option(S), Text('>'))
    GEDecl = Series(Text('<!ENTITY'), S, Name, S, EntityDef, Option(S),
                    Text('>'))
    EntityDecl = Alternative(GEDecl, PEDecl)
    PEReference = Series(Text('%'), Name, Text(';'))
    EntityRef = Series(Text('&'), Name, Text(';'))
    Reference = Alternative(EntityRef, CharRef)
    CharRef.set(
        Alternative(
            Series(Text('&#'), OneOrMore(RegExp('[0-9]')), Text(';')),
            Series(Text('&#x'), OneOrMore(RegExp('[0-9a-fA-F]')), Text(';'))))
    Ignore = Series(
        NegativeLookahead(
            Series(ZeroOrMore(Char), Alternative(Text('<!['), Text(']]>')),
                   ZeroOrMore(Char))), ZeroOrMore(Char))
    ignoreSectContents.set(
        Series(
            Ignore,
            ZeroOrMore(
                Series(Text('<!['), ignoreSectContents, Text(']]>'), Ignore))))
    ignoreSect = Series(Text('<!['), Option(S), Text('IGNORE'), Option(S),
                        Text('['), ZeroOrMore(ignoreSectContents), Text(']]>'))
    includeSect = Series(Text('<!['), Option(S), Text('INCLUDE'), Option(S),
                         Text('['), extSubsetDecl, Text(']]>'))
    conditionalSect = Alternative(includeSect, ignoreSect)
    DefaultDecl = Alternative(
        Text('#REQUIRED'), Text('#IMPLIED'),
        Series(Option(Series(Text('#FIXED'), S)), AttValue))
    Enumeration = Series(
        Text('('), Option(S), Nmtoken,
        ZeroOrMore(Series(Option(S), Text('|'), Option(S), Nmtoken)),
        Option(S), Text(')'))
    NotationType = Series(
        Text('NOTATION'), S, Text('('), Option(S), Name,
        ZeroOrMore(Series(Option(S), Text('|'), Option(S), Name)), Option(S),
        Text(')'))
    EnumeratedType = Alternative(NotationType, Enumeration)
    TokenizedType = Alternative(Text('IDREFS'), Text('IDREF'), Text('ID'),
                                Text('ENTITY'), Text('ENTITIES'),
                                Text('NMTOKENS'), Text('NMTOKEN'))
    StringType = Text('CDATA')
    AttType = Alternative(StringType, TokenizedType, EnumeratedType)
    AttDef = Series(S, Name, S, AttType, S, DefaultDecl)
    AttlistDecl = Series(Text('<!ATTLIST'), S, Name, ZeroOrMore(AttDef),
                         Option(S), Text('>'))
    Mixed = Alternative(
        Series(Text('('), Option(S), Text('#PCDATA'),
               ZeroOrMore(Series(Option(S), Text('|'), Option(S), Name)),
               Option(S), Text(')*')),
        Series(Text('('), Option(S), Text('#PCDATA'), Option(S), Text(')')))
    seq = Series(Text('('), Option(S), cp,
                 ZeroOrMore(Series(Option(S), Text(','), Option(S), cp)),
                 Option(S), Text(')'))
    choice = Series(Text('('), Option(S), cp,
                    OneOrMore(Series(Option(S), Text('|'), Option(S), cp)),
                    Option(S), Text(')'))
    cp.set(
        Series(Alternative(Name, choice, seq),
               Option(Alternative(Text('?'), Text('*'), Text('+')))))
    children = Series(Alternative(choice, seq),
                      Option(Alternative(Text('?'), Text('*'), Text('+'))))
    contentspec = Alternative(Text('EMPTY'), Text('ANY'), Mixed, children)
    elementdecl = Series(Text('<!ELEMENT'), S, Name, S, contentspec, Option(S),
                         Text('>'))
    EmptyElemTag = Series(Text('<'), Name, ZeroOrMore(Series(S, Attribute)),
                          Option(S), Text('/>'))
    content.set(
        Series(
            Option(CharData),
            ZeroOrMore(
                Series(Alternative(element, Reference, CDSect, PI, Comment),
                       Option(CharData)))))
    ETag = Series(Text('</'), Name, Option(S), Text('>'))
    Attribute.set(Series(Name, Eq, AttValue))
    STag = Series(Text('<'), Name, ZeroOrMore(Series(S, Attribute)), Option(S),
                  Text('>'))
    element.set(Alternative(EmptyElemTag, Series(STag, content, ETag)))
    SDDecl = Series(
        S, Text('standalone'), Eq,
        Alternative(
            Series(Text("\'"), Alternative(Text('yes'), Text('no')),
                   Text("\'")),
            Series(Text('"'), Alternative(Text('yes'), Text('no')),
                   Text('"'))))
    extSubsetDecl.set(
        ZeroOrMore(Alternative(markupdecl, conditionalSect, DeclSep)))
    extSubset = Series(Option(TextDecl), extSubsetDecl)
    markupdecl.set(
        Alternative(elementdecl, AttlistDecl, EntityDecl, NotationDecl, PI,
                    Comment))
    intSubset = ZeroOrMore(Alternative(markupdecl, DeclSep))
    DeclSep.set(Alternative(PEReference, S))
    doctypedecl = Series(
        Text('<!DOCTYPE'), S, Name, Option(Series(S, ExternalID)), Option(S),
        Option(Series(Text('['), intSubset, Text(']'), Option(S))), Text('>'))
    Misc = Alternative(Comment, PI, S)
    VersionNum = Series(Text('1.'), OneOrMore(RegExp('[0-9]')))
    Eq.set(Series(Option(S), Text('='), Option(S)))
    VersionInfo.set(
        Series(
            S, Text('version'), Eq,
            Alternative(Series(Text("\'"), VersionNum, Text("\'")),
                        Series(Text('"'), VersionNum, Text('"')))))
    XMLDecl = Series(Text('<?xml'), VersionInfo, Option(EncodingDecl),
                     Option(SDDecl), Option(S), Text('?>'))
    prolog = Series(Option(XMLDecl), ZeroOrMore(Misc),
                    Option(Series(doctypedecl, ZeroOrMore(Misc))))
    CDEnd = Text(']]>')
    CData = Series(
        NegativeLookahead(
            Series(ZeroOrMore(Char), Text(']]>'), ZeroOrMore(Char))),
        ZeroOrMore(Char))
    CDStart = Text('<![CDATA[')
    CDSect.set(Series(CDStart, CData, CDEnd))
    PITarget = Series(
        NegativeLookahead(
            Series(Alternative(Text('X'), Text('x')),
                   Alternative(Text('M'), Text('m')),
                   Alternative(Text('L'), Text('l')))), Name)
    PI.set(
        Series(
            Text('<?'), PITarget,
            Option(
                Series(
                    S,
                    Series(
                        NegativeLookahead(
                            Series(ZeroOrMore(Char), Text('?>'),
                                   ZeroOrMore(Char))), ZeroOrMore(Char)))),
            Text('?>')))
    Comment.set(
        Series(
            Text('<!--'),
            ZeroOrMore(
                Alternative(
                    Series(NegativeLookahead(Text('-')), Char),
                    Series(Text('-'), Series(NegativeLookahead(Text('-')),
                                             Char)))), Text('-->')))
    CharData.set(
        Series(
            NegativeLookahead(
                Series(ZeroOrMore(RegExp('[^<&]')), Text(']]>'),
                       ZeroOrMore(RegExp('[^<&]')))),
            ZeroOrMore(RegExp('[^<&]'))))
    PubidChar = Alternative(RegExp('\x20'), RegExp('\x0D'), RegExp('\x0A'),
                            RegExp('[a-zA-Z0-9]'),
                            RegExp('[-\'()+,./:=?;!*#@$_%]'))
    PubidLiteral.set(
        Alternative(
            Series(Text('"'), ZeroOrMore(PubidChar), Text('"')),
            Series(
                Text("\'"),
                ZeroOrMore(Series(NegativeLookahead(Text("\'")), PubidChar)),
                Text("\'"))))
    SystemLiteral.set(
        Alternative(
            Series(Text('"'), ZeroOrMore(RegExp('[^"]')), Text('"')),
            Series(Text("\'"), ZeroOrMore(RegExp('[^\']')), Text("\'"))))
    AttValue.set(
        Alternative(
            Series(Text('"'),
                   ZeroOrMore(Alternative(RegExp('[^<&"]'), Reference)),
                   Text('"')),
            Series(Text("\'"),
                   ZeroOrMore(Alternative(RegExp('[^<&\']'), Reference)),
                   Text("\'"))))
    EntityValue.set(
        Alternative(
            Series(
                Text('"'),
                ZeroOrMore(
                    Alternative(RegExp('[^%&"]'), PEReference, Reference)),
                Text('"')),
            Series(
                Text("\'"),
                ZeroOrMore(
                    Alternative(RegExp('[^%&\']'), PEReference, Reference)),
                Text("\'"))))
    Nmtokens = Series(Nmtoken, ZeroOrMore(Series(RegExp('\x20'), Nmtoken)))
    Nmtoken.set(OneOrMore(NameChar))
    Names = Series(Name, ZeroOrMore(Series(RegExp('\x20'), Name)))
    Name.set(Series(NameStartChar, ZeroOrMore(NameChar)))
    NameChar.set(
        Alternative(NameStartChar, Text("-"), Text("."), RegExp('[0-9]'),
                    RegExp('\xB7'), RegExp('[\u0300-\u036F]'),
                    RegExp('[\u203F-\u2040]')))
    NameStartChar.set(
        Alternative(Text(":"), RegExp('[A-Z]'), Text("_"), RegExp('[a-z]'),
                    RegExp('[\xC0-\xD6]'), RegExp('[\xD8-\xF6]'),
                    RegExp('[\xF8-\u02FF]'), RegExp('[\u0370-\u037D]'),
                    RegExp('[\u037F-\u1FFF]'), RegExp('[\u200C-\u200D]'),
                    RegExp('[\u2070-\u218F]'), RegExp('[\u2C00-\u2FEF]'),
                    RegExp('[\u3001-\uD7FF]'), RegExp('[\uF900-\uFDCF]'),
                    RegExp('[\uFDF0-\uFFFD]'),
                    RegExp('[\U00010000-\U000EFFFF]')))
    S.set(
        OneOrMore(
            Alternative(RegExp('\x20'), RegExp('\x09'), RegExp('\x0D'),
                        RegExp('\x0A'))))
    Char.set(
        Alternative(RegExp('\x09'), RegExp('\x0A'), RegExp('\x0D'),
                    RegExp('[\x20-\uD7FF]'), RegExp('[\uE000-\uFFFD]'),
                    RegExp('[\U00010000-\U0010FFFF]')))
    document = Series(prolog, element, ZeroOrMore(Misc))
    root__ = document
Ejemplo n.º 18
0
class FixedEBNFGrammar(Grammar):
    r"""Parser for a FixedEBNF source file.
    """
    countable = Forward()
    element = Forward()
    expression = Forward()
    source_hash__ = "8dbc09df6de2f2758e43fc351a3671c7"
    disposable__ = re.compile(
        'component$|pure_elem$|countable$|FOLLOW_UP$|SYM_REGEX$|ANY_SUFFIX$|EOF$'
    )
    static_analysis_pending__ = []  # type: List[bool]
    parser_initialization__ = ["upon instantiation"]
    error_messages__ = {
        'definition':
        [(re.compile(r','),
          'Delimiter "," not expected in definition!\\nEither this was meant to be a directive and the directive symbol @ is missing\\nor the error is due to inconsistent use of the comma as a delimiter\\nfor the elements of a sequence.'
          )]
    }
    resume_rules__ = {
        'definition': [re.compile(r'\n\s*(?=@|\w+\w*\s*=)')],
        'directive': [re.compile(r'\n\s*(?=@|\w+\w*\s*=)')]
    }
    COMMENT__ = r'(?!#x[A-Fa-f0-9])#.*(?:\n|$)|\/\*(?:.|\n)*?\*\/|\(\*(?:.|\n)*?\*\)'
    comment_rx__ = re.compile(COMMENT__)
    WHITESPACE__ = r'\s*'
    WSP_RE__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
    wsp__ = Whitespace(WSP_RE__)
    dwsp__ = Drop(Whitespace(WSP_RE__))
    HEXCODE = RegExp('[A-Fa-f0-9]{1,8}')
    SYM_REGEX = RegExp('(?!\\d)\\w+')
    RE_CORE = RegExp('(?:(?<!\\\\)\\\\(?:/)|[^/])*')
    regex_heuristics = Alternative(RegExp('[^ ]'),
                                   RegExp('[^/\\n*?+\\\\]*[*?+\\\\][^/\\n]/'))
    literal_heuristics = Alternative(
        RegExp('~?\\s*"(?:[\\\\]\\]|[^\\]]|[^\\\\]\\[[^"]*)*"'),
        RegExp("~?\\s*'(?:[\\\\]\\]|[^\\]]|[^\\\\]\\[[^']*)*'"),
        RegExp('~?\\s*`(?:[\\\\]\\]|[^\\]]|[^\\\\]\\[[^`]*)*`'),
        RegExp('~?\\s*´(?:[\\\\]\\]|[^\\]]|[^\\\\]\\[[^´]*)*´'),
        RegExp('~?\\s*/(?:[\\\\]\\]|[^\\]]|[^\\\\]\\[[^/]*)*/'))
    char_range_heuristics = NegativeLookahead(
        Alternative(
            RegExp('[\\n\\t ]'), Series(dwsp__, literal_heuristics),
            Series(Option(Alternative(Text("::"), Text(":?"), Text(":"))),
                   SYM_REGEX, RegExp('\\s*\\]'))))
    CH_LEADIN = Text("0x")
    RE_LEADOUT = Text("/")
    RE_LEADIN = Text("/")
    TIMES = Text("*")
    RNG_DELIM = Text(",")
    RNG_CLOSE = Text("}")
    RNG_OPEN = Text("{")
    ENDL = Text("")
    AND = Text("")
    OR = Text("|")
    DEF = Text("=")
    EOF = Drop(NegativeLookahead(RegExp('.')))
    whitespace = Series(RegExp('~'), dwsp__)
    any_char = Series(Text("."), dwsp__)
    free_char = Alternative(RegExp('[^\\n\\[\\]\\\\]'),
                            RegExp('\\\\[nrt`´\'"(){}\\[\\]/\\\\]'))
    character = Series(CH_LEADIN, HEXCODE)
    char_range = Series(
        Text("["), Lookahead(char_range_heuristics), Option(Text("^")),
        Alternative(character, free_char),
        ZeroOrMore(Alternative(Series(Option(Text("-")), character),
                               free_char)), Series(Text("]"), dwsp__))
    regexp = Series(RE_LEADIN, RE_CORE, RE_LEADOUT, dwsp__)
    plaintext = Alternative(
        Series(RegExp('`(?:(?<!\\\\)\\\\`|[^`])*?`'), dwsp__),
        Series(RegExp('´(?:(?<!\\\\)\\\\´|[^´])*?´'), dwsp__))
    literal = Alternative(
        Series(RegExp('"(?:(?<!\\\\)\\\\"|[^"])*?"'), dwsp__),
        Series(RegExp("'(?:(?<!\\\\)\\\\'|[^'])*?'"), dwsp__))
    symbol = Series(SYM_REGEX, dwsp__)
    multiplier = Series(RegExp('[1-9]\\d*'), dwsp__)
    no_range = Alternative(NegativeLookahead(multiplier),
                           Series(Lookahead(multiplier), TIMES))
    range = Series(RNG_OPEN, dwsp__, multiplier,
                   Option(Series(RNG_DELIM, dwsp__, multiplier)), RNG_CLOSE,
                   dwsp__)
    counted = Alternative(
        Series(countable, range), Series(countable, TIMES, dwsp__, multiplier),
        Series(multiplier, TIMES, dwsp__, countable, mandatory=3))
    option = Alternative(
        Series(Series(Text("["), dwsp__),
               expression,
               Series(Text("]"), dwsp__),
               mandatory=1), Series(element, Series(Text("?"), dwsp__)))
    repetition = Alternative(
        Series(Series(Text("{"), dwsp__),
               no_range,
               expression,
               Series(Text("}"), dwsp__),
               mandatory=2),
        Series(element, Series(Text("*"), dwsp__), no_range))
    oneormore = Alternative(
        Series(Series(Text("{"), dwsp__), no_range, expression,
               Series(Text("}+"), dwsp__)),
        Series(element, Series(Text("+"), dwsp__)))
    group = Series(Series(Text("("), dwsp__),
                   no_range,
                   expression,
                   Series(Text(")"), dwsp__),
                   mandatory=2)
    retrieveop = Alternative(Series(Text("::"), dwsp__),
                             Series(Text(":?"), dwsp__),
                             Series(Text(":"), dwsp__))
    flowmarker = Alternative(Series(Text("!"), dwsp__),
                             Series(Text("&"), dwsp__),
                             Series(Text("<-!"), dwsp__),
                             Series(Text("<-&"), dwsp__))
    ANY_SUFFIX = RegExp('[?*+]')
    literals = OneOrMore(literal)
    pure_elem = Series(element, NegativeLookahead(ANY_SUFFIX), mandatory=1)
    procedure = Series(SYM_REGEX, Series(Text("()"), dwsp__))
    term = Alternative(oneormore, counted, repetition, option, pure_elem)
    difference = Series(
        term,
        Option(
            Series(Series(Text("-"), dwsp__),
                   Alternative(oneormore, pure_elem),
                   mandatory=1)))
    lookaround = Series(flowmarker,
                        Alternative(oneormore, pure_elem),
                        mandatory=1)
    interleave = Series(
        difference,
        ZeroOrMore(
            Series(Series(Text("°"), dwsp__),
                   Option(Series(Text("§"), dwsp__)), difference)))
    sequence = Series(
        Option(Series(Text("§"), dwsp__)), Alternative(interleave, lookaround),
        ZeroOrMore(
            Series(AND, dwsp__, Option(Series(Text("§"), dwsp__)),
                   Alternative(interleave, lookaround))))
    FOLLOW_UP = Alternative(Text("@"), symbol, EOF)
    definition = Series(symbol,
                        DEF,
                        dwsp__,
                        Option(Series(OR, dwsp__)),
                        expression,
                        ENDL,
                        dwsp__,
                        Lookahead(FOLLOW_UP),
                        mandatory=1)
    component = Alternative(regexp, literals, procedure,
                            Series(symbol, NegativeLookahead(DEF)))
    directive = Series(Series(Text("@"), dwsp__),
                       symbol,
                       Series(Text("="), dwsp__),
                       component,
                       ZeroOrMore(Series(Series(Text(","), dwsp__),
                                         component)),
                       Lookahead(FOLLOW_UP),
                       mandatory=1)
    element.set(
        Alternative(Series(Option(retrieveop), symbol,
                           NegativeLookahead(DEF)), literal, plaintext, regexp,
                    Series(character, dwsp__), any_char, whitespace, group))
    countable.set(Alternative(option, oneormore, element))
    expression.set(Series(sequence, ZeroOrMore(Series(OR, dwsp__, sequence))))
    syntax = Series(dwsp__, ZeroOrMore(Alternative(definition, directive)),
                    EOF)
    root__ = syntax