forked from python-openxml/cxml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
54 lines (47 loc) · 1.57 KB
/
parser.py
File metadata and controls
54 lines (47 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# encoding: utf-8
"""
Parser for CXML language.
"""
from __future__ import (
absolute_import, division, print_function, unicode_literals
)
from .lib.grammar import Productions
from .lib.parser import Parser
from .symbols import (
COLON, COMMA, EQUAL, LBRACE, LPAREN, NAME, RBRACE, RPAREN, SLASH, SNTL,
TEXT, attr, attr_list, attrs, element, nsdecl, qname, root, root_element,
str_attr, tree, tree_list, trees,
)
productions = Productions.from_seq(
(root, (root_element, SLASH, trees, SNTL)),
(root, (root_element, SNTL)),
(root_element, (qname, attrs, TEXT)),
(root_element, (qname, attrs)),
(root_element, (qname, TEXT)),
(root_element, (qname,)),
(trees, (LPAREN, tree_list, RPAREN)),
(trees, (tree,)),
(tree_list, (tree, COMMA, tree_list)),
(tree_list, (tree,)),
(tree, (element, SLASH, trees)),
(tree, (element,)),
(element, (qname, attrs, TEXT)),
(element, (qname, attrs)),
(element, (qname, TEXT)),
(element, (qname,)),
(attrs, (LBRACE, attr_list, RBRACE)),
(attr_list, (attr, COMMA, attr_list)),
(attr_list, (attr,)),
(attr, (str_attr,)),
(attr, (nsdecl,)),
(str_attr, (qname, EQUAL, TEXT)),
(qname, (NAME, COLON, NAME)),
(qname, (NAME,)),
(nsdecl, (NAME, COLON)),
)
class CxmlParser(Parser):
"""
Parser for Compact XML Expression Languate (CXML).
"""
def __init__(self, lexer):
super(CxmlParser, self).__init__(lexer, productions)