X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/1c7b7e1d87f698efb2e3daad0f6484829563d96f..e9813cd4f8f86fd822f2994d60cf4f9a9afe0221:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index a8a1335b..5cefbce1 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -82,7 +82,6 @@ static int current_prec = 0; %locations %pure-parser %error-verbose -%defines %name-prefix="gram_" %expect 0 @@ -184,12 +183,12 @@ static int current_prec = 0; /* braceless is not to be used for rule or symbol actions, as it calls code_props_plain_init. */ -%type STRING "%{...%}" EPILOGUE braceless content content.opt +%type STRING "%{...%}" EPILOGUE braceless content.opt %type "{...}" %printer { fputs (quotearg_style (c_quoting_style, $$), stderr); } STRING %printer { fprintf (stderr, "{\n%s\n}", $$); } - braceless content content.opt "{...}" "%{...%}" EPILOGUE + braceless content.opt "{...}" "%{...%}" EPILOGUE %type TYPE ID ID_COLON %printer { fprintf (stderr, "<%s>", $$); } TYPE @@ -233,7 +232,20 @@ prologue_declaration: code_scanner_last_string_free (); } | "%debug" { debug_flag = true; } -| "%define" STRING content.opt { muscle_insert ($2, $3); } +| "%define" STRING content.opt + { + /* FIXME: Special characters in $2 may break %define. + For example: `['. */ + char const name_prefix[] = "percent_define_"; + char *name = xmalloc (sizeof name_prefix + strlen ($2)); + strcpy (name, name_prefix); + strcpy (name + sizeof name_prefix - 1, $2); + if (muscle_find_const (name)) + warn_at (@2, _("%s `%s' redefined"), "%define variable", $2); + MUSCLE_INSERT_STRING (uniqstr_new (name), $3); + free (name); + muscle_grow_user_name_list ("user_percent_define_variables", $2, @2); + } | "%defines" { defines_flag = true; } | "%defines" STRING { @@ -316,6 +328,8 @@ grammar_declaration: } | "%code" STRING braceless { + /* FIXME: Special characters in $2 may break %code. + For example: `['. */ char const name_prefix[] = "percent_code_"; char *name = xmalloc (sizeof name_prefix + strlen ($2)); strcpy (name, name_prefix); @@ -323,9 +337,7 @@ grammar_declaration: muscle_code_grow (uniqstr_new (name), $3, @3); free (name); code_scanner_last_string_free (); - muscle_grow ("used_percent_code_qualifiers", "[[", ","); - muscle_grow ("used_percent_code_qualifiers", $2, ""); - muscle_grow ("used_percent_code_qualifiers", "]]", ""); + muscle_grow_user_name_list ("user_percent_code_qualifiers", $2, @2); } ; @@ -523,14 +535,9 @@ rhs: ; -/*-----------* - | content. | - *-----------*/ - -content: - STRING -| braceless -; +/*---------------* + | content.opt. | + *--------------*/ /* Some content or "1" by default. */ content.opt: @@ -539,10 +546,14 @@ content.opt: static char one[] = "1"; $$ = one; } -| content +| STRING ; +/*-------------* + | braceless. | + *-------------*/ + braceless: "{...}" {