Class: Solver::Lexer

Inherits:
ANTLR3::Lexer
  • Object
show all
Includes:
TokenData
Defined in:
lib/plympton/SolverLexer.rb

Defined Under Namespace

Classes: DFA3

Constant Summary collapse

RULE_NAMES =
[ "PLUS", "MINUS", "MULT", "DIV", "MOD", "EXP", "LPAREN", 
"RPAREN", "T__19", "INT", "FLOAT", "MODVAR", "UNMODVAR", 
"WHITESPACE", "DIGIT", "MODIFIER" ].freeze
RULE_METHODS =
[ :plus!, :minus!, :mult!, :div!, :mod!, :exp!, :lparen!, 
:rparen!, :t__19!, :int!, :float!, :modvar!, :unmodvar!, 
:whitespace!, :digit!, :modifier! ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(input = nil, options = {}) ⇒ Lexer

Returns a new instance of Lexer.



96
97
98
99
# File 'lib/plympton/SolverLexer.rb', line 96

def initialize( input=nil, options = {} )
  super( input, options )

end

Instance Method Details

#digit!Object

lexer rule digit! (DIGIT) (in solver.g)



532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/plympton/SolverLexer.rb', line 532

def digit!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 15 )

  
  # - - - - main rule block - - - -
  # at line 117:18: '0' .. '9'
  match_range( 0x30, 0x39 )

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 15 )

end

#div!Object

lexer rule div! (DIV) (in solver.g)



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/plympton/SolverLexer.rb', line 195

def div!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 4 )

  type = DIV
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 24:7: '/'
  match( 0x2f )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 4 )

end

#exp!Object

lexer rule exp! (EXP) (in solver.g)



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/plympton/SolverLexer.rb', line 243

def exp!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 6 )

  type = EXP
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 26:7: '^'
  match( 0x5e )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 6 )

end

#float!Object

lexer rule float! (FLOAT) (in solver.g)



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/plympton/SolverLexer.rb', line 387

def float!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 11 )

  type = FLOAT
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 108:12: INT '.' INT
  int!
  match( 0x2e )
  int!

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 11 )

end

#int!Object

lexer rule int! (INT) (in solver.g)



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/plympton/SolverLexer.rb', line 339

def int!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 10 )

  type = INT
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 107:11: ( DIGIT )+
  # at file 107:11: ( DIGIT )+
  match_count_1 = 0
  while true
    alt_1 = 2
    look_1_0 = @input.peek( 1 )

    if ( look_1_0.between?( 0x30, 0x39 ) )
      alt_1 = 1

    end
    case alt_1
    when 1
      # at line 107:12: DIGIT
      digit!

    else
      match_count_1 > 0 and break
      eee = EarlyExit(1)


      raise eee
    end
    match_count_1 += 1
  end


  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 10 )

end

#lparen!Object

lexer rule lparen! (LPAREN) (in solver.g)



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/plympton/SolverLexer.rb', line 267

def lparen!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 7 )

  type = LPAREN
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 27:10: '('
  match( 0x28 )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 7 )

end

#minus!Object

lexer rule minus! (MINUS) (in solver.g)



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/plympton/SolverLexer.rb', line 147

def minus!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 2 )

  type = MINUS
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 22:9: '-'
  match( 0x2d )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 2 )

end

#mod!Object

lexer rule mod! (MOD) (in solver.g)



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/plympton/SolverLexer.rb', line 219

def mod!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 5 )

  type = MOD
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 25:7: '%'
  match( 0x25 )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 5 )

end

#modifier!Object

lexer rule modifier! (MODIFIER) (in solver.g)



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/plympton/SolverLexer.rb', line 549

def modifier!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 16 )

  
  # - - - - main rule block - - - -
  # at line 
  if @input.peek(1) == 0x61 || @input.peek(1) == 0x73
    @input.consume
  else
    mse = MismatchedSet( nil )
    recover mse
    raise mse
  end



ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 16 )

end

#modvar!Object

lexer rule modvar! (MODVAR) (in solver.g)



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/plympton/SolverLexer.rb', line 413

def modvar!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 12 )

  type = MODVAR
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 109:13: 'A' .. 'G' ( MODIFIER )
  match_range( 0x41, 0x47 )
  # at line 109:21: ( MODIFIER )
  # at line 109:22: MODIFIER
  modifier!


  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 12 )

end

#mult!Object

lexer rule mult! (MULT) (in solver.g)



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/plympton/SolverLexer.rb', line 171

def mult!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 3 )

  type = MULT
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 23:8: '*'
  match( 0x2a )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 3 )

end

#plus!Object

                      • lexer rules - - - - - - - - - - - -

lexer rule plus! (PLUS) (in solver.g)



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/plympton/SolverLexer.rb', line 123

def plus!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 1 )

  type = PLUS
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 21:8: '+'
  match( 0x2b )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 1 )

end

#recover(error = $!) ⇒ Object

Recovery function handling errors



106
107
108
109
# File 'lib/plympton/SolverLexer.rb', line 106

def recover( error = $! )
	puts "Lexer Recovering: #{error}"
	exit(1)
end

#report_error(error = $!) ⇒ Object

Reporting function handling errors



112
113
114
115
# File 'lib/plympton/SolverLexer.rb', line 112

def report_error( error = $! )
	puts "Lexer Reporting: #{error}"
	exit(1)
end

#rparen!Object

lexer rule rparen! (RPAREN) (in solver.g)



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/plympton/SolverLexer.rb', line 291

def rparen!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 8 )

  type = RPAREN
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 28:10: ')'
  match( 0x29 )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 8 )

end

#t__19!Object

lexer rule t__19! (T__19) (in solver.g)



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/plympton/SolverLexer.rb', line 315

def t__19!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 9 )

  type = T__19
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 29:9: 'ln'
  match( "ln" )

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 9 )

end

#token!Object

main rule used to study the input at the current position, and choose the proper lexer rule to call in order to fetch the next token

usually, you don’t make direct calls to this method, but instead use the next_token method, which will build and emit the actual next token



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/plympton/SolverLexer.rb', line 579

def token!
  # at line 1:8: ( PLUS | MINUS | MULT | DIV | MOD | EXP | LPAREN | RPAREN | T__19 | INT | FLOAT | MODVAR | UNMODVAR | WHITESPACE )
  alt_3 = 14
  alt_3 = @dfa3.predict( @input )
  case alt_3
  when 1
    # at line 1:10: PLUS
    plus!

  when 2
    # at line 1:15: MINUS
    minus!

  when 3
    # at line 1:21: MULT
    mult!

  when 4
    # at line 1:26: DIV
    div!

  when 5
    # at line 1:30: MOD
    mod!

  when 6
    # at line 1:34: EXP
    exp!

  when 7
    # at line 1:38: LPAREN
    lparen!

  when 8
    # at line 1:45: RPAREN
    rparen!

  when 9
    # at line 1:52: T__19
    t__19!

  when 10
    # at line 1:58: INT
    int!

  when 11
    # at line 1:62: FLOAT
    float!

  when 12
    # at line 1:68: MODVAR
    modvar!

  when 13
    # at line 1:75: UNMODVAR
    unmodvar!

  when 14
    # at line 1:84: WHITESPACE
    whitespace!

  end
end

#unmodvar!Object

lexer rule unmodvar! (UNMODVAR) (in solver.g)



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/plympton/SolverLexer.rb', line 441

def unmodvar!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 13 )

  type = UNMODVAR
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 110:14: ( 'R' | 'U' | 'V' )
  if @input.peek(1) == 0x52 || @input.peek( 1 ).between?( 0x55, 0x56 )
    @input.consume
  else
    mse = MismatchedSet( nil )
    recover mse
    raise mse
  end



  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 13 )

end

#whitespace!Object

lexer rule whitespace! (WHITESPACE) (in solver.g)



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/plympton/SolverLexer.rb', line 473

def whitespace!
  # -> uncomment the next line to manually enable rule tracing
  # trace_in( __method__, 14 )

  type = WHITESPACE
  channel = ANTLR3::DEFAULT_CHANNEL

  
  # - - - - main rule block - - - -
  # at line 111:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+
  # at file 111:14: ( '\\t' | ' ' | '\\r' | '\\n' | '\\u000C' )+
  match_count_2 = 0
  while true
    alt_2 = 2
    look_2_0 = @input.peek( 1 )

    if ( look_2_0.between?( 0x9, 0xa ) || look_2_0.between?( 0xc, 0xd ) || look_2_0 == 0x20 )
      alt_2 = 1

    end
    case alt_2
    when 1
      # at line 
      if @input.peek( 1 ).between?( 0x9, 0xa ) || @input.peek( 1 ).between?( 0xc, 0xd ) || @input.peek(1) == 0x20
        @input.consume
      else
        mse = MismatchedSet( nil )
        recover mse
        raise mse
      end



    else
      match_count_2 > 0 and break
      eee = EarlyExit(2)


      raise eee
    end
    match_count_2 += 1
  end

  # --> action
   channel = HIDDEN; 
  # <-- action

  
  @state.type = type
  @state.channel = channel

ensure
  # -> uncomment the next line to manually enable rule tracing
  # trace_out( __method__, 14 )

end