Example #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
Example #2
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
Example #3
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
Example #4
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
Example #5
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)
Example #6
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)
Example #7
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
Example #8
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