value type: accept "->" in type tags

Provide a means to dereference pointers when defining tags.  One
example could be:

  %code requires
  {
    typedef struct ListElementType
    {
      union value
      {
        int intVal;
        float floatVal;
        char* charptrVal;
      } value;

      struct ListElementType* next;
    } ListElementType;
  }

  %union
  {
    ListElementType* list;
  }

  %token <list->value.charptrVal> STRING
  %token <list->value.intVal> INTEGER
  %token <list->value.floatVal> REAL
  %type <list> ElementList LiteralType

* src/scan-code.l, src/scan-gram.l: Accept "->" in tags.
* tests/types.at: Add more test cases to cover this case.
This commit is contained in:
Akim Demaille
2013-02-21 15:58:05 +01:00
parent e52ddf820b
commit cb8d8bb9b6
3 changed files with 37 additions and 5 deletions

View File

@@ -78,8 +78,9 @@ static bool untyped_var_seen;
/* POSIX says that a tag must be both an id and a C union member, but
historically almost any character is allowed in a tag. We disallow
NUL and newline, as this simplifies our implementation. */
tag [^\0\n>]+
NUL and newline, as this simplifies our implementation. We allow
"->" as a means to dereference a pointer. */
tag ([^\0\n>]|->)+
/* Zero or more instances of backslash-newline. Following GCC, allow
white space between the backslash and the newline. */
@@ -595,7 +596,8 @@ fetch_type_name (char *cp, char const **type_name,
if (*cp == '<')
{
*type_name = ++cp;
while (*cp != '>')
/* Series of non-'>' or "->". */
while (*cp != '>' || cp[-1] == '-')
++cp;
/* The '>' symbol will be later replaced by '\0'. Original