2 * Lexes Ragel input files.
6 * Test works with split code gen.
16 void escapeXML( const char *data )
18 while ( *data != 0 ) {
20 case '<': cout << "<"; break;
21 case '>': cout << ">"; break;
22 case '&': cout << "&"; break;
23 default: cout << *data; break;
29 void escapeXML( char c )
32 case '<': cout << "<"; break;
33 case '>': cout << ">"; break;
34 case '&': cout << "&"; break;
35 default: cout << c; break;
39 void escapeXML( const char *data, int len )
41 for ( const char *end = data + len; data != end; data++ ) {
43 case '<': cout << "<"; break;
44 case '>': cout << ">"; break;
45 case '&': cout << "&"; break;
46 default: cout << *data; break;
51 inline void write( const char *data )
56 inline void write( char c )
61 inline void write( const char *data, int len )
63 cout.write( data, len );
70 word = [a-zA-Z_][a-zA-Z_0-9]*;
72 hex = '0x' [0-9a-fA-F] [0-9a-fA-F]*;
77 # Handles comments in outside code and inline blocks.
84 escapeXML( ts, te-ts );
93 "'" ( [^'\\] | /\\./ )* "'" => emit;
94 '"' ( [^"\\] | /\\./ )* '"' => emit;
99 '//' [^\n]* '\n' => emit;
108 /* If dropping down to the last } then return
110 if ( --inline_depth == 0 ) {
111 write( "</inline>\n" );
116 default => { escapeXML( *ts ); };
125 if ( !single_line ) {
126 write( "</section>\n" );
133 write( "</section>\n" );
142 write( "</word>\n" );
152 # Hexidecimal integer.
162 # Single literal string.
163 "'" ( [^'\\] | /\\./ )* "'" {
164 write( "<single_lit>" );
165 escapeXML( ts, te-ts );
166 write( "</single_lit>\n" );
169 # Double literal string.
170 '"' ( [^"\\] | /\\./ )* '"' {
171 write( "<double_lit>" );
172 escapeXML( ts, te-ts );
173 write( "</double_lit>\n" );
177 '[' ( [^\]\\] | /\\./ )* ']' {
179 escapeXML( ts, te-ts );
180 write( "</or_lit>\n" );
184 '/' ( [^/\\] | /\\./ ) * '/' {
186 escapeXML( ts, te-ts );
187 write( "</re_lit>\n" );
190 # Open an inline block
193 write( "<inline>{" );
200 write( "</symbol>\n" );
212 "'" ( [^'\\] | /\\./ )* "'" => emit;
213 '"' ( [^"\\] | /\\./ )* '"' => emit;
216 escapeXML( ts, te-ts );
220 '//' [^\n]* '\n' => emit;
223 write( "<section>\n" );
229 write( "<section>\n" );
243 %% write data nofinal;
245 void test( const char *data )
247 std::ios::sync_with_stdio(false);
253 bool single_line = false;
254 int inline_depth = 0;
258 /* Read in a block. */
259 const char *p = data;
260 const char *pe = data + strlen( data );
261 const char *eof = pe;
264 if ( cs == RagelScan_error ) {
265 /* Machine failed before finding a token. */
266 cerr << "PARSE ERROR" << endl;
275 std::ios::sync_with_stdio(false);
277 test("hi %%{ /'}%%'/ { /*{*/ {} } + '\\'' }%%there\n");
281 #ifdef _____OUTPUT_____
283 <re_lit>/'}%%'/</re_lit>
284 <inline>{ /*{*/ {} }</inline>
286 <single_lit>'\''</single_lit>