112 {
114 {DOCTYPE} {
countLines(yyscanner,yytext,yyleng); }
115 {OPENSPECIAL} {
countLines(yyscanner,yytext,yyleng); BEGIN(Prolog); }
118 BEGIN(Element); }
119 {COMMENT} { yyextra->commentContext = YY_START;
120 BEGIN(Comment);
121 }
static void countLines(yyscan_t yyscanner, const char *txt, yy_size_t len)
static void initElement(yyscan_t yyscanner)
122}
123<Content>{
124 {CDATA} {
countLines(yyscanner,yytext,yyleng);
125 yyextra->cdataContext = YY_START;
126 BEGIN(CDataSection);
127 }
128 {PCDATA} { yyextra->data +=
processData(yyscanner,yytext,yyleng); }
132 BEGIN(Element);
133 }
134 {COMMENT} { yyextra->commentContext = YY_START;
136 BEGIN(Comment);
137 }
static void addCharacters(yyscan_t yyscanner)
static std::string processData(yyscan_t yyscanner, const char *txt, yy_size_t len)
138}
139<Element>{
140 "/" { yyextra->isEnd = true; }
141 {NAME} { yyextra->name = yytext;
142 BEGIN(Attributes); }
145 yyextra->data = "";
146 BEGIN(Content);
147 }
static void addElement(yyscan_t yyscanner)
149}
150<Attributes>{
151 "/" { yyextra->selfClose = true; }
152 {NAME} { yyextra->attrName = yytext; }
153 "=" { BEGIN(AttributeValue); }
156 yyextra->data = "";
157 BEGIN(Content);
158 }
160}
161<AttributeValue>{
163 ['"] { yyextra->stringChar = *yytext;
164 yyextra->attrValue = "";
165 BEGIN(AttrValueStr);
166 }
167 . { std::string msg = std::string("Missing attribute value. Unexpected character `")+yytext+"` found";
168 reportError(yyscanner,msg);
169 unput(*yytext);
170 BEGIN(Attributes);
171 }
172}
173<AttrValueStr>{
174 [^'"\n]+ { yyextra->attrValue += processData(yyscanner,yytext,yyleng); }
175 ['"] { if (*yytext==yyextra->stringChar)
176 {
177 addAttribute(yyscanner);
178 BEGIN(Attributes);
179 }
180 else
181 {
182 yyextra->attrValue += processData(yyscanner,yytext,yyleng);
183 }
184 }
185 \n { yyextra->lineNr++; yyextra->attrValue+=' '; }
186}
187<CDataSection>{
188 {ENDCDATA} { BEGIN(yyextra->cdataContext); }
189 [^]\n]+ { yyextra->data += yytext; }
190 \n { yyextra->data += yytext;
191 yyextra->lineNr++;
192 }
193 . { yyextra->data += yytext; }
194}
195<Prolog>{
196 "encoding"\s*=\s*\"[^\"]*\" {
197 std::string encoding=yytext;
198 size_t i=encoding.find('"');
199 encoding=encoding.substr(i+1,yyleng-i-2);
200 if (encoding!="UTF-8") // need to transcode to UTF-8
201 {
202 yyextra->encoding=encoding;
203 }
204 }
205 {CLOSESPECIAL} { countLines(yyscanner,yytext,yyleng);
206 BEGIN(Initial);
207 }
208 \n { yyextra->lineNr++; }
209 . { }
210}
211<Comment>{
212 {COMMENTEND} {
countLines(yyscanner,yytext,yyleng);
213 BEGIN(yyextra->commentContext);
214 }
215 [^\n-]+ { }
216 \n { yyextra->lineNr++; }
217 . { }
218}
219\n { yyextra->lineNr++; }
220. { std::string msg = "Unexpected character `";
224 }
225
226%%