]>
Commit | Line | Data |
---|---|---|
51e156b3 | 1 | #include "command.h" |
478bdaeb | 2 | #include "command_parse.h" |
4b0abf24 | 3 | #include "cmdtree.h" |
51e156b3 QY |
4 | |
5 | #define GRAMMAR_STR "CLI grammar sandbox\n" | |
6 | ||
340a2b4a QY |
7 | struct graph_node * nodegraph; |
8 | ||
478bdaeb QY |
9 | DEFUN (grammar_test, |
10 | grammar_test_cmd, | |
340a2b4a | 11 | "grammar parse .COMMAND", |
51e156b3 | 12 | GRAMMAR_STR |
478bdaeb | 13 | "command to pass to new parser\n") |
51e156b3 | 14 | { |
478bdaeb QY |
15 | size_t linesize = 0; |
16 | for (int i = 0; i < argc; i++) | |
17 | linesize += strlen(argv[i]) + 1; | |
51e156b3 | 18 | |
478bdaeb QY |
19 | char* cat = malloc(linesize); |
20 | cat[0] = '\0'; | |
21 | for (int i = 0; i < argc; i++) { | |
22 | strcat(cat, argv[i]); | |
23 | if (i != argc) | |
24 | strcat(cat, " "); | |
25 | } | |
51e156b3 | 26 | |
340a2b4a QY |
27 | //struct graph_node *result = new_node(NUL_GN); |
28 | cmd_parse_format_new((const char*) cat, "lol", nodegraph); | |
29 | walk_graph(nodegraph, 0); | |
30 | ||
478bdaeb | 31 | return CMD_SUCCESS; |
51e156b3 QY |
32 | } |
33 | ||
340a2b4a QY |
34 | DEFUN (grammar_test_show, |
35 | grammar_test_show_cmd, | |
36 | "grammar tree", | |
37 | GRAMMAR_STR | |
38 | "print current accumulated DFA\n") | |
39 | { | |
40 | walk_graph(nodegraph, 0); | |
41 | return CMD_SUCCESS; | |
42 | } | |
43 | ||
51e156b3 QY |
44 | |
45 | void grammar_sandbox_init(void); | |
46 | void grammar_sandbox_init() { | |
340a2b4a QY |
47 | fprintf(stderr, "reinitializing graph\n"); |
48 | nodegraph = new_node(NUL_GN); | |
478bdaeb | 49 | install_element (ENABLE_NODE, &grammar_test_cmd); |
340a2b4a | 50 | install_element (ENABLE_NODE, &grammar_test_show_cmd); |
51e156b3 | 51 | } |