From: David Lamparter Date: Fri, 16 Dec 2016 21:34:35 +0000 (+0100) Subject: lib: parser: track matching FORK_TKN & JOIN_TKN X-Git-Tag: frr-3.0-branchpoint~64^2~7^2~9 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ab037159286a3241244a6b3e7d1033e3940aa944;p=matthieu%2Ffrr.git lib: parser: track matching FORK_TKN & JOIN_TKN This associates pairs of FORK and JOIN tokens, so the merge function can identify where a subgraph begins and ends. Signed-off-by: David Lamparter --- diff --git a/lib/command.h b/lib/command.h index dd940f0d57..b71142fdce 100644 --- a/lib/command.h +++ b/lib/command.h @@ -203,6 +203,8 @@ struct cmd_token char *desc; // token description long long min, max; // for ranges char *arg; // user input that matches this token + + struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK }; /* Structure of command element. */ diff --git a/lib/command_parse.y b/lib/command_parse.y index 478ba0537c..af6497d128 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -276,6 +276,8 @@ selector: '<' selector_seq_seq '>' $$ = malloc (sizeof (struct subgraph)); $$->start = new_token_node (ctx, FORK_TKN, NULL, NULL); $$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL); + ((struct cmd_token *)$$->start->data)->forkjoin = $$->end; + ((struct cmd_token *)$$->end->data)->forkjoin = $$->start; for (unsigned int i = 0; i < vector_active ($2->start->to); i++) { struct graph_node *sn = vector_slot ($2->start->to, i), @@ -331,6 +333,8 @@ selector: '{' selector_seq_seq '}' $$ = malloc (sizeof (struct subgraph)); $$->start = new_token_node (ctx, FORK_TKN, NULL, NULL); $$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL); + ((struct cmd_token *)$$->start->data)->forkjoin = $$->end; + ((struct cmd_token *)$$->end->data)->forkjoin = $$->start; graph_add_edge ($$->start, $$->end); for (unsigned int i = 0; i < vector_active ($2->start->to); i++) { @@ -379,6 +383,8 @@ option: '[' option_token_seq ']' $$ = malloc (sizeof (struct subgraph)); $$->start = new_token_node (ctx, FORK_TKN, NULL, NULL); $$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL); + ((struct cmd_token *)$$->start->data)->forkjoin = $$->end; + ((struct cmd_token *)$$->end->data)->forkjoin = $$->start; // add a path through the sequence to the end graph_add_edge ($$->start, $2->start); graph_add_edge ($2->end, $$->end);