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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
|
head 1.3;
access;
symbols;
locks; strict;
comment @ * @;
1.3
date 99.11.21.19.38.12; author krisrose; state Exp;
branches;
next 1.2;
1.2
date 99.11.08.03.21.00; author krisrose; state Exp;
branches;
next 1.1;
1.1
date 99.10.26.16.20.08; author krisrose; state Exp;
branches;
next ;
desc
@@
1.3
log
@Moved to flexml.skel.
@
text
@%{
/* Flex(1) XML processor skeleton scanner.
* Copyright 1999 Kristoffer Rose. All rights reserved.
*
* This file is part of the FleXML XML processer generator system.
* See the companion README and INSTALL files for further information.
* Copyright 1999 Kristoffer Rose. All rights reserved.
*
* 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 2 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, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* (Note: FleXML depends on the format of this comment.)
*/
const char* rcs_flexml_skeleton =
"$Id: skeleton.l,v 1.2 1999/11/08 03:21:00 krisrose Exp krisrose $";
/* ANSI headers. */
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
FLEXML_API
/* XML state. */
#define ENTER(state) (yy_push_state(state))
#define LEAVE(state) (assert(yy_top_state()==state), yy_pop_state())
#define CHECKEPILOG(tag) if (YY_START==ROOT_##tag) BEGIN(EPILOG)
/* Text buffer. */
#define BUFFERSIZE 24000
static char buffer[BUFFERSIZE];
static char* nextp;
static char* lastp = buffer+BUFFERSIZE-1;
#define BUFFERINIT (nextp = buffer)
#define BUFFERSET(P) (P = nextp)
#define BUFFERPUTC(C) (assert(nextp<lastp), *(nextp++) = (C))
#define BUFFERDONE (BUFFERPUTC('\0'))
#define ENTITYTEXT(T)
/* Actions. */
#define SKIP
#define FAIL return fail
#define SUCCEED return 0
/* Diagnostics. */
static int fail(const char* fmt, ...)
{
va_list ap; va_start(ap, fmt);
fprintf(stderr, "Invalid XML: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
return 1;
}
%}
/* Flex options. */
%option 8bit
%option stack
%option noinput
%option nounput
%option noreject
%option noyymore
%option noyywrap
/* XML character classes (currently restricted to ASCII). */
/* "Common syntactic structures." */
S [ \t\n\r\f]+
/* "Names and Tokens." */
NameChar [[:alpha][:digit].:_-]
Name [[:alpha:]_:]{NameChar}*
Names {Name}({S}{Name})*
Nmtoken ({NameChar})+
Nmtokens {Nmtoken}({S}{Nmtoken})*
/* Miscellaneous. */
Version ([a-zA-Z0-9_.:-])+
Eq {S}?"="{S}?
/* XML parser states:
*
* INITIAL the XML prolog of the document before <?xml...>
* DOCTYPE the XML prolog of the document after <?xml...>
* EPILOG after the root element
* COMMENT inside an XML comment <!--....-->
* VALUE1 inside a '...'-delimited literal
* VALUE2 inside a "..."-delimited literal
* PCDATA inside a <tag> with textual ("mixed") contents
* CDATA inside a <![CDATA[...]]> section.
* ROOT_<tag> expect root element <tag>
* AL_<tag> inside the attribute list for <tag>
* IN_<tag> inside a <tag> with element contents
*/
%x DOCTYPE EPILOG COMMENT VALUE1 VALUE2 PCDATA CDATA
FLEXML_START_CONDITIONS
%%
/* PROLOG: determine root element and process it. */
<INITIAL>"<?xml"[^>]*"?>" BEGIN(DOCTYPE);
<DOCTYPE,INITIAL>{
FLEXML_DOCTYPES
"<!--" ENTER(COMMENT);
{S} SKIP;
. FAIL("Unexpected character `%c' in prolog.", *yytext);
<<EOF>> FAIL("EOF in prolog.");
}
/* RULES DERIVED FROM DTD. */
FLEXML_RULES
/* EPILOG: after the root element. */
<EPILOG>{
"<!--" ENTER(COMMENT);
{S} SKIP;
. FAIL("Unexpected character `%c' after document.", *yytext);
<<EOF>> SUCCEED;
}
/* COMMON SYNTAX. */
/* Comments. */
<COMMENT>{
"-->" LEAVE(COMMENT);
{S} |
. SKIP;
<<EOF>> FAIL("EOF in comment.");
}
/* Text. */
<VALUE1>\' BUFFERDONE; LEAVE(VALUE1);
<VALUE2>\" BUFFERDONE; LEAVE(VALUE2);
<PCDATA>{
"<!--" ENTER(COMMENT);
"<![CDATA[" ENTER(CDATA);
}
<PCDATA,VALUE1,VALUE2>{
FLEXML_ENTITIES
"&" BUFFERPUTC('&');
"<" BUFFERPUTC('<');
">" BUFFERPUTC('>');
"'" BUFFERPUTC('\'');
""" BUFFERPUTC('\"');
"&#"[[:digit:]]+";" BUFFERPUTC((unsigned char)atoi(yytext+2));
"&#x"[[:xdigit:]]+";" BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
. |
"\n" BUFFERPUTC(*yytext);
}
<PCDATA><<EOF>> FAIL("Premature EOF.");
<VALUE1><<EOF>> FAIL("EOF in literal (' expected).");
<VALUE2><<EOF>> FAIL("EOF in literal (\" expected).");
/* Literal data. */
<CDATA>{
"]]>" LEAVE(CDATA);
. |
"\n" BUFFERPUTC(*yytext);
<<EOF>> FAIL("EOF in CDATA section.");
}
%%
@
1.2
log
@ZZzzz.
@
text
@d2 11
a12 3
/*
* FleXML: flex(1) based XML scanner generator.
* Copyright 1999 NTSys, Ecully (France). All rights reserved.
d14 4
a17 4
* Description: Flex(1) skeleton scanner for XML data
* Author: Kristoffer Rose
* Created: August 1999
* License: GNU GPL "copyleft"
d19 3
a21 4
* 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 2 of the License, or
* (at your option) any later version.
d23 1
a23 10
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
FLEXML_TOPMATTER
d27 1
a27 3
"$Header: /plume/yquem/home/krisrose/cons/FleXML/RCS/skeleton.l,v 1.1 1999/10/26 16:20:08 krisrose Exp krisrose $";
FLEXML_VERSION
d34 1
d38 1
a38 1
/* Internals. */
d41 1
d43 1
d50 19
a68 2
#define BUFFERPUT(C) (assert(nextp<lastp), *(nextp++) = (C))
#define BUFFERNEXT (BUFFERPUT('\0'))
d71 1
a71 2
/* Flex options for in-memory scanner with stack... */
d82 1
a83 3
s [ \t\n\r\f]*
NameChar [[:alpha]_:[:digit].-]
d85 3
a87 1
Name [[:alpha:]_:]{NameChar}+
a88 1
d92 3
a94 2
Eq {s}"="{s}
Q [\'\"]
d96 2
a97 1
/* Start conditions:
d99 10
a108 6
* INITIAL the XML prolog of the document
* COMMENT inside an XML comment <!--....--> (exclusive)
* XML ready for XML elements
* AT_<tag> inside the attribute list for <tag>
* VALUE1 inside a '...'-delimited attribute value (exclusive)
* VALUE2 inside a "..."-delimited attribute value (exclusive)
a109 1
* PCDATA inside a <tag> with textual contents (exclusive)
d111 2
d114 1
a114 4
%x COMMENT
%s XML
%x VALUE1 VALUE2
%x PCDATA CDATA
d116 1
d118 1
a118 3
/* Start conditions derived from DTD. */
FLEXML_START_CONDITIONS
/* End of start conditions derived from DTD. */
d120 7
d128 2
a129 1
%%
d131 1
a131 1
/* GENERIC RULES PART. */
d133 5
a137 4
<INITIAL>{
"<?xml"{S}([^?]|"?"[^>])*"?>" |
FLEXML_DOCTYPE
{S} ;
d140 3
a142 1
/* Comments are permitted almost everywhere, including in the prolog. */
a143 1
"<!--" ENTER(COMMENT);
d145 4
a148 2
.|{S} /*IGNORE*/;
"-->" LEAVE(COMMENT);
d151 1
a151 1
/* The prolog is finished as soon as none of the above rules apply :) */
d153 2
a154 1
<INITIAL> BEGIN(XML);
d156 4
a159 7
/* Rules derived from DTD. */
FLEXML_RULES
/* End of rules derived from DTD. */
/* CharData. */
d162 1
a162 7
"&" BUFFERPUT('&');
"<" BUFFERPUT('<');
">" BUFFERPUT('>');
"'" BUFFERPUT('\'');
""" BUFFERPUT('"');
"&#"[[:digit:]]+";" BUFFERPUT((char)atoi(yytext+2));
}
d164 9
a172 2
<VALUE1,VALUE2>"%"[0-9a-zA-Z][0-9a-zA-Z] {
BUFFERPUT((char)strtol(yytext+1,NULL,16));
d175 11
a185 15
<VALUE1>\' BUFFERNEXT; LEAVE(VALUE1);
<VALUE2>\" BUFFERNEXT; LEAVE(VALUE2);
<PCDATA,VALUE1,VALUE2>[^&<] BUFFERPUT(*yytext);
/* Comments are permitted in text mode. */
<PCDATA>"<!--" ENTER(COMMENT);
/* Literal text. */
<PCDATA>"<![CDATA[" ENTER(CDATA);
<CDATA> {
"]]>" LEAVE(CDATA);
. BUFFERPUT(*yytext);
a186 4
/* Only `normal' exit is at the end of the input. */
<<EOF>> yyterminate();
@
1.1
log
@Initial revision
@
text
@d28 2
a29 2
static char* rcs_flexml_skeleton =
"$Header: /var/cvsroot/ntsys/FleXML/skeleton.l,v 1.8 1999/09/14 15:42:13 krisrose Exp $";
d37 1
d39 1
d41 12
a52 32
/* ------------------- USER HANDLER DECLARATIONS -------------------- */
void XML_init(void);
void XML_eof(void);
FLEXML_HANDLER_DECLARATIONS
/* --------------- END OF USER HANDLER DECLARATIONS ----------------- */
/* Declarations for use in the flex rules. */
#define STag(tag) (STag_##tag(), flexml_new_emit())
#define ETag(tag) flexml_pass_emitted(&ETag_##tag)
#define ENTER(state) (flexml_new_emit(), yy_push_state(state))
#define LEAVE(state) (flexml_new_emit(), yy_pop_state())
typedef void FLEXML_Handler(char*);
FLEXML_Handler* flexml_text_handlerp;
#define Attribute(tag,attribute) \
(ENTER(yytext[yyleng-1] == '\'' ? VALUE1 : VALUE2), \
flexml_new_emit(), flexml_text_handlerp = &Attribute_##tag##_##attribute)
#define HANDLE flexml_pass_emitted(flexml_text_handlerp)
void flexml_new_emit(void);
void flexml_emit(char);
void flexml_pass_emitted(FLEXML_Handler*);
void flexml_dummy_STag(char*);
void flexml_dummy_ETag(char*,char*);
void flexml_dummy_Attribute(char*,char*,char*);
a62 1
%option noyy_top_state
d96 1
a96 1
%x PCDATA
d110 1
a110 1
"<!DOCTYPE"{S}[^][>]*">" |
d124 1
a124 1
<INITIAL> XML_init(); BEGIN(XML);
d135 6
a140 6
"&" flexml_emit('&');
"<" flexml_emit('<');
">" flexml_emit('>');
"'" flexml_emit('\'');
""" flexml_emit('"');
"&#"[[:digit:]]+";" flexml_emit((char)atoi(yytext+2));
d144 1
a144 1
flexml_emit((char)strtol(yytext+1,NULL,16));
d147 2
a148 2
<VALUE1>\' HANDLE, LEAVE(VALUE1);
<VALUE2>\" HANDLE, LEAVE(VALUE2);
d150 1
a150 1
<PCDATA,VALUE1,VALUE2>[^&<] flexml_emit(yytext[0]);
d154 1
a154 1
<PCDATA>"<!--" ENTER(COMMENT);
d156 1
a156 1
/* Unmatched stuff ignored silently... */
d158 7
a164 1
<*>{S}|. ;
d166 1
a166 1
<<EOF>> XML_eof();
a168 27
/* GENERIC C FUNCTION PART. */
/* Emit buffer management. (TODO: use recursive scanning.) */
#define BIGBLOCKSIZE 10000
char emit_buf[BIGBLOCKSIZE];
int total;
void flexml_new_emit(void)
{
memset(emit_buf,0,BIGBLOCKSIZE);
total = 0;
}
void flexml_emit(char c)
{
if (total+1 < BIGBLOCKSIZE)
emit_buf[total++] = c;
else
fprintf(stderr, "#PCDATA or AttributeValue to long.\n");
}
void flexml_pass_emitted(FLEXML_Handler* hp)
{
(*hp)(emit_buf);
}
@
|