Prepare @$ in %destructor, but currently don't bind it in the

skeleton, as %location use is not cleaned up yet.
* src/scan-gram.l (handle_dollar, handle_destructor_at)
(handle_action_at): New.
(handle_at, handle_action_dollar, handle_destructor_dollar): Take
a braced_code_t and a location as additional arguments.
(handle_destructor_dollar): Instead of requiring `b4_eval', just
unquote one when outputting `b4_dollar_dollar'.
Adjust callers.
* data/bison.simple (b4_eval): Remove.
(b4_symbol_destructor): Adjust.
* tests/input.at (Invalid @n): Adjust.
This commit is contained in:
Akim Demaille
2002-06-19 08:22:49 +00:00
parent c732d2c6dc
commit f25bfb75aa
5 changed files with 237 additions and 105 deletions

View File

@@ -76,13 +76,13 @@ scanner_last_string_free (void)
}
static int braces_level = 0;
static int percent_percent_count = 0;
static void handle_action_dollar PARAMS ((char *cp, location_t location));
static void handle_destructor_dollar PARAMS ((char *cp, location_t location));
static void handle_at PARAMS ((char *cp));
static void handle_dollar PARAMS ((braced_code_t code_kind,
char *cp, location_t location));
static void handle_at PARAMS ((braced_code_t code_kind,
char *cp, location_t location));
%}
%x SC_COMMENT
@@ -443,19 +443,10 @@ blanks [ \t\f]+
"{" YY_OBS_GROW; braces_level++;
"$"("<"[^>]+">")?(-?[0-9]+|"$") {
switch (current_braced_code)
{
case action_braced_code:
handle_action_dollar (yytext, *yylloc);
break;
case destructor_braced_code:
handle_destructor_dollar (yytext, *yylloc);
break;
}
}
"@"(-?[0-9]+|"$") { handle_at (yytext); }
"$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code,
yytext, *yylloc); }
"@"(-?[0-9]+|"$") { handle_at (current_braced_code,
yytext, *yylloc); }
[^$@\[\]/\'\"\{\}\n\r]+ YY_OBS_GROW;
{eols} YY_OBS_GROW; YY_LINES;
@@ -532,7 +523,7 @@ blanks [ \t\f]+
| Output to the STRING_OBSTACK a reference to this semantic value. |
`------------------------------------------------------------------*/
static void
static inline void
handle_action_dollar (char *cp, location_t location)
{
const char *type_name = NULL;
@@ -596,21 +587,17 @@ handle_action_dollar (char *cp, location_t location)
}
/*---------------------------------------------------------------.
| CP is pointing to $$ in a destructor. This should probably be |
| done once the grammar completely parsed, instead of during its |
| parsing, since that means %type must be specified before |
| %destructor. |
`---------------------------------------------------------------*/
/*---------------------------------------.
| CP is pointing to $$ in a destructor. |
`---------------------------------------*/
static void
static inline void
handle_destructor_dollar (char *cp, location_t location)
{
++cp;
if (*cp == '$')
{
/* FIXME: We should find something more robust. */
obstack_sgrow (&string_obstack, "b4_dollar_dollar");
obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
}
else
{
@@ -620,32 +607,55 @@ handle_destructor_dollar (char *cp, location_t location)
}
}
/*-------------------------------------------------------.
| CP is pointing to a location (i.e., a `@'). Output to |
| STRING_OBSTACK a reference to this location. |
`-------------------------------------------------------*/
/*-----------------------------------------------------------------.
| Dispatch onto handle_action_dollar, or handle_destructor_dollar, |
| depending upon CODE_KIND. |
`-----------------------------------------------------------------*/
static void
handle_at (char *cp)
handle_dollar (braced_code_t braced_code_kind,
char *text, location_t location)
{
switch (braced_code_kind)
{
case action_braced_code:
handle_action_dollar (text, location);
break;
case destructor_braced_code:
handle_destructor_dollar (text, location);
break;
}
}
/*------------------------------------------------------.
| TEXT is a location token (i.e., a `@...'). Output to |
| STRING_OBSTACK a reference to this location. |
`------------------------------------------------------*/
static inline void
handle_action_at (char *text, location_t location)
{
locations_flag = 1;
++cp;
++text;
if (*cp == '$')
if (*text == '$')
{
obstack_sgrow (&string_obstack, "]b4_lhs_location[");
}
else if (isdigit (*cp) || *cp == '-')
else if (isdigit (*text) || *text == '-')
{
/* RULE_LENGTH is the number of values in the current rule so
far, which says where to find `$0' with respect to the top of
the stack. It is not the same as the rule->length in the
case of mid rule actions. */
int rule_length = symbol_list_length (current_rule->next);
int n = strtol (cp, &cp, 10);
int n = strtol (text, &text, 10);
if (n > rule_length)
complain (_("invalid value: %s%d"), "@", n);
complain_at (location, _("invalid value: %s%d"), "@", n);
else
obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[",
rule_length, n);
@@ -653,11 +663,59 @@ handle_at (char *cp)
else
{
char buf[] = "@c";
buf[1] = *cp;
complain (_("%s is invalid"), quote (buf));
buf[1] = *text;
complain_at (location, _("%s is invalid"), quote (buf));
}
}
/*--------------------------------------------.
| TEXT is expexted tp be @$ in a destructor. |
`--------------------------------------------*/
static inline void
handle_destructor_at (char *text, location_t location)
{
++text;
if (*text == '$')
{
obstack_sgrow (&string_obstack, "]b4_at_dollar[");
}
else
{
char buf[] = "$c";
buf[1] = *text;
complain_at (location, _("%s is invalid"), quote (buf));
}
}
/*-------------------------------------------------------------------.
| Dispatch onto handle_action_at, or handle_destructor_at, depending |
| upon CODE_KIND. |
`-------------------------------------------------------------------*/
static void
handle_at (braced_code_t braced_code_kind,
char *text, location_t location)
{
switch (braced_code_kind)
{
case action_braced_code:
handle_action_at (text, location);
break;
case destructor_braced_code:
handle_destructor_at (text, location);
break;
}
}
/*-------------------------.
| Initialize the scanner. |
`-------------------------*/
void
scanner_initialize (void)
{
@@ -665,6 +723,10 @@ scanner_initialize (void)
}
/*-----------------------------------------------.
| Free all the memory allocated to the scanner. |
`-----------------------------------------------*/
void
scanner_free (void)
{