]> git.proxmox.com Git - mirror_frr.git/blame - lib/command.y
lib: Update build config for new parser
[mirror_frr.git] / lib / command.y
CommitLineData
92055a92
QY
1%{
2#include <string.h>
3#include <stdlib.h>
4#include <stdio.h>
782d9789 5#include "cmdtree.h"
92055a92
QY
6
7extern int yylex(void);
782d9789
QY
8void yyerror(const char *);
9
10// turn on debug
11#define YYDEBUG 1
92055a92
QY
12%}
13
14%union{
15 int integer;
16 char *string;
782d9789 17 struct graph_node *node;
92055a92
QY
18}
19
782d9789
QY
20%{
21// last top-level node
22struct graph_node *topnode,
23//
24 *optnode,
25 *selnode;
26%}
27
28%token <string> WORD
29%token <string> IPV4
30%token <string> IPV4_PREFIX
31%token <string> IPV6
32%token <string> IPV6_PREFIX
33%token <string> VARIABLE
34%token <string> RANGE
35%token <integer> NUMBER
36
37%type <node> start
38%type <node> sentence_root
39%type <node> cmd_token
40%type <node> literal_token
41%type <node> placeholder_token
42%type <node> option_token
43%type <node> selector_token
44%type <node> option
45%type <node> selector
46%type <node> selector_token_seq
47%type <node> option_token_seq
48
49%output "command.c"
50%defines
92055a92
QY
51
52/* grammar proper */
53%%
54
782d9789
QY
55start: sentence_root
56 cmd_token_seq;
92055a92 57
782d9789
QY
58sentence_root: WORD {
59 currnode = new_node(WORD_GN);
60 currnode->is_root = 1;
61 };
92055a92
QY
62
63/* valid top level tokens */
782d9789
QY
64cmd_token:
65 placeholder_token
66| literal_token
67| selector
68| option
69;
92055a92 70
782d9789
QY
71cmd_token_seq:
72 %empty
73| cmd_token_seq cmd_token
74;
75
76placeholder_token:
77 IPV4 {$$ = new_node(IPV4_GN);}
78| IPV4_PREFIX {$$ = new_node(IPV4_PREFIX_GN);}
79| IPV6 {$$ = new_node(IPV6_GN);}
80| IPV6_PREFIX {$$ = new_node(IPV6_PREFIX_GN);}
81| VARIABLE {$$ = new_node(VARIABLE_GN);}
82| RANGE {$$ = new_node(RANGE_GN);}
83;
84
85literal_token:
86 WORD {$$ = new_node(WORD_GN);}
87| NUMBER {$$ = new_node(NUMBER_GN);}
88;
92055a92
QY
89
90/* <selector|token> productions */
782d9789
QY
91selector:
92 '<' selector_part '|'
93 selector_element '>' {
94 //$$ = new_node(SELECTOR_GN);
95 //add_node($$, $4);
96 };
97
98selector_part:
99 selector_part '|' selector_element
100| selector_element
101;
102
103selector_element:
104 WORD selector_token_seq;
105
106selector_token_seq:
107 %empty
108| selector_token_seq selector_token {
109 //add_node(currnode, $2);
110 //currnode = $2;
111 }
112;
113
114selector_token:
115 literal_token
116| placeholder_token
117| option
118;
92055a92
QY
119
120/* [option|set] productions */
782d9789
QY
121option: '[' option_part ']';
122
123option_part:
124 option_part '|' option_token_seq
125| option_token_seq
126;
127
128option_token_seq:
129 option_token
130| option_token_seq option_token
131;
132
133option_token:
134 literal_token
135| placeholder_token
136;
137
92055a92
QY
138%%
139
140int
141main (void)
142{
782d9789
QY
143 yydebug = 1;
144 const char* input = "show [random conf NAME] thing";
145 printf("Parsing:\n\t%s\n", input);
146 return cmd_parse_format(input, "description");
92055a92
QY
147}
148
149void yyerror(char const *message) {
150 printf("Grammar error: %s\n", message);
151 exit(EXIT_FAILURE);
152}
782d9789
QY
153
154int
155cmd_parse_format(const char *string, const char *desc)
156{
157 yy_scan_string(string);
158 yyparse();
159 return 0;
160}
161
162