b4dec9d7b588e56799b26a18434925aca32bf829
[com/gs-lite.git] / src / tools / xml.y
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15  \r
16  /*\r
17         MUST COMPILE WITH\r
18         bison --verbose -d -p xmlParser  -o xml.tab.cc xml.y\r
19 \r
20          (or equivalent).\r
21 */\r
22 \r
23 %{\r
24 \r
25 \r
26 #include <stdio.h>\r
27 \r
28 /*              Some addn'l includes, necessary but not included by the\r
29                 bison generated code.\r
30 */\r
31 \r
32 #include <stdlib.h>\r
33 \r
34 /*              prototypes for the parser callbacks.\r
35 */\r
36 \r
37 #include "xml_t.h"\r
38 \r
39 \r
40 extern xml_t *xml_result;\r
41 \r
42 extern int xmlParserdebug;\r
43 extern void xmlParsererror(char *s);\r
44 extern int xmlParserlex();\r
45 \r
46 \r
47 #define YYDEBUG 1\r
48 \r
49 %}\r
50 \r
51 \r
52         /* symbolic tokens */\r
53 \r
54 %union {\r
55         int intval;\r
56         double floatval;\r
57         char *strval;\r
58         int subtok;\r
59         struct name_val_pair_t *nvpt;\r
60         struct name_val_list_t *nvpl;\r
61         struct tag_t *tg_t;\r
62         struct xml_list_t *xlist_t;\r
63         struct xml_t *x_t;\r
64 }\r
65 \r
66 %token <strval> NAME\r
67 %token <strval> STRING_TOKEN\r
68 \r
69 %type <nvpt> val\r
70 %type <nvpl> val_list\r
71 %type <nvpl> opt_val_list\r
72 %type <strval> end_tag\r
73 %type <tg_t> start_tag\r
74 %type <xlist_t> xml_list\r
75 %type<x_t> resource\r
76 \r
77 \r
78 %%\r
79 \r
80 parse_result:   resource        {xml_result = $1;}\r
81         ;\r
82 \r
83 resource:\r
84         start_tag xml_list end_tag {$$ = new xml_t($1,$2,$3);}\r
85         | start_tag end_tag     {$$=new xml_t($1,$2);}\r
86         | '<' NAME opt_val_list '/' '>' {$$=new xml_t($2,$3);}\r
87         ;\r
88 \r
89 start_tag:\r
90         '<' NAME opt_val_list '>'       {$$ = new tag_t($2, $3);}\r
91         ;\r
92 \r
93 end_tag:\r
94         '<' '/' NAME '>'        {$$=$3;}\r
95         ;\r
96 \r
97 \r
98 xml_list:\r
99         resource        {$$=new xml_list_t($1);}\r
100         | xml_list resource     {$$=$1->append($2);}\r
101         ;\r
102 \r
103 opt_val_list:\r
104         val_list        {$$=$1;}\r
105         |               {$$=new name_val_list_t();}\r
106         ;\r
107 \r
108 val_list:\r
109         val             {$$ = new name_val_list_t($1);}\r
110         | val_list val {$$ = $1->append($2);}\r
111         ;\r
112 \r
113 val:\r
114         NAME '=' STRING_TOKEN   {$$ = new name_val_pair_t($1,$3);}\r
115         ;\r
116         \r
117 \r
118 \r
119 \r
120 \r
121 %%\r
122 \r
123 \r