mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
grammar.py: Don't create productions for special sequences
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
4fee6ac06e
commit
fee94deb48
1 changed files with 18 additions and 3 deletions
|
|
@ -177,6 +177,9 @@ def format_ebnf_rule(grammar, rule):
|
||||||
def format_yacc_rule(rule):
|
def format_yacc_rule(rule):
|
||||||
r = ''
|
r = ''
|
||||||
for c in rule:
|
for c in rule:
|
||||||
|
if c.tp != t_target_lang:
|
||||||
|
slog(DEBUG, "ignoring non-target-language token", c.token, "in rule")
|
||||||
|
continue
|
||||||
r += tok2sym(c.token) + ' '
|
r += tok2sym(c.token) + ' '
|
||||||
return r[:-1]
|
return r[:-1]
|
||||||
|
|
||||||
|
|
@ -516,6 +519,7 @@ def grammar_parse_ebnf_tokens(tokens):
|
||||||
grammar_add_symbol(grammar, s, None)
|
grammar_add_symbol(grammar, s, None)
|
||||||
grammar[s].set_type(p_terminal)
|
grammar[s].set_type(p_terminal)
|
||||||
for s in specials:
|
for s in specials:
|
||||||
|
slog(INFO, "found special sequence symbol", s)
|
||||||
grammar_add_symbol(grammar, s, None)
|
grammar_add_symbol(grammar, s, None)
|
||||||
grammar[s].set_type(p_special)
|
grammar[s].set_type(p_special)
|
||||||
|
|
||||||
|
|
@ -1123,14 +1127,20 @@ def create_yacc(grammar):
|
||||||
out += '\n'
|
out += '\n'
|
||||||
for t, p in grammar.iteritems():
|
for t, p in grammar.iteritems():
|
||||||
if p.tp == p_terminal:
|
if p.tp == p_terminal:
|
||||||
#out += '%token <String> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
out += '%token <' + p.sym + '> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
||||||
|
|
||||||
|
# special tokens
|
||||||
|
out += '\n'
|
||||||
|
for t, p in grammar.iteritems():
|
||||||
|
if p.tp == p_special:
|
||||||
|
if p.token == '?': # TODO: why is this among the symbols anyway?
|
||||||
|
continue
|
||||||
out += '%token <' + p.sym + '> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
out += '%token <' + p.sym + '> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
||||||
|
|
||||||
# regex tokens
|
# regex tokens
|
||||||
out += '\n'
|
out += '\n'
|
||||||
for t, p in grammar.iteritems():
|
for t, p in grammar.iteritems():
|
||||||
if p.tp == p_literal:
|
if p.tp == p_literal:
|
||||||
#out += '%token <String> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
|
||||||
out += '%token <' + p.sym + '> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
out += '%token <' + p.sym + '> ' + p.sym + (20 - len(p.sym)) * ' ' + '/* ' + t + ' */' +'\n'
|
||||||
|
|
||||||
# types
|
# types
|
||||||
|
|
@ -1149,10 +1159,15 @@ def create_yacc(grammar):
|
||||||
# productions
|
# productions
|
||||||
out += '\n%%\n\n'
|
out += '\n%%\n\n'
|
||||||
for t, p in grammar.iteritems():
|
for t, p in grammar.iteritems():
|
||||||
|
|
||||||
if not len(p.rules):
|
if not len(p.rules):
|
||||||
continue
|
continue
|
||||||
if p.term is not None:
|
if p.tp == p_terminal:
|
||||||
continue
|
continue
|
||||||
|
if p.tp == p_special:
|
||||||
|
continue
|
||||||
|
slog(INFO, "creating production for symbol", p.str())
|
||||||
|
|
||||||
#if p.is_lexical_element is True:
|
#if p.is_lexical_element is True:
|
||||||
# continue
|
# continue
|
||||||
if len(p.rules) == 0:
|
if len(p.rules) == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue