Add support for character terminal group rules

This commit is contained in:
Matthias Schiffer 2015-04-17 23:10:47 +02:00
parent 59db91599c
commit 9cbf364a46
4 changed files with 388 additions and 309 deletions

View file

@ -309,6 +309,7 @@ int lex_t::lex(parse_token_value_t *value) {
case '=':
case '(':
case ')':
case '.':
token = current();
next(true);
consume(false);

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@ typedef enum parse_token {
} parse_token_t;
typedef struct parse_token_value {
char c;
unsigned char c;
std::string *str;
} parse_token_value_t;

View file

@ -15,10 +15,6 @@ static inline void free_symbol(solar::symbol_t *v) {
delete v;
}
static inline void free_rule(solar::rule_t *v) {
delete v;
}
static inline void free_rhs(rhs_t *v) {
delete v;
}
@ -40,12 +36,9 @@ static inline void free_rhs(rhs_t *v) {
%type STRING {std::string *} str
%destructor STRING free_string
%type CHAR {char} c
%type CHAR {unsigned char} c
%type rule {solar::rule_t *}
%destructor rule free_rule
%type rhs {rhs_t *}
%destructor rhs free_rhs
@ -93,13 +86,17 @@ directive |= "%extra_arg" BLOCK(type) varname(name) {
grammar->extra_args.push_back(std::make_pair(*type, *name));
}
directive |= rule(rule) {
grammar->add_rule(*rule);
directive |= SYMBOL(lhs) "|=" rhs(rhs) action(action) {
grammar->add_rule({solar::item_t(*lhs, rhs->first), rhs->second, *action});
}
directive |= SYMBOL(lhs) "|=" '(' CHAR(c1) "..." CHAR(c2) ')' ';' {
vars_t vars;
vars.emplace_back();
rule |= SYMBOL(lhs) "|=" rhs(rhs) action(action)
[new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}]
for (unsigned int c = c1; c <= c2; c++)
grammar->add_rule({solar::item_t(*lhs, {solar::symbol_t::make_char(c)}), vars, std::string()});
}
rhs |= [new rhs_t()]