@@ -96,8 +96,6 @@ public class RipperLexer extends LexingCommon {
96
96
map .put ("__ENCODING__" , Keyword .__ENCODING__ );
97
97
}
98
98
99
- public boolean ignoreNextScanEvent = false ;
100
-
101
99
protected void ambiguousOperator (String op , String syn ) {
102
100
parser .dispatch ("on_operator_ambiguous" , getRuntime ().newSymbol (op ), getRuntime ().newString (syn ));
103
101
}
@@ -248,6 +246,7 @@ public RipperLexer(RipperParserBase parser, LexerSource src) {
248
246
protected ByteList delayed = null ;
249
247
private int delayed_line = 0 ;
250
248
private int delayed_col = 0 ;
249
+ private boolean cr_seen = false ;
251
250
252
251
/**
253
252
* Has lexing started yet?
@@ -267,64 +266,76 @@ protected void flush_string_content(Encoding encoding) {
267
266
tokp = lex_p ;
268
267
}
269
268
}
270
-
271
- public int nextc () {
272
- if (lex_p == lex_pend ) {
273
- line_offset += lex_pend ;
274
269
275
- ByteList v = lex_nextline ;
276
- lex_nextline = null ;
277
-
278
- if (v == null ) {
279
- if (eofp ) return EOF ;
280
-
281
- if (src == null || (v = src .gets ()) == null ) {
282
- eofp = true ;
283
- lex_goto_eol ();
284
- return EOF ;
285
- }
286
- }
287
-
288
- // Left over stuffs...Add to delayed for later processing.
289
- if (tokp < lex_pend ) {
290
- if (delayed == null ) {
291
- delayed = new ByteList ();
292
- delayed .setEncoding (getEncoding ());
293
- delayed .append (lexb , tokp , lex_pend - tokp );
294
- delayed_line = ruby_sourceline ;
295
- delayed_col = tokp - lex_pbeg ;
296
- } else {
297
- delayed .append (lexb , tokp , lex_pend - tokp );
298
- }
270
+ public void addDelayedToken (int tok , int end ) {
271
+ // Left over stuffs...Add to delayed for later processing.
272
+ if (tok < end ) {
273
+ if (delayed == null ) {
274
+ delayed = new ByteList ();
275
+ delayed .setEncoding (getEncoding ());
276
+ delayed_line = ruby_sourceline ;
277
+ delayed_col = tok - lex_pbeg ;
299
278
}
300
-
301
- if (heredoc_end > 0 ) {
302
- ruby_sourceline = heredoc_end ;
303
- heredoc_end = 0 ;
279
+ delayed .append (lexb , tok , end - tok );
280
+ tokp = end ;
281
+ }
282
+ }
283
+
284
+ private boolean nextLine () {
285
+ line_offset += lex_pend ;
286
+
287
+ ByteList v = lex_nextline ;
288
+ lex_nextline = null ;
289
+
290
+ if (v == null ) {
291
+ if (eofp ) return true ;
292
+
293
+ if (src == null || (v = src .gets ()) == null ) {
294
+ eofp = true ;
295
+ lex_goto_eol ();
296
+ return true ;
304
297
}
305
- ruby_sourceline ++;
306
- line_count ++;
307
- lex_pbeg = lex_p = 0 ;
308
- lex_pend = lex_p + v .length ();
309
- lexb = v ;
310
- flush ();
311
- lex_lastline = v ;
298
+ cr_seen = false ;
312
299
}
313
-
300
+
301
+ addDelayedToken (tokp , lex_pend );
302
+
303
+ if (heredoc_end > 0 ) {
304
+ ruby_sourceline = heredoc_end ;
305
+ heredoc_end = 0 ;
306
+ }
307
+ ruby_sourceline ++;
308
+ line_count ++;
309
+ lex_pbeg = lex_p = 0 ;
310
+ lex_pend = lex_p + v .length ();
311
+ lexb = v ;
312
+ flush ();
313
+ lex_lastline = v ;
314
+
315
+ return false ;
316
+ }
317
+
318
+ private int cr (int c ) {
319
+ if (peek ('\n' )) {
320
+ lex_p ++;
321
+ c = '\n' ;
322
+ } else if (!cr_seen ) {
323
+ cr_seen = true ;
324
+ warn ("encountered \\ \\ r in middle of line, treated as a mere space" );
325
+ }
326
+ return c ;
327
+ }
328
+
329
+ public int nextc () {
330
+ if (lex_p == lex_pend || eofp || lex_nextline != null ) {
331
+ if (nextLine ()) return EOF ;
332
+ }
333
+
314
334
int c = p (lex_p );
315
335
lex_p ++;
316
- if (c == '\r' ) {
317
- if (peek ('\n' )) {
318
- lex_p ++;
319
- c = '\n' ;
320
- } else if (ruby_sourceline > last_cr_line ) {
321
- last_cr_line = ruby_sourceline ;
322
- warn ("encountered \\ \\ r in middle of line, treated as a mere space" );
323
- c = ' ' ;
324
- }
325
- }
326
336
327
- // System.out.println("C: " + (char) c + ", LEXP: " + lex_p + ", PEND: "+ lex_pend);
337
+ if (c == '\r' ) c = cr (c );
338
+
328
339
return c ;
329
340
}
330
341
@@ -714,7 +725,9 @@ private void printToken(int token) {
714
725
}
715
726
716
727
public boolean hasScanEvent () {
717
- if (lex_p < tokp ) throw parser .getRuntime ().newRuntimeError ("lex_p < tokp" );
728
+ if (lex_p < tokp ) {
729
+ throw parser .getRuntime ().newRuntimeError ("lex_p < tokp" );
730
+ }
718
731
719
732
return lex_p > tokp ;
720
733
}
0 commit comments