summaryrefslogtreecommitdiff
path: root/lib/command_parse.y
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-07-27 01:35:46 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-07-27 01:35:46 +0000
commiteceb106640e0279ed89e476c25f37f3b2da860fc (patch)
treeb12bbe56de2a2ad613a8880ae1b7d825a7fd992e /lib/command_parse.y
parenta53fbbf5f0e52793c262f9326340a606cf37500f (diff)
lib: Add matching and argv support
Queries may be run against DFA's to find matching cmd_element, and argument lists may be constructed. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_parse.y')
-rw-r--r--lib/command_parse.y41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/command_parse.y b/lib/command_parse.y
index 1cef6766ae..7b56aec952 100644
--- a/lib/command_parse.y
+++ b/lib/command_parse.y
@@ -9,22 +9,24 @@
*/
%{
-#include "command_graph.h"
-#include "command_new.h"
-
extern int yylex(void);
extern void yyerror(const char *);
// compile with debugging facilities
#define YYDEBUG 1
%}
+%code requires {
+ #include "command.h"
+ #include "command_graph.h"
+}
%code provides {
-extern struct
-graph_node *cmd_parse_format(const char *, const char *, struct graph_node *);
-extern void
-set_buffer_string(const char *);
+ extern void
+ set_buffer_string(const char *);
+ struct graph_node *
+ parse_command_format(struct graph_node *, struct cmd_element *);
}
+
/* valid types for tokens */
%union{
int integer;
@@ -45,7 +47,7 @@ struct graph_node *optnode_start, // start node for option set
struct graph_node *selnode_start, // start node for selector set
*selnode_end; // end node for selector set
-const struct cmd_element *command; // command we're parsing
+struct cmd_element *command; // command we're parsing
%}
%token <node> WORD
@@ -86,12 +88,16 @@ start: sentence_root
struct graph_node *end = new_node(END_GN);
end->element = command;
+ // ensure there are no END_GN children
+ for (unsigned int i = 0; i < vector_active(currnode->children); i++)
+ {
+ struct graph_node *child = vector_slot(currnode->children, i);
+ if (child->type == END_GN)
+ yyerror("Duplicate command.");
+ }
+
// add node
end = add_node(currnode, end);
-
- // check that we did not get back an existing node
- if (!strcmp(command->string, end->element->string)
- yyerror("Duplicate command.");
}
sentence_root: WORD
@@ -166,12 +172,7 @@ placeholder_token:
// get the numbers out
strsep(&yylval.string, "(-)");
$$->min = atoi( strsep(&yylval.string, "(-)") );
- strsep(&yylval.string, "(-)");
$$->max = atoi( strsep(&yylval.string, "(-)") );
-
- // we could do this a variety of ways with either
- // the lexer or the parser, but this is the simplest
- // and involves the least amount of free()
}
;
@@ -304,9 +305,9 @@ void yyerror(char const *message) {
}
struct graph_node *
-cmd_parse_format(struct graph_node *start, struct cmd_element *cmd)
+parse_command_format(struct graph_node *start, struct cmd_element *cmd)
{
- fprintf(stderr, "parsing: %s\n", string);
+ fprintf(stderr, "parsing: %s\n", cmd->string);
/* clear state pointers */
startnode = currnode = seqhead = NULL;
@@ -318,7 +319,7 @@ cmd_parse_format(struct graph_node *start, struct cmd_element *cmd)
// command string
command = cmd;
// make flex read from a string
- set_buffer_string(input);
+ set_buffer_string(command->string);
// initialize the start node of this command dfa
startnode = start;
// parse command into DFA