2 * Lexes Ragel input files.
12 void escapeXML( char *data )
14 while ( *data != 0 ) {
16 case '<': cout << "<"; break;
17 case '>': cout << ">"; break;
18 case '&': cout << "&"; break;
19 default: cout << *data; break;
25 void escapeXML( char c )
28 case '<': cout << "<"; break;
29 case '>': cout << ">"; break;
30 case '&': cout << "&"; break;
31 default: cout << c; break;
35 void escapeXML( char *data, int len )
37 for ( char *end = data + len; data != end; data++ ) {
39 case '<': cout << "<"; break;
40 case '>': cout << ">"; break;
41 case '&': cout << "&"; break;
42 default: cout << *data; break;
47 inline void write( const char *data )
52 inline void write( char c )
57 inline void write( char *data, int len )
59 cout.write( data, len );
66 word = [a-zA-Z_][a-zA-Z_0-9]*;
68 hex = '0x' [0-9a-fA-F] [0-9a-fA-F]*;
73 # Handles comments in outside code and inline blocks.
80 escapeXML( ts, te-ts );
89 "'" ( [^'\\] | /\\./ )* "'" => emit;
90 '"' ( [^"\\] | /\\./ )* '"' => emit;
95 '//' [^\n]* '\n' => emit;
104 /* If dropping down to the last } then return
106 if ( --inline_depth == 0 ) {
107 write( "</inline>\n" );
112 default => { escapeXML( *ts ); };
121 if ( !single_line ) {
122 write( "</section>\n" );
129 write( "</section>\n" );
138 write( "</word>\n" );
148 # Hexidecimal integer.
158 # Single literal string.
159 "'" ( [^'\\] | /\\./ )* "'" {
160 write( "<single_lit>" );
161 escapeXML( ts, te-ts );
162 write( "</single_lit>\n" );
165 # Double literal string.
166 '"' ( [^"\\] | /\\./ )* '"' {
167 write( "<double_lit>" );
168 escapeXML( ts, te-ts );
169 write( "</double_lit>\n" );
173 '[' ( [^\]\\] | /\\./ )* ']' {
175 escapeXML( ts, te-ts );
176 write( "</or_lit>\n" );
180 '/' ( [^/\\] | /\\./ ) * '/' {
182 escapeXML( ts, te-ts );
183 write( "</re_lit>\n" );
186 # Open an inline block
189 write( "<inline>{" );
196 write( "</symbol>\n" );
208 "'" ( [^'\\] | /\\./ )* "'" => emit;
209 '"' ( [^"\\] | /\\./ )* '"' => emit;
212 escapeXML( ts, te-ts );
216 '//' [^\n]* '\n' => emit;
219 write( "<section>\n" );
225 write( "<section>\n" );
239 %% write data nofinal;
245 std::ios::sync_with_stdio(false);
251 static char inbuf[BUFSIZE];
252 bool single_line = false;
253 int inline_depth = 0;
260 /* How much space is in the buffer? */
261 int space = BUFSIZE - have;
263 /* Buffer is full. */
264 cerr << "TOKEN TOO BIG" << endl;
268 /* Read in a block. */
269 char *p = inbuf + have;
270 cin.read( p, space );
271 int len = cin.gcount();
283 if ( cs == RagelScan_error ) {
284 /* Machine failed before finding a token. */
285 cerr << "PARSE ERROR" << endl;
292 /* There is a prefix to preserve, shift it over. */
294 memmove( inbuf, ts, have );
295 te = inbuf + (te-ts);