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 53/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ 54 55#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 56#include <inttypes.h> 57typedef int8_t flex_int8_t; 58typedef uint8_t flex_uint8_t; 59typedef int16_t flex_int16_t; 60typedef uint16_t flex_uint16_t; 61typedef int32_t flex_int32_t; 62typedef uint32_t flex_uint32_t; 63#else 64typedef signed char flex_int8_t; 65typedef short int flex_int16_t; 66typedef int flex_int32_t; 67typedef unsigned char flex_uint8_t; 68typedef unsigned short int flex_uint16_t; 69typedef unsigned int flex_uint32_t; 70#endif /* ! C99 */ 71END 72} 73 74# Skip over the flex output prologue: the above typedefs, forward declarations, etc. 75# Stop when we get to the declarations of tables. 76while (<>) { 77 last if /YY_NUM_RULES/; 78} 79 80# Dump the generated tables. /yy_last_accepting/ matches the first declaration after the tables. 81print; 82while (<>) { 83 last if /yy_last_accepting/; 84 print; 85} 86 87# Skip down the the declaration of yytext; the body of the flex output begins after it. 88while (<>) { 89 last if /yytext/; 90} 91# Dump the definitions of states (INITIAL, media query, tokenizer state support). 92while (<>) { 93 last if not (/define/ || /line/) ; 94 print; 95} 96 97# Skip to main scanner function. 98while (<>) { 99 last if /^YY_DECL/; 100} 101 102# Dump main scanner declarations, substituting in our 16-bit character type. 103# Declarations end with the declaration matching /yy_act/. 104print; 105while (<>) { 106 s/char/UChar/; 107 print; 108 last if /yy_act/; 109} 110 111# Skip past initialization code, down to main loop. 112while (<>) { 113 last if /while \( 1 \)/; 114} 115 116# Dump the main loop, skipping over labels we don't use. 117# Stop before dumping the end-of-buffer handling, because we output our own custom end-of-buffer handling. 118print; 119while (<>) { 120 next if /^yy_match:/; 121 next if /^do_action:/; 122 last if /YY_END_OF_BUFFER/; 123 if (/^case YY_STATE_EOF\(INITIAL\):/) { 124 print "case YY_END_OF_BUFFER:\n"; 125 # flex outputs a ton of logic related to end-of-buffer handling; we just want to fall through to 126 # the yyterminate() found in other EOF states. But we need to be careful to back up to behind 127 # the terminating double-NUL so that subsequent calls to flex will have the pointers in order, 128 # so this logic is a reduction of the normal flex-generated YY_END_OF_BUFFER code. 129 print "\tyy_c_buf_p = yy_cp - 1;\n"; 130 print "\tyy_cp = yy_c_buf_p;\n"; 131 } 132 print; 133} 134 135# Skip over the end-of-buffer handling; dump the rest of the function. 136while (<>) { 137 last if /default:/; 138} 139print; 140while (<>) { 141 print; 142 last if /end of yylex/; 143} 144 145# We don't want the remainder of flex's output. 146# However, flex may choke with "flex: error writing output file <stdout>" 147# if its stdout is unexpectedly closed on it. 148# Consume the remaining output. 149while (<>) { 150} 151