bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quoting of strings in non-C languages


From: Tim Landscheidt
Subject: Quoting of strings in non-C languages
Date: Thu, 03 Nov 2011 21:44:30 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

I wrote:

> [...]
> 2. The $yytname_'s definition reads
>    (b4_typed_parser_table_define):

>    |   private $yytname_ = array(
>    |   "$end", "error", "$undefined", "NUM", "'-'", "'+'", "'*'", "'/'", 
> "'^'",
>    |   "'\\n'", "'('", "')'", "$accept", "input", "line", "exp", null
>    |     );

>    The "$id"s have to be escaped either as "\$id" or "'$id'"
>    (probably also an issue for Perl). In the current form,
>    this is a syntax error for PHP.
> [...]

After first working around that in m4, I patched
src/output.c:

| diff --git a/src/output.c b/src/output.c
| index 44184b3..80cf046 100644
| --- a/src/output.c
| +++ b/src/output.c
| @@ -161,6 +161,8 @@ prepare_symbols (void)
|      struct quoting_options *qo = clone_quoting_options (0);
|      set_quoting_style (qo, c_quoting_style);
|      set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
| +    if (!strcmp (language->language, "php"))
| +      set_char_quoting (qo, '$', 1);
|      for (i = 0; i < nsyms; i++)
|        {
|          char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);

This works, but is wrong, though.  For example, in theory a
token name containing a C trigraph (I had forgotten that
they even existed :-)) ends up as '"a?""?>b"'.  This is not
only invalid in PHP, but also in Java.

  Rather than trying to solve this in Bison, I think the
right way would be to enhance Gnulib's quotearg.c to support
(at least) Java and PHP and then add fields to
valid_languages for the quoting style and flags.

  Comments?

Tim




reply via email to

[Prev in Thread] Current Thread [Next in Thread]