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