groups = i.groups0 + i.groups1
group_rules_text.append(
regex.Text(
- text = '''global yy_groups, yy_groups_by_name, yy_action
+ [
+ '''global yy_groups, yy_groups_by_name, yy_action
yy_groups = [yy_group_text[:yy_group_stack[-1]]{0:s}]
yy_groups_by_name = {{}}
yy_action = yy_action{1:d}
'''.format(
- ', None' * len(groups),
- i.action
- )
+ ', None' * len(groups),
+ i.action
+ )
+ ]
)
)
group_actions_text.extend(
groups[j].children[0]
if isinstance(groups[j], regex.RegexGroupAction) else
regex.Text(
- text = '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+ [
+ '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
yy_element = yy_group_element(
yy_group_stack[-1],
yy_group_stack[-2],
)
del yy_group_stack[-2:]
'''.format(
- j + 1,
- groups[j].children[0].get_text()
- )
+ j + 1,
+ groups[j].children[0].get_text()
+ )
+ ]
)
if isinstance(groups[j], regex.RegexGroupElement) else
regex.Text(
- text = '''yy_temp = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+ [
+ '''yy_temp = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
yy_groups[{0:d}] = yy_temp
yy_groups_by_name['{1:s}'] = yy_temp
del yy_group_stack[-2:]
'''.format(
- j + 1,
- groups[j].children[0].get_text()
- )
+ j + 1,
+ groups[j].children[0].get_text()
+ )
+ ]
)
if isinstance(groups[j], regex.RegexGroupName) else
regex.Text(
- text = '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+ [
+ '''yy_groups[{0:d}] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
del yy_group_stack[-2:]
'''.format(
- j + 1
- )
+ j + 1
+ )
+ ]
)
)
for j in range(len(groups))
)
group_rules_text.append(
regex.Text(
- text = '''global yy_groups, yy_groups_by_name, yy_action
+ [
+ '''global yy_groups, yy_groups_by_name, yy_action
yy_groups = [yy_group_text[:yy_group_stack[-1]]]
yy_groups_by_name = {{}}
yy_action = yy_action{0:d}
'''.format(
- _ast.default_action
- )
+ _ast.default_action
+ )
+ ]
)
)
%%
def factory(tag, *args, **kwargs):
- return tag_to_class.get(tag, regex.factory)(tag, attrib, *args, **kwargs)
+ _class = tag_to_class.get(tag)
+ return (
+ regex.factory(tag, *args, **kwargs)
+ if _class is None else
+ _class(*args, **kwargs)
+ )
@method(Item)
def post_process(
]
self.actions_text = []
self.eof_actions_text = [
- AST.Text(text = '\t\t\t\tyyterminate();\n')
+ AST.Text(['\t\t\t\tyyterminate();\n'])
]
self.flex_rules = []
self.n_groups = 0
self.default_action = len(self.actions_text)
self.actions_text.append(
AST.Text(
- text = (
+ [
'ECHO;\n'
if self.children[0].default else
'YY_FATAL_ERROR( "flex scanner jammed" );\n'
- )
+ ]
)
)
del post_process
n_characters = 0x100
def factory(tag, *args, **kwargs):
- return tag_to_class.get(tag, element.Element)(tag, *args, **kwargs)
+ return tag_to_class[tag](*args, **kwargs)
@method(Regex)
def post_process(self, groups, caseless = False):
def yy_group_end_element():
yy_element_stack.append([])
-def yy_group_element(pos0, pos1, stack, factory, *args, **kwargs):
- _element = factory(*args, **kwargs)
+def yy_group_element(pos0, pos1, stack, _class, *args, **kwargs):
+ _element = _class(*args, **kwargs)
del _element.text[:]
for pos2, pos3, i in reversed(stack):
_element.text.append(yy_group_text[pos0:pos2])
# GENERATE SECTION2
-def yylex(factory = element.Element, *args, **kwargs):
+def yylex(_class = element.Element, *args, **kwargs):
global \
yyin, \
yy_threads0, \
# GENERATE SECTION2INITIAL
- yy_element_space = factory(*args, **kwargs)
- yy_element_token = factory(*args, **kwargs)
+ yy_element_space = _class(*args, **kwargs)
+ yy_element_token = _class(*args, **kwargs)
while True:
while yytext_len:
block = yy_buffer_stack[-1].next
0,
yytext_len,
yy_element_stack.pop(),
- factory,
+ _class,
*args,
**kwargs
)
def yy_group_end_element():
yy_element_stack.append([])
-def yy_group_element(pos0, pos1, stack, factory, *args, **kwargs):
- _element = factory(*args, **kwargs)
+def yy_group_element(pos0, pos1, stack, _class, *args, **kwargs):
+ _element = _class(*args, **kwargs)
del _element.text[:]
for pos2, pos3, i in reversed(stack):
_element.text.append(yy_group_text[pos0:pos2])
# GENERATE SECTION2
-def yylex(factory = element.Element, *args, **kwargs):
+def yylex(_class = element.Element, *args, **kwargs):
global \
yyin, \
yy_threads0, \
# GENERATE SECTION2INITIAL
- yy_element_space = factory(*args, **kwargs)
- yy_element_token = factory(*args, **kwargs)
+ yy_element_space = _class(*args, **kwargs)
+ yy_element_token = _class(*args, **kwargs)
while True:
while yytext_len:
block = yy_buffer_stack[-1].next
0,
yytext_len,
yy_element_stack.pop(),
- factory,
+ _class,
*args,
**kwargs
)
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-%{
- import element
-%}
-
%%
class Text;
%%
-def factory(tag, attrib = {}, *args, **kwargs):
- return tag_to_class.get(tag, element.Element)(tag, attrib, *args, **kwargs)
+def factory(tag, *args, **kwargs):
+ return tag_to_class[tag](*args, **kwargs)
@method(Text)
def get_text(self):