]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: parser: move allowrepeat to cmd_token
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 16:19:37 +0000 (17:19 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 16 Dec 2016 19:42:01 +0000 (20:42 +0100)
struct graph_node isn't quite the right place to control matcher
behaviour.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command.h
lib/command_match.c
lib/command_parse.y
lib/graph.h

index ba6fd9b7b038cbc90f83ae95e87b509712d5e408..1e1698fc7d123908f65365a6e7bcddbd643a18b9 100644 (file)
@@ -196,6 +196,8 @@ struct cmd_token
 {
   enum cmd_token_type type;     // token type
   u_char attr;                  // token attributes
+  bool allowrepeat;             // matcher allowed to match token repetively?
+
   char *text;                   // token text
   char *desc;                   // token description
   long long min, max;           // for ranges
index b6897109afc1bd6cfc7af57d2db503d2197d6785..62905a4f7f8755fbb95b331cf160eee8adebfc34 100644 (file)
@@ -202,20 +202,20 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n,
 {
   assert (n < vector_active (vline));
 
+  // get the minimum match level that can count as a full match
+  struct cmd_token *token = start->data;
+  enum match_type minmatch = min_match_level (token->type);
+
   /* check history/stack of tokens
    * this disallows matching the same one more than once if there is a
    * circle in the graph (used for keyword arguments) */
   if (n == MAXDEPTH)
     return NULL;
-  if (!start->allowrepeat)
+  if (!token->allowrepeat)
     for (size_t s = 0; s < n; s++)
       if (stack[s] == start)
         return NULL;
 
-  // get the minimum match level that can count as a full match
-  struct cmd_token *token = start->data;
-  enum match_type minmatch = min_match_level (token->type);
-
   // get the current operating input token
   char *input_token = vector_slot (vline, n);
 
@@ -481,7 +481,8 @@ add_nexthops (struct list *list, struct graph_node *node,
     {
       child = vector_slot (node->to, i);
       size_t j;
-      if (!child->allowrepeat)
+      struct cmd_token *token = child->data;
+      if (!token->allowrepeat)
         {
           for (j = 0; j < stackpos; j++)
             if (child == stack[j])
@@ -489,7 +490,6 @@ add_nexthops (struct list *list, struct graph_node *node,
           if (j != stackpos)
             continue;
         }
-      struct cmd_token *token = child->data;
       switch (token->type)
         {
           case OPTION_TKN:
index 81aa8a04e77cb81cf48c229b071ecc83ef6cf93a..43062eb5da97781cab79d05715e39bf1c112975d 100644 (file)
@@ -183,7 +183,7 @@ start:
   if ((ctx->currnode = add_edge_dedup (ctx->currnode, $3)) != $3)
     graph_delete_node (ctx->graph, $3);
 
-  ctx->currnode->allowrepeat = 1;
+  ((struct cmd_token *)ctx->currnode->data)->allowrepeat = 1;
 
   // adding a node as a child of itself accepts any number
   // of the same token, which is what we want for variadics
index ee8e37c93255605b05ab85ae01c29957ed72f214..8d8aa3823ba5f90474b2732449eda127ce22c1bd 100644 (file)
@@ -36,7 +36,6 @@ struct graph_node
 {
   vector from;                  // nodes which have edges to this node
   vector to;                    // nodes which this node has edges to
-  bool allowrepeat;
 
   void *data;                   // node data
   void (*del) (void *data);     // deletion callback