[voltLib] Context can take multiple except/in_context, multiple left or right contexts
This commit is contained in:
parent
6f4f7849cf
commit
ffa929b404
@ -61,3 +61,10 @@ class SubstitutionDefinition(ast.Statement):
|
|||||||
def __init__(self, location, src, dest):
|
def __init__(self, location, src, dest):
|
||||||
ast.Statement.__init__(self, location)
|
ast.Statement.__init__(self, location)
|
||||||
self.mapping = zip(src, dest)
|
self.mapping = zip(src, dest)
|
||||||
|
|
||||||
|
class ContextDefinition(ast.Statement):
|
||||||
|
def __init__(self, location, ex_or_in, left=[], right=[]):
|
||||||
|
ast.Statement.__init__(self, location)
|
||||||
|
self.ex_or_in = ex_or_in
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
@ -162,8 +162,8 @@ class Parser(object):
|
|||||||
if self.next_token_ == "COMMENTS":
|
if self.next_token_ == "COMMENTS":
|
||||||
self.expect_keyword_("COMMENTS")
|
self.expect_keyword_("COMMENTS")
|
||||||
comments = self.expect_string_()
|
comments = self.expect_string_()
|
||||||
context = None
|
context = []
|
||||||
if self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
|
while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
|
||||||
context = self.parse_context_()
|
context = self.parse_context_()
|
||||||
as_pos_or_sub = self.expect_name_()
|
as_pos_or_sub = self.expect_name_()
|
||||||
sub = None
|
sub = None
|
||||||
@ -178,16 +178,30 @@ class Parser(object):
|
|||||||
return def_lookup
|
return def_lookup
|
||||||
|
|
||||||
def parse_context_(self):
|
def parse_context_(self):
|
||||||
except_or_in = self.expect_name_()
|
location = self.cur_token_location_
|
||||||
assert except_or_in in ("EXCEPT_CONTEXT", "IN_CONTEXT")
|
contexts = []
|
||||||
side = None
|
while self.next_token_ in ("EXCEPT_CONTEXT", "IN_CONTEXT"):
|
||||||
coverage = None
|
side = None
|
||||||
if self.next_token_ != "END_CONTEXT" :
|
coverage = None
|
||||||
side = self.expect_name_()
|
ex_or_in = self.expect_name_()
|
||||||
assert side in ("LEFT", "RIGHT")
|
side_contexts = []
|
||||||
coverage = self.parse_coverage_()
|
if self.next_token_ != "END_CONTEXT":
|
||||||
self.expect_keyword_("END_CONTEXT")
|
left = []
|
||||||
return (except_or_in, side)
|
right = []
|
||||||
|
while self.next_token_ in ("LEFT", "RIGHT"):
|
||||||
|
side = self.expect_name_()
|
||||||
|
coverage = self.parse_coverage_()
|
||||||
|
if side == "LEFT":
|
||||||
|
left.append(coverage)
|
||||||
|
else:
|
||||||
|
right.append(coverage)
|
||||||
|
self.expect_keyword_("END_CONTEXT")
|
||||||
|
context = ast.ContextDefinition(location, ex_or_in, left,
|
||||||
|
right)
|
||||||
|
contexts.append(context)
|
||||||
|
else:
|
||||||
|
self.expect_keyword_("END_CONTEXT")
|
||||||
|
return contexts
|
||||||
|
|
||||||
def parse_substitution_(self):
|
def parse_substitution_(self):
|
||||||
assert self.is_cur_keyword_("AS_SUBSTITUTION")
|
assert self.is_cur_keyword_("AS_SUBSTITUTION")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user