Don't apply the default %destructor or %printer to the error token,

$undefined, or $accept.  This change fits the general rule that the
default %destructor and %printer are only for user-declared symbols,
and it solves several difficulties that are described in the new test
cases listed below.
* src/symtab.c (symbol_destructor_get, symbol_printer_get): Implement.
* tests/actions.at (Default %printer and %destructor are not for error
or $undefined, Default %printer and %destructor are not for $accept):
New test cases.
This commit is contained in:
Joel E. Denny
2006-08-21 21:53:18 +00:00
parent 4d7370cb4f
commit 9350499cfc
3 changed files with 203 additions and 12 deletions

View File

@@ -163,12 +163,14 @@ symbol_destructor_set (symbol *sym, const char *destructor, location loc)
const char *
symbol_destructor_get (symbol *sym)
{
/* Token 0 cannot have a %destructor unless the user renames it. */
if (UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
return NULL;
/* Per-symbol %destructor. */
if (sym->destructor != NULL)
return sym->destructor;
/* Apply the default %destructor only to user-defined symbols. */
if (sym == errtoken || sym == undeftoken || sym == accept
|| UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
return NULL;
return default_destructor;
}
@@ -207,12 +209,14 @@ symbol_printer_set (symbol *sym, const char *printer, location loc)
const char *
symbol_printer_get (symbol *sym)
{
/* Token 0 cannot have a %printer unless the user renames it. */
if (UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
return NULL;
/* Per-symbol %printer. */
if (sym->printer != NULL)
return sym->printer;
/* Apply the default %printer only to user-defined symbols. */
if (sym == errtoken || sym == undeftoken || sym == accept
|| UNIQSTR_EQ (sym->tag, uniqstr_new ("$end")))
return NULL;
return default_printer;
}