),
''.join(
[
- '''def yy_rule{0:d}(match, pos):
+ '''def yy_rule{0:d}():
{1:s}'''.format(
i,
regex_text_to_python(group_rules_text[i], ' ')
),
''.join(
[
- '''def yy_group{0:d}(match, pos):
+ '''def yy_group{0:d}():
{1:s}'''.format(
i,
regex_text_to_python(group_actions_text[i], ' ')
yy_threads1 = [None]
yy_prefix_slop = 1
+yy_group_text = None
+yy_group_stack = None
+yy_action = None
yytext = ''
yytext_len = 0
-yy_action = None
-yy_group_stack = None
-
def REJECT():
raise YYReject()
yytext_len -= i
yy_buffer_stack[-1].next = YYBufferBlock(yy_buffer_stack[-1].next, 0, text)
-def yy_rule_start(match, pos):
+def yy_rule_start():
global yytext, yytext_len
- yytext = match[:pos]
- yytext_len = pos
+ yytext_len = yy_group_stack.pop()
+ yytext = yy_group_text[:yytext_len]
-def yy_group_end(match, pos):
- yy_group_stack.append(pos)
+def yy_group_end():
+ pass
# GENERATE SECTION2
yy_threads0, \
yy_threads1, \
yy_prefix_slop, \
- yytext, \
- yytext_len, \
+ yy_group_text, \
+ yy_group_stack, \
yy_action, \
- yy_group_stack
+ yytext, \
+ yytext_len
# GENERATE SECTION2INITIAL
match += block.text[block_pos - i:]
for i in yy_dfa_states[state][2]:
+ yy_group_text = match
+ yy_group_stack = []
+ yy_action = None
yytext = None
yytext_len = None
- yy_action = None
- yy_group_stack = []
thread = yy_threads0[yy_prefix_slop + i]
#print('thread', thread)
while thread is not None:
pos, ref_data, thread = thread
- ref_data(match, pos)
+ yy_group_stack.append(pos)
+ ref_data()
#print('yytext', yytext)
#print('yytext_len', yytext_len)
#print('yy_action', yy_action)
- #print('yy_group_stack', yy_group_stack)
try:
return yy_action()
NUM = 0x100
yylval = None
groups = None
+groups_by_name = {}
def gc(n):
- global groups
+ global groups, groups_by_name
groups = [None for i in range(n)]
- yy_group_stack.pop()
-def g(n, match, pos):
- groups[n] = match[pos:yy_group_stack.pop()]
+ groups_by_name = {}
+ del yy_group_stack[-2:]
+def g(n, name = None):
+ if groups[n] is None:
+ groups[n] = yy_group_text[yy_group_stack[-1]:yy_group_stack[-2]]
+ if name is not None and name not in groups_by_name:
+ groups_by_name[name] = groups[n]
+ del yy_group_stack[-2:]
%}
-DIGIT (?{g(1, match, pos)}[0-9]+)\.?|(?{g(2, match, pos)}[0-9]*)\.(?{g(3, match, pos)}[0-9]+)
+DIGIT (?{g(1, 'mantissa')}[0-9]+)\.?|(?{g(2, 'mantissa')}[0-9]*)\.(?{g(3, 'fraction')}[0-9]+)
%option noecs nometa-ecs noyywrap reject yymore
%%
[ ]
-(?{g(0, match, pos)}{DIGIT})(?{gc(4)}"") {
+(?{g(0)}{DIGIT})(?{gc(4)}"") {
global yylval
- #print('groups', groups)
+ print('groups', groups)
+ print('groups_by_name', groups_by_name)
+
+ # by Python parser:
#yylval = float(yytext)
- if groups[1] is not None:
- mantissa = groups[1]
- exponent = 0
- else:
- mantissa = groups[2] + groups[3]
- exponent = -len(groups[3])
- yylval = int(mantissa) * 10 ** exponent
+
+ # by group numbers:
+ #if groups[1] is not None:
+ # mantissa = groups[1]
+ # fraction = ''
+ #else:
+ # mantissa = groups[2]
+ # fraction = groups[3]
+ #yylval = int(mantissa + fraction) * 10 ** -len(fraction)
+
+ # by group names:
+ mantissa = groups_by_name['mantissa']
+ fraction = groups_by_name.get('fraction', '')
+ yylval = int(mantissa + fraction) * 10 ** -len(fraction)
+
return NUM
}
\n|. {