summaryrefslogtreecommitdiffstats
path: root/src/lex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lex.cpp')
-rw-r--r--src/lex.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/lex.cpp b/src/lex.cpp
index 851ac87..3adfb5b 100644
--- a/src/lex.cpp
+++ b/src/lex.cpp
@@ -42,6 +42,7 @@ struct keyword_t {
/* the keyword list must be sorted */
static const keyword_t keywords[] = {
+ {"%type", TOK_TYPE},
};
static int compare_keywords(const void *v1, const void *v2) {
@@ -330,24 +331,21 @@ int lex_t::lex_block(parser_value_t *value) {
return TOK_BLOCK;
}
-int lex_t::lex_symbol(parser_value_t *value, bool terminal) {
+int lex_t::lex_symbol(parser_value_t *value) {
if (needspace)
return syntax_error(value);
- while (next(false)) {
- char cur = current();
+ bool uc = true;
+ bool lc = true;
- switch (cur) {
+ do {
+ switch (current()) {
case 'A' ... 'Z':
- if (!terminal)
- break;
-
+ lc = false;
continue;
case 'a' ... 'z':
- if (terminal)
- break;
-
+ uc = false;
continue;
case '0' ... '9':
@@ -356,10 +354,16 @@ int lex_t::lex_symbol(parser_value_t *value, bool terminal) {
}
break;
- }
+ } while (next(false));
value->str = get_token();
- return terminal ? TOK_TERM : TOK_NONTERM;
+
+ if (uc)
+ return TOK_SYMBOL_UC;
+ else if (lc)
+ return TOK_SYMBOL_LC;
+ else
+ return TOK_SYMBOL;
}
int lex_t::lex(parser_value_t *value) {
@@ -382,6 +386,8 @@ int lex_t::lex(parser_value_t *value) {
case ':':
case '|':
case '=':
+ case '(':
+ case ')':
token = current();
next(true);
consume(false);
@@ -436,10 +442,11 @@ int lex_t::lex(parser_value_t *value) {
return lex_number(value);
case 'a' ... 'z':
- return lex_symbol(value, false);
-
case 'A' ... 'Z':
- return lex_symbol(value, true);
+ return lex_symbol(value);
+
+ case '%':
+ return lex_keyword(value);
default:
return syntax_error(value);