##// END OF EJS Templates
parser: separate actions for primary expression and prefix operator...
Yuya Nishihara -
r25815:e71e5629 default
parent child Browse files
Show More
@@ -10,21 +10,21 b' import parser, error, util, merge'
10 from i18n import _
10 from i18n import _
11
11
12 elements = {
12 elements = {
13 # token-type: binding-strength, prefix, infix, suffix
13 # token-type: binding-strength, primary, prefix, infix, suffix
14 "(": (20, ("group", 1, ")"), ("func", 1, ")"), None),
14 "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None),
15 "-": (5, ("negate", 19), ("minus", 5), None),
15 "-": (5, None, ("negate", 19), ("minus", 5), None),
16 "not": (10, ("not", 10), None, None),
16 "not": (10, None, ("not", 10), None, None),
17 "!": (10, ("not", 10), None, None),
17 "!": (10, None, ("not", 10), None, None),
18 "and": (5, None, ("and", 5), None),
18 "and": (5, None, None, ("and", 5), None),
19 "&": (5, None, ("and", 5), None),
19 "&": (5, None, None, ("and", 5), None),
20 "or": (4, None, ("or", 4), None),
20 "or": (4, None, None, ("or", 4), None),
21 "|": (4, None, ("or", 4), None),
21 "|": (4, None, None, ("or", 4), None),
22 "+": (4, None, ("or", 4), None),
22 "+": (4, None, None, ("or", 4), None),
23 ",": (2, None, ("list", 2), None),
23 ",": (2, None, None, ("list", 2), None),
24 ")": (0, None, None, None),
24 ")": (0, None, None, None, None),
25 "symbol": (0, ("symbol",), None, None),
25 "symbol": (0, "symbol", None, None, None),
26 "string": (0, ("string",), None, None),
26 "string": (0, "string", None, None, None),
27 "end": (0, None, None, None),
27 "end": (0, None, None, None, None),
28 }
28 }
29
29
30 keywords = set(['and', 'or', 'not'])
30 keywords = set(['and', 'or', 'not'])
@@ -11,8 +11,8 b''
11
11
12 # takes a tokenizer and elements
12 # takes a tokenizer and elements
13 # tokenizer is an iterator that returns (type, value, pos) tuples
13 # tokenizer is an iterator that returns (type, value, pos) tuples
14 # elements is a mapping of types to binding strength, prefix, infix and
14 # elements is a mapping of types to binding strength, primary, prefix, infix
15 # suffix actions
15 # and suffix actions
16 # an action is a tree node name, a tree label, and an optional match
16 # an action is a tree node name, a tree label, and an optional match
17 # __call__(program) parses program into a labeled tree
17 # __call__(program) parses program into a labeled tree
18
18
@@ -31,7 +31,7 b' class parser(object):'
31 return t
31 return t
32 def _hasnewterm(self):
32 def _hasnewterm(self):
33 'True if next token may start new term'
33 'True if next token may start new term'
34 return bool(self._elements[self.current[0]][1])
34 return any(self._elements[self.current[0]][1:3])
35 def _match(self, m):
35 def _match(self, m):
36 'make sure the tokenizer matches an end condition'
36 'make sure the tokenizer matches an end condition'
37 if self.current[0] != m:
37 if self.current[0] != m:
@@ -50,17 +50,17 b' class parser(object):'
50 def _parse(self, bind=0):
50 def _parse(self, bind=0):
51 token, value, pos = self._advance()
51 token, value, pos = self._advance()
52 # handle prefix rules on current token
52 # handle prefix rules on current token
53 prefix = self._elements[token][1]
53 primary, prefix = self._elements[token][1:3]
54 if not prefix:
54 if primary:
55 expr = (primary, value)
56 elif prefix:
57 expr = (prefix[0], self._parseoperand(*prefix[1:]))
58 else:
55 raise error.ParseError(_("not a prefix: %s") % token, pos)
59 raise error.ParseError(_("not a prefix: %s") % token, pos)
56 if len(prefix) == 1:
57 expr = (prefix[0], value)
58 else:
59 expr = (prefix[0], self._parseoperand(*prefix[1:]))
60 # gather tokens until we meet a lower binding strength
60 # gather tokens until we meet a lower binding strength
61 while bind < self._elements[self.current[0]][0]:
61 while bind < self._elements[self.current[0]][0]:
62 token, value, pos = self._advance()
62 token, value, pos = self._advance()
63 infix, suffix = self._elements[token][2:]
63 infix, suffix = self._elements[token][3:]
64 # check for suffix - next token isn't a valid prefix
64 # check for suffix - next token isn't a valid prefix
65 if suffix and not self._hasnewterm():
65 if suffix and not self._hasnewterm():
66 expr = (suffix[0], expr)
66 expr = (suffix[0], expr)
@@ -115,31 +115,31 b' def _revsbetween(repo, roots, heads):'
115 return baseset(sorted(reachable))
115 return baseset(sorted(reachable))
116
116
117 elements = {
117 elements = {
118 # token-type: binding-strength, prefix, infix, suffix
118 # token-type: binding-strength, primary, prefix, infix, suffix
119 "(": (21, ("group", 1, ")"), ("func", 1, ")"), None),
119 "(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None),
120 "##": (20, None, ("_concat", 20), None),
120 "##": (20, None, None, ("_concat", 20), None),
121 "~": (18, None, ("ancestor", 18), None),
121 "~": (18, None, None, ("ancestor", 18), None),
122 "^": (18, None, ("parent", 18), ("parentpost", 18)),
122 "^": (18, None, None, ("parent", 18), ("parentpost", 18)),
123 "-": (5, ("negate", 19), ("minus", 5), None),
123 "-": (5, None, ("negate", 19), ("minus", 5), None),
124 "::": (17, ("dagrangepre", 17), ("dagrange", 17),
124 "::": (17, None, ("dagrangepre", 17), ("dagrange", 17),
125 ("dagrangepost", 17)),
125 ("dagrangepost", 17)),
126 "..": (17, ("dagrangepre", 17), ("dagrange", 17),
126 "..": (17, None, ("dagrangepre", 17), ("dagrange", 17),
127 ("dagrangepost", 17)),
127 ("dagrangepost", 17)),
128 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
128 ":": (15, None, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
129 "not": (10, ("not", 10), None, None),
129 "not": (10, None, ("not", 10), None, None),
130 "!": (10, ("not", 10), None, None),
130 "!": (10, None, ("not", 10), None, None),
131 "and": (5, None, ("and", 5), None),
131 "and": (5, None, None, ("and", 5), None),
132 "&": (5, None, ("and", 5), None),
132 "&": (5, None, None, ("and", 5), None),
133 "%": (5, None, ("only", 5), ("onlypost", 5)),
133 "%": (5, None, None, ("only", 5), ("onlypost", 5)),
134 "or": (4, None, ("or", 4), None),
134 "or": (4, None, None, ("or", 4), None),
135 "|": (4, None, ("or", 4), None),
135 "|": (4, None, None, ("or", 4), None),
136 "+": (4, None, ("or", 4), None),
136 "+": (4, None, None, ("or", 4), None),
137 "=": (3, None, ("keyvalue", 3), None),
137 "=": (3, None, None, ("keyvalue", 3), None),
138 ",": (2, None, ("list", 2), None),
138 ",": (2, None, None, ("list", 2), None),
139 ")": (0, None, None, None),
139 ")": (0, None, None, None, None),
140 "symbol": (0, ("symbol",), None, None),
140 "symbol": (0, "symbol", None, None, None),
141 "string": (0, ("string",), None, None),
141 "string": (0, "string", None, None, None),
142 "end": (0, None, None, None),
142 "end": (0, None, None, None, None),
143 }
143 }
144
144
145 keywords = set(['and', 'or', 'not'])
145 keywords = set(['and', 'or', 'not'])
@@ -15,17 +15,17 b' import minirst'
15 # template parsing
15 # template parsing
16
16
17 elements = {
17 elements = {
18 # token-type: binding-strength, prefix, infix, suffix
18 # token-type: binding-strength, primary, prefix, infix, suffix
19 "(": (20, ("group", 1, ")"), ("func", 1, ")"), None),
19 "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None),
20 ",": (2, None, ("list", 2), None),
20 ",": (2, None, None, ("list", 2), None),
21 "|": (5, None, ("|", 5), None),
21 "|": (5, None, None, ("|", 5), None),
22 "%": (6, None, ("%", 6), None),
22 "%": (6, None, None, ("%", 6), None),
23 ")": (0, None, None, None),
23 ")": (0, None, None, None, None),
24 "integer": (0, ("integer",), None, None),
24 "integer": (0, "integer", None, None, None),
25 "symbol": (0, ("symbol",), None, None),
25 "symbol": (0, "symbol", None, None, None),
26 "string": (0, ("string",), None, None),
26 "string": (0, "string", None, None, None),
27 "template": (0, ("template",), None, None),
27 "template": (0, "template", None, None, None),
28 "end": (0, None, None, None),
28 "end": (0, None, None, None, None),
29 }
29 }
30
30
31 def tokenize(program, start, end):
31 def tokenize(program, start, end):
General Comments 0
You need to be logged in to leave comments. Login now