add_nexthops (struct list *, struct graph_node *);
static struct list *
-match_command_r (struct graph_node *, vector, unsigned int);
+command_match_r (struct graph_node *, vector, unsigned int);
static int
score_precedence (enum graph_node_type);
static enum matcher_rv matcher_rv;
enum matcher_rv
-match_command (struct graph_node *start,
+command_match (struct graph_node *start,
vector vline,
struct list **argv,
struct cmd_element **el)
memcpy (vvline->index + 1, vline->index, sizeof (void *) * vline->alloced);
vvline->active = vline->active + 1;
- if ((*argv = match_command_r (start, vvline, 0))) // successful match
+ if ((*argv = command_match_r (start, vvline, 0))) // successful match
{
list_delete_node (*argv, listhead (*argv));
struct graph_node *end = listgetdata (listtail (*argv));
* @param[in] n the index of the first input token.
*/
static struct list *
-match_command_r (struct graph_node *start, vector vline, unsigned int n)
+command_match_r (struct graph_node *start, vector vline, unsigned int n)
{
assert (n < vector_active (vline));
}
// else recurse on candidate child node
- struct list *result = match_command_r (gn, vline, n+1);
+ struct list *result = command_match_r (gn, vline, n+1);
// save the best match
if (result && currbest)
}
enum matcher_rv
-match_command_complete (struct graph_node *start, vector vline, struct list **completions)
+command_complete (struct graph_node *start,
+ vector vline,
+ struct list **completions)
{
// pointer to next input token to match
char *token;
}
enum matcher_rv
-match_command_complete_str (struct graph_node *start,
- vector vline,
- vector completions)
+command_complete_str (struct graph_node *start,
+ vector vline,
+ vector completions)
{
struct list *comps;
- enum matcher_rv rv = match_command_complete (start, vline, &comps);
+ enum matcher_rv rv = command_complete (start, vline, &comps);
// quick n' dirty deduplication fn here, prolly like O(n^n)
struct listnode *ln;
static struct graph_node *
copy_node (struct graph_node *node)
{
- struct graph_node *new = new_node(node->type);
+ struct graph_node *new = graphnode_new(node->type);
new->children = NULL;
new->text = node->text ? XSTRDUP(MTYPE_CMD_TOKENS, node->text) : NULL;
new->value = node->value;
static void
delete_nodelist (void *node)
{
- delete_node ((struct graph_node *) node);
+ graphnode_delete ((struct graph_node *) node);
}
/* functionality this unit exports */
%code provides {
struct graph_node *
- parse_command_format (struct graph_node *, struct cmd_element *);
+ command_parse_format (struct graph_node *, struct cmd_element *);
/* maximum length of a number, lexer will not match anything longer */
#define DECIMAL_STRLEN_MAX 20
| sentence_root cmd_token_seq '.' placeholder_token
{
if ((currnode = node_replace (currnode, $4)) != $4)
- delete_node ($4);
+ graphnode_delete ($4);
// adding a node as a child of itself accepts any number
// of the same token, which is what we want for varags
sentence_root: WORD
{
- struct graph_node *root = new_node (WORD_GN);
+ struct graph_node *root = graphnode_new (WORD_GN);
root->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
root->doc = doc_next();
placeholder_token
{
if ((currnode = node_replace (currnode, $1)) != $1)
- delete_node ($1);
+ graphnode_delete ($1);
}
| literal_token
{
if ((currnode = node_replace (currnode, $1)) != $1)
- delete_node ($1);
+ graphnode_delete ($1);
}
/* selectors and options are subgraphs with start and end nodes */
| selector
{
- add_node (currnode, $1);
+ graphnode_add_child (currnode, $1);
currnode = selnode_end;
selnode_start = selnode_end = NULL;
}
| option
{
- add_node (currnode, $1);
+ graphnode_add_child (currnode, $1);
currnode = optnode_end;
optnode_start = optnode_end = NULL;
}
placeholder_token:
IPV4
{
- $$ = new_node (IPV4_GN);
+ $$ = graphnode_new (IPV4_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| IPV4_PREFIX
{
- $$ = new_node (IPV4_PREFIX_GN);
+ $$ = graphnode_new (IPV4_PREFIX_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| IPV6
{
- $$ = new_node (IPV6_GN);
+ $$ = graphnode_new (IPV6_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| IPV6_PREFIX
{
- $$ = new_node (IPV6_PREFIX_GN);
+ $$ = graphnode_new (IPV6_PREFIX_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| VARIABLE
{
- $$ = new_node (VARIABLE_GN);
+ $$ = graphnode_new (VARIABLE_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| RANGE
{
- $$ = new_node (RANGE_GN);
+ $$ = graphnode_new (RANGE_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
literal_token:
WORD
{
- $$ = new_node (WORD_GN);
+ $$ = graphnode_new (WORD_GN);
$$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
$$->doc = doc_next();
free ($1);
}
| NUMBER
{
- $$ = new_node (NUMBER_GN);
+ $$ = graphnode_new (NUMBER_GN);
$$->value = yylval.number;
$$->text = XCALLOC(MTYPE_CMD_TOKENS, DECIMAL_STRLEN_MAX+1);
snprintf($$->text, DECIMAL_STRLEN_MAX, "%lld", $$->value);
// if the selector start and end do not exist, create them
if (!selnode_start || !selnode_end) { // if one is null
assert(!selnode_start && !selnode_end); // both should be null
- selnode_start = new_node (SELECTOR_GN); // diverging node
- selnode_end = new_node (NUL_GN); // converging node
+ selnode_start = graphnode_new (SELECTOR_GN); // diverging node
+ selnode_end = graphnode_new (NUL_GN); // converging node
}
// add element head as a child of the selector
- add_node (selnode_start, $1);
+ graphnode_add_child (selnode_start, $1);
if ($2->type != NUL_GN) {
- add_node ($1, seqhead);
- add_node ($2, selnode_end);
+ graphnode_add_child ($1, seqhead);
+ graphnode_add_child ($2, selnode_end);
}
else
- add_node ($1, selnode_end);
+ graphnode_add_child ($1, selnode_end);
seqhead = NULL;
}
selector_token_seq:
- %empty { $$ = new_node (NUL_GN); }
+ %empty { $$ = graphnode_new (NUL_GN); }
| selector_token_seq selector_token
{
// if the sequence component is NUL_GN, this is a sequence start
seqhead = $2;
}
else // chain on new node
- add_node ($1, $2);
+ graphnode_add_child ($1, $2);
$$ = $2;
}
option: '[' option_part ']'
{
// add null path
- add_node (optnode_start, optnode_end);
+ graphnode_add_child (optnode_start, optnode_end);
$$ = optnode_start;
};
{
if (!optnode_start || !optnode_end) {
assert(!optnode_start && !optnode_end);
- optnode_start = new_node (OPTION_GN);
- optnode_end = new_node (NUL_GN);
+ optnode_start = graphnode_new (OPTION_GN);
+ optnode_end = graphnode_new (NUL_GN);
}
- add_node (optnode_start, seqhead);
- add_node ($1, optnode_end);
+ graphnode_add_child (optnode_start, seqhead);
+ graphnode_add_child ($1, optnode_end);
seqhead = NULL;
}
option_token
{ $$ = seqhead = $1; }
| option_token_seq option_token
-{ $$ = add_node ($1, $2); }
+{ $$ = graphnode_add_child ($1, $2); }
;
option_token:
%%
struct graph_node *
-parse_command_format(struct graph_node *start, struct cmd_element *cmd)
+command_parse_format (struct graph_node *start, struct cmd_element *cmd)
{
// set to 1 to enable parser traces
yydebug = 0;
struct graph_node *finalnode,
struct cmd_element *element)
{
- struct graph_node *end = new_node (END_GN);
+ struct graph_node *end = graphnode_new (END_GN);
end->element = element;
end->text = XSTRDUP(MTYPE_CMD_TOKENS, "<cr>");
if (node_exists (finalnode, end))
yyerror (element, startnode, "Duplicate command.");
else
- add_node (finalnode, end);
+ graphnode_add_child (finalnode, end);
}
static char *
node_replace (struct graph_node *parent, struct graph_node *child)
{
struct graph_node *existing = node_exists (parent, child);
- return existing ? existing : add_node (parent, child);
+ return existing ? existing : graphnode_add_child (parent, child);
}
static int
case NUMBER_GN:
if (first->value != second->value) return 0;
break;
- /* selectors and options should be equal if their subgraphs are equal, but
- * the graph isomorphism problem is not known to be solvable in polynomial time
- * so we consider selectors and options inequal in all cases; ultimately this
- * forks the graph, but the matcher can handle this regardless
+ /* selectors and options should be equal if their subgraphs are equal,
+ * but the graph isomorphism problem is not known to be solvable in
+ * polynomial time so we consider selectors and options inequal in all
+ * cases; ultimately this forks the graph, but the matcher can handle
+ * this regardless
*/
case SELECTOR_GN:
case OPTION_GN:
cmd->tokens = vector_init(VECTOR_MIN_SIZE);
// parse the command and install it into the command graph
- parse_command_format (nodegraph, cmd);
+ command_parse_format (nodegraph, cmd);
// free resources
free (command);
vector completions = vector_init (VECTOR_MIN_SIZE);
enum matcher_rv result =
- match_command_complete_str (nodegraph, command, completions);
+ command_complete_str (nodegraph, command, completions);
// print completions or relevant error message
if (!MATCHER_ERROR(result))
struct list *argvv = NULL;
struct cmd_element *element = NULL;
- enum matcher_rv result = match_command (nodegraph, command, &argvv, &element);
+ enum matcher_rv result = command_match (nodegraph, command, &argvv, &element);
// print completions or relevant error message
if (element)
cmd->tokens = vector_init (VECTOR_MIN_SIZE);
// parse element
- parse_command_format (nodegraph, cmd);
+ command_parse_format (nodegraph, cmd);
return CMD_SUCCESS;
}
/* this is called in vtysh.c to set up the testing shim */
void grammar_sandbox_init() {
zlog_info ("Initializing grammar testing shim");
- nodegraph = new_node(START_GN);
+ nodegraph = graphnode_new (START_GN);
install_element (ENABLE_NODE, &grammar_test_cmd);
install_element (ENABLE_NODE, &grammar_test_show_cmd);
install_element (ENABLE_NODE, &grammar_test_match_cmd);