forked from Mirror/frr
lib: parser: simplify OPTION_TKN & SELECTOR_TKN
These are functionally identical as "fork" tokens. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
61617d382e
commit
0bf5b1cbe3
|
@ -1268,7 +1268,7 @@ permute (struct graph_node *start, struct vty *vty)
|
||||||
for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
|
for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
|
||||||
{
|
{
|
||||||
struct cmd_token *tt = gnn->data;
|
struct cmd_token *tt = gnn->data;
|
||||||
if (tt->type < SELECTOR_TKN)
|
if (tt->type < SPECIAL_TKN)
|
||||||
vty_out (vty, " %s", tt->text);
|
vty_out (vty, " %s", tt->text);
|
||||||
}
|
}
|
||||||
if (gn == start)
|
if (gn == start)
|
||||||
|
|
|
@ -176,11 +176,12 @@ enum cmd_token_type
|
||||||
IPV6_PREFIX_TKN, // IPV6 network prefixes
|
IPV6_PREFIX_TKN, // IPV6 network prefixes
|
||||||
|
|
||||||
/* plumbing types */
|
/* plumbing types */
|
||||||
SELECTOR_TKN, // marks beginning of selector
|
FORK_TKN, // marks subgraph beginning
|
||||||
OPTION_TKN, // marks beginning of option
|
JOIN_TKN, // marks subgraph end
|
||||||
NUL_TKN, // dummy token
|
|
||||||
START_TKN, // first token in line
|
START_TKN, // first token in line
|
||||||
END_TKN, // last token in line
|
END_TKN, // last token in line
|
||||||
|
|
||||||
|
SPECIAL_TKN = FORK_TKN,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Command attributes */
|
/* Command attributes */
|
||||||
|
|
|
@ -459,7 +459,7 @@ command_complete (struct graph *graph,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds all children that are reachable by one parser hop to the given list.
|
* Adds all children that are reachable by one parser hop to the given list.
|
||||||
* NUL_TKN, SELECTOR_TKN, and OPTION_TKN nodes are treated as transparent.
|
* special tokens except END_TKN are treated as transparent.
|
||||||
*
|
*
|
||||||
* @param[in] list to add the nexthops to
|
* @param[in] list to add the nexthops to
|
||||||
* @param[in] node to start calculating nexthops from
|
* @param[in] node to start calculating nexthops from
|
||||||
|
@ -490,26 +490,24 @@ add_nexthops (struct list *list, struct graph_node *node,
|
||||||
if (j != stackpos)
|
if (j != stackpos)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (token->type)
|
if (token->type >= SPECIAL_TKN && token->type != END_TKN)
|
||||||
{
|
{
|
||||||
case OPTION_TKN:
|
added += add_nexthops (list, child, stack, stackpos);
|
||||||
case SELECTOR_TKN:
|
}
|
||||||
case NUL_TKN:
|
else
|
||||||
added += add_nexthops (list, child, stack, stackpos);
|
{
|
||||||
break;
|
if (stack)
|
||||||
default:
|
{
|
||||||
if (stack)
|
nextstack = XMALLOC (MTYPE_CMD_MATCHSTACK,
|
||||||
{
|
(stackpos + 1) * sizeof(struct graph_node *));
|
||||||
nextstack = XMALLOC (MTYPE_CMD_MATCHSTACK,
|
nextstack[0] = child;
|
||||||
(stackpos + 1) * sizeof(struct graph_node *));
|
memcpy(nextstack + 1, stack, stackpos * sizeof(struct graph_node *));
|
||||||
nextstack[0] = child;
|
|
||||||
memcpy(nextstack + 1, stack, stackpos * sizeof(struct graph_node *));
|
|
||||||
|
|
||||||
listnode_add (list, nextstack);
|
listnode_add (list, nextstack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
listnode_add (list, child);
|
listnode_add (list, child);
|
||||||
added++;
|
added++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -274,8 +274,8 @@ placeholder_token:
|
||||||
selector: '<' selector_seq_seq '>'
|
selector: '<' selector_seq_seq '>'
|
||||||
{
|
{
|
||||||
$$ = malloc (sizeof (struct subgraph));
|
$$ = malloc (sizeof (struct subgraph));
|
||||||
$$->start = new_token_node (ctx, SELECTOR_TKN, NULL, NULL);
|
$$->start = new_token_node (ctx, FORK_TKN, NULL, NULL);
|
||||||
$$->end = new_token_node (ctx, NUL_TKN, NULL, NULL);
|
$$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL);
|
||||||
for (unsigned int i = 0; i < vector_active ($2->start->to); i++)
|
for (unsigned int i = 0; i < vector_active ($2->start->to); i++)
|
||||||
{
|
{
|
||||||
struct graph_node *sn = vector_slot ($2->start->to, i),
|
struct graph_node *sn = vector_slot ($2->start->to, i),
|
||||||
|
@ -329,8 +329,8 @@ selector_seq_seq:
|
||||||
selector: '{' selector_seq_seq '}'
|
selector: '{' selector_seq_seq '}'
|
||||||
{
|
{
|
||||||
$$ = malloc (sizeof (struct subgraph));
|
$$ = malloc (sizeof (struct subgraph));
|
||||||
$$->start = new_token_node (ctx, SELECTOR_TKN, NULL, NULL);
|
$$->start = new_token_node (ctx, FORK_TKN, NULL, NULL);
|
||||||
$$->end = new_token_node (ctx, NUL_TKN, NULL, NULL);
|
$$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL);
|
||||||
graph_add_edge ($$->start, $$->end);
|
graph_add_edge ($$->start, $$->end);
|
||||||
for (unsigned int i = 0; i < vector_active ($2->start->to); i++)
|
for (unsigned int i = 0; i < vector_active ($2->start->to); i++)
|
||||||
{
|
{
|
||||||
|
@ -377,8 +377,8 @@ option: '[' option_token_seq ']'
|
||||||
{
|
{
|
||||||
// make a new option
|
// make a new option
|
||||||
$$ = malloc (sizeof (struct subgraph));
|
$$ = malloc (sizeof (struct subgraph));
|
||||||
$$->start = new_token_node (ctx, OPTION_TKN, NULL, NULL);
|
$$->start = new_token_node (ctx, FORK_TKN, NULL, NULL);
|
||||||
$$->end = new_token_node (ctx, NUL_TKN, NULL, NULL);
|
$$->end = new_token_node (ctx, JOIN_TKN, NULL, NULL);
|
||||||
// add a path through the sequence to the end
|
// add a path through the sequence to the end
|
||||||
graph_add_edge ($$->start, $2->start);
|
graph_add_edge ($$->start, $2->start);
|
||||||
graph_add_edge ($2->end, $$->end);
|
graph_add_edge ($2->end, $$->end);
|
||||||
|
@ -575,8 +575,7 @@ cmp_token (struct cmd_token *first, struct cmd_token *second)
|
||||||
* cases; ultimately this forks the graph, but the matcher can handle
|
* cases; ultimately this forks the graph, but the matcher can handle
|
||||||
* this regardless
|
* this regardless
|
||||||
*/
|
*/
|
||||||
case SELECTOR_TKN:
|
case FORK_TKN:
|
||||||
case OPTION_TKN:
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* end nodes are always considered equal, since each node may only
|
/* end nodes are always considered equal, since each node may only
|
||||||
|
@ -584,7 +583,7 @@ cmp_token (struct cmd_token *first, struct cmd_token *second)
|
||||||
*/
|
*/
|
||||||
case START_TKN:
|
case START_TKN:
|
||||||
case END_TKN:
|
case END_TKN:
|
||||||
case NUL_TKN:
|
case JOIN_TKN:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,9 +275,8 @@ struct message tokennames[] = {
|
||||||
item(IPV6_PREFIX_TKN), // IPV6 network prefixes
|
item(IPV6_PREFIX_TKN), // IPV6 network prefixes
|
||||||
|
|
||||||
/* plumbing types */
|
/* plumbing types */
|
||||||
item(SELECTOR_TKN), // marks beginning of selector
|
item(FORK_TKN),
|
||||||
item(OPTION_TKN), // marks beginning of option
|
item(JOIN_TKN),
|
||||||
item(NUL_TKN), // dummy token
|
|
||||||
item(START_TKN), // first token in line
|
item(START_TKN), // first token in line
|
||||||
item(END_TKN), // last token in line
|
item(END_TKN), // last token in line
|
||||||
{ 0, NULL }
|
{ 0, NULL }
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#ifndef _GRAMMAR_SANDBOX_H
|
|
||||||
#define _GRAMMAR_SANDBOX_H
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Houses functionality for testing shim as well as code that should go into
|
|
||||||
* command.h and command.c during integration.
|
|
||||||
*/
|
|
||||||
#include "memory.h"
|
|
||||||
|
|
||||||
#define CMD_CR_TEXT "<cr>"
|
|
||||||
|
|
||||||
void
|
|
||||||
grammar_sandbox_init (void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Types for tokens.
|
|
||||||
*
|
|
||||||
* The type determines what kind of data the token can match (in the
|
|
||||||
* matching use case) or hold (in the argv use case).
|
|
||||||
*/
|
|
||||||
enum cmd_token_type_t
|
|
||||||
{
|
|
||||||
WORD_TKN, // words
|
|
||||||
NUMBER_TKN, // integral numbers
|
|
||||||
VARIABLE_TKN, // almost anything
|
|
||||||
RANGE_TKN, // integer range
|
|
||||||
IPV4_TKN, // IPV4 addresses
|
|
||||||
IPV4_PREFIX_TKN, // IPV4 network prefixes
|
|
||||||
IPV6_TKN, // IPV6 prefixes
|
|
||||||
IPV6_PREFIX_TKN, // IPV6 network prefixes
|
|
||||||
|
|
||||||
/* plumbing types */
|
|
||||||
SELECTOR_TKN, // marks beginning of selector
|
|
||||||
OPTION_TKN, // marks beginning of option
|
|
||||||
NUL_TKN, // dummy token
|
|
||||||
START_TKN, // first token in line
|
|
||||||
END_TKN, // last token in line
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Token struct.
|
|
||||||
*/
|
|
||||||
struct cmd_token_t
|
|
||||||
{
|
|
||||||
enum cmd_token_type_t type; // token type
|
|
||||||
|
|
||||||
char *text; // token text
|
|
||||||
char *desc; // token description
|
|
||||||
|
|
||||||
long long value; // for numeric types
|
|
||||||
long long min, max; // for ranges
|
|
||||||
|
|
||||||
char *arg; // user input that matches this token
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* _GRAMMAR_SANDBOX_H */
|
|
|
@ -70,7 +70,7 @@ permute (struct graph_node *start)
|
||||||
for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
|
for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
|
||||||
{
|
{
|
||||||
struct cmd_token *tt = gnn->data;
|
struct cmd_token *tt = gnn->data;
|
||||||
if (tt->type < SELECTOR_TKN)
|
if (tt->type < SPECIAL_TKN)
|
||||||
fprintf (stdout, "%s ", tt->text);
|
fprintf (stdout, "%s ", tt->text);
|
||||||
}
|
}
|
||||||
fprintf (stdout, "\n");
|
fprintf (stdout, "\n");
|
||||||
|
|
Loading…
Reference in a new issue