{
return &lexer->tokstr;
}
+
+/* If the lexer is positioned at the (pseudo)identifier S, which
+ may contain a hyphen ('-'), skips it and returns true. Each
+ half of the identifier may be abbreviated to its first three
+ letters.
+ Otherwise, returns false. */
+bool
+lex_match_hyphenated_word (struct lexer *lexer, const char *s)
+{
+ const char *hyphen = strchr (s, '-');
+ if (hyphen == NULL)
+ return lex_match_id (lexer, s);
+ else if (lexer->token != T_ID
+ || !lex_id_match (ss_buffer (s, hyphen - s), ss_cstr (lexer->tokid))
+ || lex_look_ahead (lexer) != '-')
+ return false;
+ else
+ {
+ lex_get (lexer);
+ lex_force_match (lexer, '-');
+ lex_force_match_id (lexer, hyphen + 1);
+ return true;
+ }
+}
+
bool lex_match_id (struct lexer *, const char *);
bool lex_match_id_n (struct lexer *, const char *, size_t n);
bool lex_match_int (struct lexer *, int);
+bool lex_match_hyphenated_word (struct lexer *lexer, const char *s);
+
/* Forcible matching functions. */
bool lex_force_match (struct lexer *, int);
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2008 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
#endif /* DUMP_TOKENS */
+
+const char hyphen_proxy = '_';
+
+static void
+id_cpy (char **cp)
+{
+ char *dest = tokstr;
+ char *src = *cp;
+
+ while (*src == '_' || *src == '-' || isalnum ((unsigned char) *src))
+ {
+ *dest++ = *src == '-' ? hyphen_proxy :toupper ((unsigned char) (*src));
+ src++;
+ }
+
+ *cp = src;
+ *dest++ = '\0';
+}
+
+static const char *
+unmunge (const char *s)
+{
+ char *dest = xmalloc (strlen (s));
+ char *d = dest;
+
+ while (*s)
+ {
+ if (*s == hyphen_proxy)
+ *d = '-';
+ else
+ *d = *s;
+ s++;
+ d++;
+ }
+
+ return dest;
+}
+
/* Reads a token from the input file. */
static int
lex_get (void)
{
char *dest = tokstr;
token = T_ID;
- while (*cp == '_' || isalnum ((unsigned char) *cp))
- *dest++ = toupper ((unsigned char) (*cp++));
- *dest++ = '\0';
+
+ id_cpy (&cp);
}
else
token = *cp++;
else if (isdigit ((unsigned char) t[0]))
sprintf (s, "lex_match_int (lexer, %s)", t);
else
- sprintf (s, "lex_match_id (lexer, \"%s\")", t);
+ {
+ char *c = unmunge (t);
+ sprintf (s, "lex_match_hyphenated_word (lexer, \"%s\")", c);
+ free (c);
+ }
return s;
}