# GENERATE END
# syntax classes
- class Name(element.Element):
- # GENERATE ELEMENT() BEGIN
- def __init__(
- self,
- tag = 'PLex_Name',
- attrib = {},
- text = '',
- children = []
- ):
- element.Element.__init__(
- self,
- tag,
- attrib,
- text,
- children
- )
- def copy(self, factory = None):
- result = element.Element.copy(
- self,
- Name if factory is None else factory
- )
- return result
- def __repr__(self):
- params = []
- self.repr_serialize(params)
- return 'ast.PLex.Name({0:s})'.format(', '.join(params))
- # GENERATE END
-
- class Section(element.Element):
+ class Text(element.Element):
# GENERATE ELEMENT() BEGIN
def __init__(
self,
- tag = 'PLex_Section',
+ tag = 'PLex_Text',
attrib = {},
text = '',
children = []
def copy(self, factory = None):
result = element.Element.copy(
self,
- Section if factory is None else factory
+ Text if factory is None else factory
)
return result
def __repr__(self):
params = []
self.repr_serialize(params)
- return 'ast.PLex.Section({0:s})'.format(', '.join(params))
+ return 'ast.PLex.Text({0:s})'.format(', '.join(params))
# GENERATE END
- def post_process(
- self,
- plex,
- name_to_start_condition,
- all_start_conditions,
- inclusive_start_conditions
- ):
- for i in self:
- i.post_process(
- plex,
- self,
- name_to_start_condition,
- all_start_conditions,
- inclusive_start_conditions
- )
+ def get_text(self):
+ return element.get_text(self, 0)
- class Text(element.Element):
+ class Name(Text):
# GENERATE ELEMENT() BEGIN
def __init__(
self,
- tag = 'PLex_Text',
+ tag = 'PLex_Name',
attrib = {},
text = '',
children = []
):
- element.Element.__init__(
+ PLex.Text.__init__(
self,
tag,
attrib,
children
)
def copy(self, factory = None):
- result = element.Element.copy(
+ result = PLex.Text.copy(
self,
- Text if factory is None else factory
+ Name if factory is None else factory
)
return result
def __repr__(self):
params = []
self.repr_serialize(params)
- return 'ast.PLex.Text({0:s})'.format(', '.join(params))
+ return 'ast.PLex.Name({0:s})'.format(', '.join(params))
# GENERATE END
- class Section1Or2(Section):
+ class Section1Or2(element.Element):
class CodeBlock(Item):
# GENERATE ELEMENT() BEGIN
def __init__(
children = [],
code_blocks_text = []
):
- PLex.Section.__init__(
+ element.Element.__init__(
self,
tag,
attrib,
)
self.code_blocks_text = code_blocks_text
def serialize(self, ref_list):
- PLex.Section.serialize(self, ref_list)
+ element.Element.serialize(self, ref_list)
self.set(
'code_blocks_text',
' '.join([element.serialize_ref(i, ref_list) for i in self.code_blocks_text])
)
def deserialize(self, ref_list):
- PLex.Section.deserialize(self, ref_list)
+ element.Element.deserialize(self, ref_list)
self.code_blocks_text = [
element.deserialize_ref(i, ref_list)
for i in self.get('code_blocks_text', '').split()
]
def copy(self, factory = None):
- result = PLex.Section.copy(
+ result = element.Element.copy(
self,
Section1Or2 if factory is None else factory
)
result.code_blocks_text = self.code_blocks_text
return result
def repr_serialize(self, params):
- PLex.Section.repr_serialize(self, params)
+ element.Element.repr_serialize(self, params)
if len(self.code_blocks_text):
params.append(
'code_blocks_text = [{0:s}]'.format(
self.repr_serialize(params)
return 'ast.PLex.Section1Or2({0:s})'.format(', '.join(params))
# GENERATE END
+ def post_process(
+ self,
+ plex,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions
+ ):
+ for i in self:
+ i.post_process(
+ plex,
+ self,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions
+ )
class Section1(Section1Or2):
class Options(Item):
inclusive_start_conditions
):
for i in self:
- assert isinstance(i, PLex.Name)
- name = element.get_text(i, 0)
+ name = i.get_text()
assert name not in name_to_start_condition
name_to_start_condition[name] = len(plex.start_conditions)
all_start_conditions.add(len(plex.start_conditions))
self.reject = True
self.yymore = True
self.yywrap = True
- PLex.Section.post_process(
+ PLex.Section1Or2.post_process(
self,
plex,
name_to_start_condition,
else:
start_condition_set = set()
for i in start_conditions:
- assert isinstance(i, PLex.Name)
start_condition_set.add(
- name_to_start_condition[element.get_text(i, 0)]
+ name_to_start_condition[i.get_text()]
)
expr = self[1]
trailing_context = self[2]
return 'ast.PLex.Section2({0:s})'.format(', '.join(params))
# GENERATE END
- class Section3(Section):
+ class Section3(Text):
# GENERATE ELEMENT() BEGIN
def __init__(
self,
text = '',
children = []
):
- PLex.Section.__init__(
+ PLex.Text.__init__(
self,
tag,
attrib,
children
)
def copy(self, factory = None):
- result = PLex.Section.copy(
+ result = PLex.Text.copy(
self,
Section3 if factory is None else factory
)
self.repr_serialize(params)
return 'ast.PLex({0:s})'.format(', '.join(params))
# GENERATE END
+
def post_process(self):
# variables that will be serialized
self.start_conditions = [
]
self.actions_text = []
self.eof_actions_text = [
- PLex.Section2.Rule.Action(text = '\t\t\t\tyyterminate();\n')
+ PLex.Text(text = '\t\t\t\tyyterminate();\n')
]
# variables that won't be serialized
all_start_conditions = set([0])
inclusive_start_conditions = set([0])
- for i in self:
- i.post_process(
- self,
- name_to_start_condition,
- all_start_conditions,
- inclusive_start_conditions
- )
+ # perform the semantic analysis pass
+ self[0].post_process(
+ self,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions
+ )
+ self[1].post_process(
+ self,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions
+ )
# add default rule to each expr, then make it greedy
for i in range(len(self.start_conditions)):
]
)
self.actions_text.append(PLex.Text(text = 'ECHO;\n'))
+
def to_nfa(self):
_nfa = nfa.NFA()
for i in self.start_conditions:
'Item': Item,
'PLex': PLex,
'PLex_StartCondition': PLex.StartCondition,
- 'PLex_Name': PLex.Name,
- 'PLex_Section': PLex.Section,
'PLex_Text': PLex.Text,
+ 'PLex_Name': PLex.Name,
'PLex_Section1Or2': PLex.Section1Or2,
'PLex_Section1Or2_CodeBlock': PLex.Section1Or2.CodeBlock,
'PLex_Section1': PLex.Section1,