2 * Lexes Ragel input files.
11 void escapeXML( char *data )
13 while ( *data != 0 ) {
15 case '<': cout << "<"; break;
16 case '>': cout << ">"; break;
17 case '&': cout << "&"; break;
18 default: cout << *data; break;
24 void escapeXML( char c )
27 case '<': cout << "<"; break;
28 case '>': cout << ">"; break;
29 case '&': cout << "&"; break;
30 default: cout << c; break;
34 void escapeXML( char *data, int len )
36 for ( char *end = data + len; data != end; data++ ) {
38 case '<': cout << "<"; break;
39 case '>': cout << ">"; break;
40 case '&': cout << "&"; break;
41 default: cout << *data; break;
46 inline void write( char *data )
51 inline void write( char c )
56 inline void write( char *data, int len )
58 cout.write( data, len );
65 word = [a-zA-Z_][a-zA-Z_0-9]*;
67 hex = '0x' [0-9a-fA-F] [0-9a-fA-F]*;
72 # Handles comments in outside code and inline blocks.
79 escapeXML( tokstart, tokend-tokstart );
88 "'" ( [^'\\] | /\\./ )* "'" => emit;
89 '"' ( [^"\\] | /\\./ )* '"' => emit;
94 '//' [^\n]* '\n' => emit;
103 /* If dropping down to the last } then return
105 if ( --inline_depth == 0 ) {
106 write( "</inline>\n" );
111 default => { escapeXML( *tokstart ); };
120 if ( !single_line ) {
121 write( "</section>\n" );
128 write( "</section>\n" );
136 write( tokstart, tokend-tokstart );
137 write( "</word>\n" );
143 write( tokstart, tokend-tokstart );
147 # Hexidecimal integer.
150 write( tokstart, tokend-tokstart );
157 # Single literal string.
158 "'" ( [^'\\] | /\\./ )* "'" {
159 write( "<single_lit>" );
160 escapeXML( tokstart, tokend-tokstart );
161 write( "</single_lit>\n" );
164 # Double literal string.
165 '"' ( [^"\\] | /\\./ )* '"' {
166 write( "<double_lit>" );
167 escapeXML( tokstart, tokend-tokstart );
168 write( "</double_lit>\n" );
172 '[' ( [^\]\\] | /\\./ )* ']' {
174 escapeXML( tokstart, tokend-tokstart );
175 write( "</or_lit>\n" );
179 '/' ( [^/\\] | /\\./ ) * '/' {
181 escapeXML( tokstart, tokend-tokstart );
182 write( "</re_lit>\n" );
185 # Open an inline block
188 write( "<inline>{" );
195 write( "</symbol>\n" );
207 "'" ( [^'\\] | /\\./ )* "'" => emit;
208 '"' ( [^"\\] | /\\./ )* '"' => emit;
211 escapeXML( tokstart, tokend-tokstart );
215 '//' [^\n]* '\n' => emit;
218 write( "<section>\n" );
224 write( "<section>\n" );
230 escapeXML( *tokstart );
238 %% write data nofinal;
244 std::ios::sync_with_stdio(false);
247 char *tokstart, *tokend;
250 static char inbuf[BUFSIZE];
251 bool single_line = false;
252 int inline_depth = 0;
259 /* How much space is in the buffer? */
260 int space = BUFSIZE - have;
262 /* Buffer is full. */
263 cerr << "TOKEN TOO BIG" << endl;
267 /* Read in a block. */
268 char *p = inbuf + have;
269 cin.read( p, space );
270 int len = cin.gcount();
282 if ( cs == RagelScan_error ) {
283 /* Machine failed before finding a token. */
284 cerr << "PARSE ERROR" << endl;
291 /* There is a prefix to preserve, shift it over. */
292 have = pe - tokstart;
293 memmove( inbuf, tokstart, have );
294 tokend = inbuf + (tokend-tokstart);