1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/* $Id: xml_y.yy 2838 2007-12-01 03:02:12Z flaterco $
xml_y.yy Bison file for limited XML parser (just tags, no text).
This is *NOT* a general-purpose XML parser.
Note that all lists except for the top level one are returned in
reverse order.
Copyright (C) 1997 David Flater.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
%{
/* Cleanup2006 Legacy Cruft CloseEnough */
#include "common.hh"
#include "xmlparser.hh"
Dstr xmlfilename;
xmltag *xmlparsetree;
extern int yylex ();
extern void yyerror (constString s unusedParameter);
#define balance(lname,rname) { \
if ((*(lname)) != (*(rname))) { \
Dstr details ("Parse error in XML file "); \
details += xmlfilename; \
details += "\n<"; \
details += (*(lname)); \
details += "> ended by </"; \
details += (*(rname)); \
details += ">"; \
Global::barf (Error::XMLPARSE, details); \
} \
delete rname; }
%}
%union {
xmltag *tag;
xmlattribute *attribute;
Dstr *value;
}
%token <value> NAME ATTVALUE
%token XMLSTART
%type <tag> tag xml_file taglist
%type <attribute> attribute avlist
%%
xml_file: XMLSTART taglist
{ // Un-reverse the top-level list
xmltag *temp;
$$ = NULL;
while ($2) {
temp = $2->next;
$2->next = $$;
$$ = $2;
$2 = temp;
}
xmlparsetree = $$; }
;
taglist: tag
{ $$ = $1; }
| taglist tag
{ $$ = $2;
$$->next = $1; }
;
tag: '<' NAME avlist '>' '<' '/' NAME '>'
{
balance ($2, $7);
$$ = new xmltag;
$$->name = $2;
$$->attributes = $3;
$$->contents = NULL;
$$->next = NULL;
}
| '<' NAME avlist '>' taglist '<' '/' NAME '>'
{
balance ($2, $8);
$$ = new xmltag;
$$->name = $2;
$$->attributes = $3;
$$->contents = $5;
$$->next = NULL;
}
| '<' NAME avlist '/' '>'
{
$$ = new xmltag;
$$->name = $2;
$$->attributes = $3;
$$->contents = NULL;
$$->next = NULL;
}
| '<' NAME '>' '<' '/' NAME '>'
{
balance ($2, $6);
$$ = new xmltag;
$$->name = $2;
$$->attributes = NULL;
$$->contents = NULL;
$$->next = NULL;
}
| '<' NAME '>' taglist '<' '/' NAME '>'
{
balance ($2, $7);
$$ = new xmltag;
$$->name = $2;
$$->attributes = NULL;
$$->contents = $4;
$$->next = NULL;
}
| '<' NAME '/' '>'
{
$$ = new xmltag;
$$->name = $2;
$$->attributes = NULL;
$$->contents = NULL;
$$->next = NULL;
}
;
avlist: attribute
{ $$ = $1; }
| avlist attribute
{ $$ = $2;
$$->next = $1; }
;
attribute: NAME '=' ATTVALUE
{ $$ = new xmlattribute;
$$->name = $1;
$$->value = $3;
$$->next = NULL; }
;
%%
|