diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-19 11:29:50 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-19 11:29:50 +0200 |
commit | 16b3146a1ed4497205a378472b35c40eb34c0d40 (patch) | |
tree | 1607ca63497008ce51f4333dcea9b729483f23f8 /libparser-generate.c | |
parent | Compile with -O2 and -s (diff) | |
download | libparser-16b3146a1ed4497205a378472b35c40eb34c0d40.tar.gz libparser-16b3146a1ed4497205a378472b35c40eb34c0d40.tar.bz2 libparser-16b3146a1ed4497205a378472b35c40eb34c0d40.tar.xz |
Add rejection + fix documentation of comment syntax (can contain string)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libparser-generate.c')
-rw-r--r-- | libparser-generate.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libparser-generate.c b/libparser-generate.c index 72cd294..9f82a2e 100644 --- a/libparser-generate.c +++ b/libparser-generate.c @@ -361,12 +361,13 @@ emit_and_free_sentence(struct node *node, size_t *indexp) free(node); } - if (node->token->s[0] == '[' || node->token->s[0] == '{') { + if (node->token->s[0] == '[' || node->token->s[0] == '{' || node->token->s[0] == '!') { emit_and_free_sentence(node->data, indexp); printf("static union libparser_sentence sentence_%zu_%zu = {.unary = {" ".type = LIBPARSER_SENTENCE_TYPE_%s, .sentence = &sentence_%zu_%zu" "}};\n", - nrule_names, index, node->token->s[0] == '[' ? "OPTIONAL" : "REPEATED", nrule_names, index + 1); + nrule_names, index, node->token->s[0] == '[' ? "OPTIONAL" : + node->token->s[0] == '{' ? "REPEATED" : "REJECTION", nrule_names, index + 1); } else if (node->token->s[0] == '<') { low = node->data; high = node->data->next; @@ -551,11 +552,16 @@ main(int argc, char *argv[]) again: for (; tokens[i]; i++) { if (tokens[i + 1] && tokens[i]->s[0] == '(' && tokens[i + 1]->s[0] == '*') { + free(tokens[i]); + free(tokens[i + 1]); for (i += 2; tokens[i] && tokens[i + 1]; i++) { if (tokens[i]->s[0] == '*' && tokens[i + 1]->s[0] == ')') { + free(tokens[i]); + free(tokens[i + 1]); i += 2; goto again; } + free(tokens[i]); } eprintf("%s: premature end of file\n", argv0); } @@ -612,6 +618,8 @@ again: stack->head = &stack->data; } else if (tokens[i]->s[0] == '-') { goto add; + } else if (tokens[i]->s[0] == '!') { + goto push_stack; } else { stray: eprintf("%s: stray '%c' on line %zu at column %zu (character %zu)\n", @@ -625,6 +633,11 @@ again: break; case EXPECT_OPERATOR: + while (stack->token->s[0] == '!') { + *stack->parent->head = stack; + stack->parent->head = &stack->next; + stack = stack->parent; + } if (tokens[i]->s[0] == '|' || tokens[i]->s[0] == ',') { state = EXPECT_OPERAND; add_singleton: |