mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
grammar.py: Add support for --start-symbols
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
3cba245b77
commit
c7ecfbff3a
1 changed files with 10 additions and 2 deletions
|
|
@ -1117,6 +1117,8 @@ def grammar_create_y(grammar, opts):
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <slog.h>
|
||||
|
||||
""")
|
||||
|
||||
for f in opts['includes']:
|
||||
|
|
@ -1210,6 +1212,9 @@ def grammar_create_y(grammar, opts):
|
|||
%param { struct context *context } { void *scanner }
|
||||
""")
|
||||
|
||||
if opts['start'] is not None:
|
||||
out += "%start " + opts['start']
|
||||
|
||||
# productions
|
||||
out += '\n%%\n\n'
|
||||
for t, p in grammar.iteritems():
|
||||
|
|
@ -1240,6 +1245,7 @@ def grammar_create_y(grammar, opts):
|
|||
else:
|
||||
out += indent + "| " + format_yacc_rule(rule) + "\n"
|
||||
out += indent + "{" + "\n"
|
||||
out += indent + "\t" + 'slog(PRI_NOTICE, "stack size = %d, %d / %d, %d", yyssp - &yyssa[0], yyss - &yyssa[0], yyvsp - &yyvsa[0], yyvs - &yyvsa[0]);\n'
|
||||
out += indent + "\t" + "$$ = new " + opts['namespace'] + '::' + t + ";\n"
|
||||
out += indent + "\t" + "$$->type = " + opts['namespace'] + '::' + t + "::t_" + str(n_rule) + ";\n"
|
||||
tokens = []
|
||||
|
|
@ -1423,7 +1429,7 @@ def grammar_create_l(grammar, opts):
|
|||
|
||||
out += textwrap.dedent("""\
|
||||
. {
|
||||
slog(PRI_NOTICE, "returning character %c", yytext[0]);
|
||||
slog(PRI_NOTICE, "returning character '%c'", yytext[0]);
|
||||
return yytext[0];
|
||||
}
|
||||
|
||||
|
|
@ -1644,6 +1650,7 @@ class GrammarCmd(jwutils.Cmd):
|
|||
p.add_argument('-t', '--trim-symbols', help='trim grammar tree at symbol', nargs='?', default='')
|
||||
p.add_argument('-r', '--irrelevant-symbols', help='exclude symbol from output payload', nargs='?', default='')
|
||||
p.add_argument('-c', '--cut-symbols', help='cut grammar tree at symbol', nargs='?', default='')
|
||||
p.add_argument('-s', '--start-symbols', help='use start-symbols', nargs='?', default=None)
|
||||
p.add_argument('-f', '--config-file', help='config file', nargs='?', default=None)
|
||||
return p
|
||||
|
||||
|
|
@ -1737,7 +1744,8 @@ class CmdCreate(DerivedGrammarCmd):
|
|||
"namespace" : args.namespace,
|
||||
"includes" : includes,
|
||||
"mip" : mip,
|
||||
"config" : config
|
||||
"config" : config,
|
||||
"start" : args.start_symbols
|
||||
}
|
||||
|
||||
cmd = getattr(sys.modules[__name__], 'grammar_create_' + ext)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue