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