aboutsummaryrefslogtreecommitdiffstats
path: root/libparser-generate.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-01-05 13:50:38 +0100
committerMattias Andrée <m@maandree.se>2026-02-23 07:52:18 +0100
commit7dd4970daafdc1992e1dba486a1477a17cb4c53e (patch)
treee56e544ec55e68872397738e0e5064b000d31eba /libparser-generate.c
parentOptimise detection of rejection (diff)
downloadlibparser-7dd4970daafdc1992e1dba486a1477a17cb4c53e.tar.gz
libparser-7dd4970daafdc1992e1dba486a1477a17cb4c53e.tar.bz2
libparser-7dd4970daafdc1992e1dba486a1477a17cb4c53e.tar.xz
Add committed-operator
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'libparser-generate.c')
-rw-r--r--libparser-generate.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libparser-generate.c b/libparser-generate.c
index f72ed85..a8761f8 100644
--- a/libparser-generate.c
+++ b/libparser-generate.c
@@ -375,6 +375,7 @@ emit_and_free_sentence(struct node *node, size_t *indexp)
switch (node->token->s[0]) {
case '[': type = "OPTIONAL"; goto unary;
case '{': type = "REPEATED"; goto unary;
+ case '+': type = "COMMITTED"; goto unary;
case '!': type = "REJECTION"; unary:
emit_and_free_sentence(node->data, indexp);
printf("static union libparser_sentence sentence_%zu_%zu = {.unary = {"
@@ -501,6 +502,7 @@ order_sentences(struct node *node)
case '[':
case '{':
case '!':
+ case '+':
/* Everything else we immediately put into the queue,
* but for brackets and unary operators, we simply
* use recursion to order inner sentences */
@@ -699,10 +701,11 @@ again:
* closing statements; and we still expect
* the next token to be an operand */
goto push_stack;
- } else if (tokens[i]->s[0] == '!') {
- /* Likewise for rejections (it is added to
- * the stack but it is an unary operator
- * so no matching symbol will be expected) */
+ } else if (tokens[i]->s[0] == '!' || tokens[i]->s[0] == '+') {
+ /* Likewise for rejections and commitments
+ * (it is added to the stack but they are
+ * unary operators so no matching symbol
+ * will be expected) */
goto push_stack;
} else if (tokens[i]->s[0] == '<') {
/* Likewise for value ranges, but we expect
@@ -741,8 +744,8 @@ again:
case EXPECT_OPERATOR:
/* When we get an binary operator, or the end
* of a sentence, we have to pop out all unary
- * operators (rejects) from the stack */
- while (stack->token->s[0] == '!') {
+ * operators from the stack */
+ while (stack->token->s[0] == '!' || stack->token->s[0] == '+') {
*stack->parent->head = stack;
stack->parent->head = &stack->next;
stack = stack->parent;