1print <<END;
2/*
3 * Copyright (C) 2003 Lars Knoll (knoll\@kde.org)
4 *
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB.  If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22/* This file is mostly data generated by flex. Unfortunately flex
23   can't handle 16bit strings directly, so we just copy the part of
24   the code we need and modify it to our needs.
25
26   Most of the defines below are to make sure we can easily use the
27   flex generated code, using as little editing as possible.
28
29   The flex syntax to generate the lexer are more or less directly
30   copied from the CSS2.1 specs, with some fixes for comments and
31   the important symbol.
32
33   To regenerate, run flex on tokenizer.flex. After this, copy the
34   data tables and the YY_DECL method over to this file. Remove the
35   init code from YY_DECL and change the YY_END_OF_BUFFER to only call
36   yyterminate().
37
38*/
39
40// --------- begin generated code -------------------
41
42END
43
44{
45print<<END
46
47#include "CSSGrammar.h"
48
49#define INITIAL 0
50#define mediaquery 1
51#define forkeyword 2
52#define nthchild 3
53
54/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
55
56#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
57#include <inttypes.h>
58typedef int8_t flex_int8_t;
59typedef uint8_t flex_uint8_t;
60typedef int16_t flex_int16_t;
61typedef uint16_t flex_uint16_t;
62typedef int32_t flex_int32_t;
63typedef uint32_t flex_uint32_t;
64#else
65typedef signed char flex_int8_t;
66typedef short int flex_int16_t;
67typedef int flex_int32_t;
68typedef unsigned char flex_uint8_t;
69typedef unsigned short int flex_uint16_t;
70typedef unsigned int flex_uint32_t;
71#endif /* ! C99 */
72END
73}
74
75# Skip over the flex output prologue: the above typedefs, forward declarations, etc.
76# Stop when we get to the declarations of tables.
77while (<>) {
78    last if /YY_NUM_RULES/;
79}
80
81# Dump the generated tables.  /yy_last_accepting/ matches the first declaration after the tables.
82print;
83while (<>) {
84    last if /yy_last_accepting/;
85    print;
86}
87
88# Skip down the the declaration of yytext; the body of the flex output begins after it.
89while (<>) {
90  last if /yytext/;
91}
92# Dump the definitions of states (INITIAL, media query, tokenizer state support).
93while (<>) {
94  last if not (/define/ || /line/) ;
95  print;
96}
97
98# Skip to main scanner function.
99while (<>) {
100    last if /^YY_DECL/;
101}
102
103# Dump main scanner declarations, substituting in our 16-bit character type.
104# Declarations end with the declaration matching /yy_act/.
105print;
106while (<>) {
107    s/char/UChar/;
108    print;
109    last if /yy_act/;
110}
111
112# Skip past initialization code, down to main loop.
113while (<>) {
114    last if /while \( 1 \)/;
115}
116
117# Dump the main loop, skipping over labels we don't use.
118# Stop before dumping the end-of-buffer handling, because we output our own custom end-of-buffer handling.
119print;
120while (<>) {
121    next if /^yy_match:/;
122    next if /^do_action:/;
123    last if /YY_END_OF_BUFFER/;
124    if (/^case YY_STATE_EOF\(INITIAL\):/) {
125        print "case YY_END_OF_BUFFER:\n";
126        # flex outputs a ton of logic related to end-of-buffer handling; we just want to fall through to
127        # the yyterminate() found in other EOF states.  But we need to be careful to back up to behind
128        # the terminating double-NUL so that subsequent calls to flex will have the pointers in order,
129        # so this logic is a reduction of the normal flex-generated YY_END_OF_BUFFER code.
130        print "\tyy_c_buf_p = yy_cp - 1;\n";
131        print "\tyy_cp = yy_c_buf_p;\n";
132    }
133    print;
134}
135
136# Skip over the end-of-buffer handling; dump the rest of the function.
137while (<>) {
138    last if /default:/;
139}
140print;
141while (<>) {
142    print;
143    last if /end of yylex/;
144}
145
146# We don't want the remainder of flex's output.
147# However, flex may choke with "flex: error writing output file <stdout>"
148# if its stdout is unexpectedly closed on it.
149# Consume the remaining output.
150while (<>) {
151}
152