Add support for character terminal group rules
This commit is contained in:
parent
59db91599c
commit
9cbf364a46
4 changed files with 388 additions and 309 deletions
|
@ -309,6 +309,7 @@ int lex_t::lex(parse_token_value_t *value) {
|
||||||
case '=':
|
case '=':
|
||||||
case '(':
|
case '(':
|
||||||
case ')':
|
case ')':
|
||||||
|
case '.':
|
||||||
token = current();
|
token = current();
|
||||||
next(true);
|
next(true);
|
||||||
consume(false);
|
consume(false);
|
||||||
|
|
673
src/parse.cpp
673
src/parse.cpp
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,7 @@ typedef enum parse_token {
|
||||||
} parse_token_t;
|
} parse_token_t;
|
||||||
|
|
||||||
typedef struct parse_token_value {
|
typedef struct parse_token_value {
|
||||||
char c;
|
unsigned char c;
|
||||||
std::string *str;
|
std::string *str;
|
||||||
} parse_token_value_t;
|
} parse_token_value_t;
|
||||||
|
|
||||||
|
|
21
src/parse.y
21
src/parse.y
|
@ -15,10 +15,6 @@ static inline void free_symbol(solar::symbol_t *v) {
|
||||||
delete v;
|
delete v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_rule(solar::rule_t *v) {
|
|
||||||
delete v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void free_rhs(rhs_t *v) {
|
static inline void free_rhs(rhs_t *v) {
|
||||||
delete v;
|
delete v;
|
||||||
}
|
}
|
||||||
|
@ -40,12 +36,9 @@ static inline void free_rhs(rhs_t *v) {
|
||||||
%type STRING {std::string *} str
|
%type STRING {std::string *} str
|
||||||
%destructor STRING free_string
|
%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 *}
|
%type rhs {rhs_t *}
|
||||||
%destructor rhs free_rhs
|
%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));
|
grammar->extra_args.push_back(std::make_pair(*type, *name));
|
||||||
}
|
}
|
||||||
|
|
||||||
directive |= rule(rule) {
|
directive |= SYMBOL(lhs) "|=" rhs(rhs) action(action) {
|
||||||
grammar->add_rule(*rule);
|
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)
|
for (unsigned int c = c1; c <= c2; c++)
|
||||||
[new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}]
|
grammar->add_rule({solar::item_t(*lhs, {solar::symbol_t::make_char(c)}), vars, std::string()});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
rhs |= [new rhs_t()]
|
rhs |= [new rhs_t()]
|
||||||
|
|
Reference in a new issue