lrama 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c786e8955350ca51e6226aacd493073f7c31714ef7d5911dfb16259aa9415513
4
- data.tar.gz: d167b1a2df9dcbc8f31912e8842388aa7d6a788a8d3eeff0278c6d3ed5ecbac6
3
+ metadata.gz: 52e495f849079217c2cb4ee28edf873dd7c999d02f2f486acf8b9c2c1e74006f
4
+ data.tar.gz: 708aea3d87d066b71857d09c4b9fc0705c8abaedc1e8b8e465ae5f6c2a5e0315
5
5
  SHA512:
6
- metadata.gz: c89fe932ef32b5f441b87df33c2431c8631a069c293306d0a39c858e462731e11d753117ab4e7c48b4e4e41015405328a8d8f5590fbce3544e67babdaeddd8a6
7
- data.tar.gz: 619d1affd9f09c5c1b7748f712005b60073638be709e8bae986e39801173cf9de32555cf05837dbb7450360989989f5277e76a496eec702ace75c3b4af944471
6
+ metadata.gz: 779e08f5090a78347214d8fbe73e710469ed62f61e923b5fbf50ed1e4c022a4096961df035b517b4c6434fa69326d3a006d94cff144f2c87b48407093f8961c7
7
+ data.tar.gz: df1e4828906ae7613bca0f5f7dda3466091aa0fe15d7d5147e92bcd803f8ef0e58b6935a6e5061bb18d715a1e0f8b47aaab678c553edda828cb7ff1b05b2bc0f
data/Rakefile CHANGED
@@ -3,11 +3,11 @@ require "bundler/gem_tasks"
3
3
  namespace "build" do
4
4
  desc "build parser from parser.y by using Racc"
5
5
  task :racc_parser do
6
- `bundle exec racc parser.y --embedded -o lib/lrama/parser.rb`
6
+ sh "bundle exec racc parser.y --embedded -o lib/lrama/parser.rb"
7
7
  end
8
8
 
9
9
  desc "build parser for debugging"
10
10
  task :racc_verbose_parser do
11
- `bundle exec racc parser.y --embedded -o lib/lrama/parser.rb -t --log-file=parser.output`
11
+ sh "bundle exec racc parser.y --embedded -o lib/lrama/parser.rb -t --log-file=parser.output"
12
12
  end
13
13
  end
data/lib/lrama/command.rb CHANGED
@@ -8,7 +8,7 @@ module Lrama
8
8
  warning = Lrama::Warning.new
9
9
  text = options.y.read
10
10
  options.y.close if options.y != STDIN
11
- grammar = Lrama::Parser.new(text).parse
11
+ grammar = Lrama::Parser.new(text, options.grammar_file).parse
12
12
  states = Lrama::States.new(grammar, warning, trace_state: (options.trace_opts[:automaton] || options.trace_opts[:closure]))
13
13
  states.compute
14
14
  context = Lrama::Context.new(states)
data/lib/lrama/grammar.rb CHANGED
@@ -308,39 +308,45 @@ module Lrama
308
308
  @nterms ||= @symbols.select(&:nterm?)
309
309
  end
310
310
 
311
+ def scan_reference(scanner)
312
+ start = scanner.pos
313
+ case
314
+ # $ references
315
+ # It need to wrap an identifier with brackets to use ".-" for identifiers
316
+ when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\$/) # $$, $<long>$
317
+ tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
318
+ return [:dollar, "$", tag, start, scanner.pos - 1]
319
+ when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
320
+ tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
321
+ return [:dollar, Integer(scanner[2]), tag, start, scanner.pos - 1]
322
+ when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z_][a-zA-Z0-9_]*)/) # $foo, $expr, $<long>program (named reference without brackets)
323
+ tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
324
+ return [:dollar, scanner[2], tag, start, scanner.pos - 1]
325
+ when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # $expr.right, $expr-right, $<long>program (named reference with brackets)
326
+ tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
327
+ return [:dollar, scanner[2], tag, start, scanner.pos - 1]
328
+
329
+ # @ references
330
+ # It need to wrap an identifier with brackets to use ".-" for identifiers
331
+ when scanner.scan(/@\$/) # @$
332
+ return [:at, "$", nil, start, scanner.pos - 1]
333
+ when scanner.scan(/@(\d+)/) # @1
334
+ return [:at, Integer(scanner[1]), nil, start, scanner.pos - 1]
335
+ when scanner.scan(/@([a-zA-Z][a-zA-Z0-9_]*)/) # @foo, @expr (named reference without brackets)
336
+ return [:at, scanner[1], nil, start, scanner.pos - 1]
337
+ when scanner.scan(/@\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # @expr.right, @expr-right (named reference with brackets)
338
+ return [:at, scanner[1], nil, start, scanner.pos - 1]
339
+ end
340
+ end
341
+
311
342
  def extract_references
312
343
  unless initial_action.nil?
313
344
  scanner = StringScanner.new(initial_action.s_value)
314
345
  references = []
315
346
 
316
347
  while !scanner.eos? do
317
- start = scanner.pos
318
- case
319
- # $ references
320
- # It need to wrap an identifier with brackets to use ".-" for identifiers
321
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\$/) # $$, $<long>$
322
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
323
- references << [:dollar, "$", tag, start, scanner.pos - 1]
324
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
325
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
326
- references << [:dollar, Integer(scanner[2]), tag, start, scanner.pos - 1]
327
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z_][a-zA-Z0-9_]*)/) # $foo, $expr, $<long>program (named reference without brackets)
328
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
329
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
330
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # $expr.right, $expr-right, $<long>program (named reference with brackets)
331
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
332
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
333
-
334
- # @ references
335
- # It need to wrap an identifier with brackets to use ".-" for identifiers
336
- when scanner.scan(/@\$/) # @$
337
- references << [:at, "$", nil, start, scanner.pos - 1]
338
- when scanner.scan(/@(\d+)/) # @1
339
- references << [:at, Integer(scanner[1]), nil, start, scanner.pos - 1]
340
- when scanner.scan(/@([a-zA-Z][a-zA-Z0-9_]*)/) # @foo, @expr (named reference without brackets)
341
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
342
- when scanner.scan(/@\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # @expr.right, @expr-right (named reference with brackets)
343
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
348
+ if reference = scan_reference(scanner)
349
+ references << reference
344
350
  else
345
351
  scanner.getch
346
352
  end
@@ -355,33 +361,8 @@ module Lrama
355
361
  references = []
356
362
 
357
363
  while !scanner.eos? do
358
- start = scanner.pos
359
- case
360
- # $ references
361
- # It need to wrap an identifier with brackets to use ".-" for identifiers
362
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\$/) # $$, $<long>$
363
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
364
- references << [:dollar, "$", tag, start, scanner.pos - 1]
365
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
366
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
367
- references << [:dollar, Integer(scanner[2]), tag, start, scanner.pos - 1]
368
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z_][a-zA-Z0-9_]*)/) # $foo, $expr, $<long>program (named reference without brackets)
369
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
370
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
371
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # $expr.right, $expr-right, $<long>program (named reference with brackets)
372
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
373
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
374
-
375
- # @ references
376
- # It need to wrap an identifier with brackets to use ".-" for identifiers
377
- when scanner.scan(/@\$/) # @$
378
- references << [:at, "$", nil, start, scanner.pos - 1]
379
- when scanner.scan(/@(\d+)/) # @1
380
- references << [:at, Integer(scanner[1]), nil, start, scanner.pos - 1]
381
- when scanner.scan(/@([a-zA-Z][a-zA-Z0-9_]*)/) # @foo, @expr (named reference without brackets)
382
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
383
- when scanner.scan(/@\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # @expr.right, @expr-right (named reference with brackets)
384
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
364
+ if reference = scan_reference(scanner)
365
+ references << reference
385
366
  else
386
367
  scanner.getch
387
368
  end
@@ -396,33 +377,8 @@ module Lrama
396
377
  references = []
397
378
 
398
379
  while !scanner.eos? do
399
- start = scanner.pos
400
- case
401
- # $ references
402
- # It need to wrap an identifier with brackets to use ".-" for identifiers
403
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\$/) # $$, $<long>$
404
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
405
- references << [:dollar, "$", tag, start, scanner.pos - 1]
406
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
407
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
408
- references << [:dollar, Integer(scanner[2]), tag, start, scanner.pos - 1]
409
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z_][a-zA-Z0-9_]*)/) # $foo, $expr, $<long>program (named reference without brackets)
410
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
411
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
412
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # $expr.right, $expr-right, $<long>program (named reference with brackets)
413
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
414
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
415
-
416
- # @ references
417
- # It need to wrap an identifier with brackets to use ".-" for identifiers
418
- when scanner.scan(/@\$/) # @$
419
- references << [:at, "$", nil, start, scanner.pos - 1]
420
- when scanner.scan(/@(\d+)/) # @1
421
- references << [:at, Integer(scanner[1]), nil, start, scanner.pos - 1]
422
- when scanner.scan(/@([a-zA-Z][a-zA-Z0-9_]*)/) # @foo, @expr (named reference without brackets)
423
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
424
- when scanner.scan(/@\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # @expr.right, @expr-right (named reference with brackets)
425
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
380
+ if reference = scan_reference(scanner)
381
+ references << reference
426
382
  else
427
383
  scanner.getch
428
384
  end
@@ -440,34 +396,9 @@ module Lrama
440
396
  references = []
441
397
 
442
398
  while !scanner.eos? do
443
- start = scanner.pos
444
399
  case
445
- # $ references
446
- # It need to wrap an identifier with brackets to use ".-" for identifiers
447
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\$/) # $$, $<long>$
448
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
449
- references << [:dollar, "$", tag, start, scanner.pos - 1]
450
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?(\d+)/) # $1, $2, $<long>1
451
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
452
- references << [:dollar, Integer(scanner[2]), tag, start, scanner.pos - 1]
453
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?([a-zA-Z_][a-zA-Z0-9_]*)/) # $foo, $expr, $<long>program (named reference without brackets)
454
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
455
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
456
- when scanner.scan(/\$(<[a-zA-Z0-9_]+>)?\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # $expr.right, $expr-right, $<long>program (named reference with brackets)
457
- tag = scanner[1] ? Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Tag, s_value: scanner[1]) : nil
458
- references << [:dollar, scanner[2], tag, start, scanner.pos - 1]
459
-
460
- # @ references
461
- # It need to wrap an identifier with brackets to use ".-" for identifiers
462
- when scanner.scan(/@\$/) # @$
463
- references << [:at, "$", nil, start, scanner.pos - 1]
464
- when scanner.scan(/@(\d+)/) # @1
465
- references << [:at, Integer(scanner[1]), nil, start, scanner.pos - 1]
466
- when scanner.scan(/@([a-zA-Z][a-zA-Z0-9_]*)/) # @foo, @expr (named reference without brackets)
467
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
468
- when scanner.scan(/@\[([a-zA-Z_.][-a-zA-Z0-9_.]*)\]/) # @expr.right, @expr-right (named reference with brackets)
469
- references << [:at, scanner[1], nil, start, scanner.pos - 1]
470
-
400
+ when reference = scan_reference(scanner)
401
+ references << reference
471
402
  when scanner.scan(/\/\*/)
472
403
  scanner.scan_until(/\*\//)
473
404
  else
@@ -482,14 +413,6 @@ module Lrama
482
413
  end
483
414
  end
484
415
 
485
- def create_token(type, s_value, line, column)
486
- t = Token.new(type: type, s_value: s_value)
487
- t.line = line
488
- t.column = column
489
-
490
- return t
491
- end
492
-
493
416
  private
494
417
 
495
418
  def find_nterm_by_id!(id)
@@ -61,7 +61,6 @@ module Lrama
61
61
  o.separator ''
62
62
  o.separator 'Output:'
63
63
  o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v }
64
- o.on('-h=[FILE]', 'also produce a header file named FILE (deprecated)') {|v| @options.header = true; @options.header_file = v }
65
64
  o.on('-d', 'also produce a header file') { @options.header = true }
66
65
  o.on('-r', '--report=THINGS', Array, 'also produce details on the automaton') {|v| @report = v }
67
66
  o.on('--report-file=FILE', 'also produce details on the automaton output to a file named FILE') {|v| @options.report_file = v }
@@ -74,7 +73,7 @@ module Lrama
74
73
  o.separator ''
75
74
  o.separator 'Other options:'
76
75
  o.on('-V', '--version', "output version information and exit") {|v| puts "lrama #{Lrama::VERSION}"; exit 0 }
77
- o.on('--help', "display this help and exit") {|v| puts o; exit 0 }
76
+ o.on('-h', '--help', "display this help and exit") {|v| puts o; exit 0 }
78
77
  o.separator ''
79
78
  o.parse!(argv)
80
79
  end
data/lib/lrama/parser.rb CHANGED
@@ -668,12 +668,13 @@ end
668
668
  module Lrama
669
669
  class Parser < Racc::Parser
670
670
 
671
- module_eval(<<'...end parser.y/module_eval...', 'parser.y', 387)
671
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 388)
672
672
 
673
673
  include Lrama::Report::Duration
674
674
 
675
- def initialize(text)
675
+ def initialize(text, path)
676
676
  @text = text
677
+ @path = path
677
678
  end
678
679
 
679
680
  def parse
@@ -696,74 +697,78 @@ def next_token
696
697
  end
697
698
 
698
699
  def on_error(error_token_id, error_value, value_stack)
699
- raise ParseError, sprintf("\n%d:%d: parse error on value %s (%s)",
700
- @lexer.line, @lexer.column, error_value.inspect, token_to_str(error_token_id) || '?')
700
+ source = @text.split("\n")[error_value.line - 1]
701
+ raise ParseError, <<~ERROR
702
+ #{@path}:#{@lexer.line}:#{@lexer.column}: parse error on value #{error_value.inspect} (#{token_to_str(error_token_id) || '?'})
703
+ #{source}
704
+ #{' ' * @lexer.column}^
705
+ ERROR
701
706
  end
702
707
  ...end parser.y/module_eval...
703
708
  ##### State transition tables begin ###
704
709
 
705
710
  racc_action_table = [
706
- 77, 6, 41, 42, 7, 83, 65, 56, 41, 42,
707
- 68, 41, 42, 3, 134, 8, 20, 22, 23, 24,
708
- 25, 26, 27, 28, 29, 30, 65, 82, 41, 42,
709
- 65, 132, 135, 32, 38, 84, 41, 42, 134, 68,
710
- 41, 42, 65, 68, 41, 42, 131, 61, 41, 42,
711
- 39, 9, 41, 42, 44, 14, 135, 12, 65, 13,
712
- 15, 16, 17, 18, 41, 42, 19, 20, 22, 23,
713
- 24, 25, 26, 27, 28, 29, 30, 65, 46, 65,
714
- 41, 42, 65, 46, 65, 41, 42, 65, 41, 42,
715
- 65, 41, 42, 65, 41, 42, 65, 41, 42, 41,
716
- 42, 41, 42, 65, 41, 42, 41, 42, 153, 41,
717
- 42, 153, 41, 42, 153, 41, 42, 153, 41, 42,
718
- 65, 68, 41, 42, 153, 41, 42, 20, 22, 23,
719
- 24, 25, 26, 27, 28, 29, 30, 41, 42, 41,
720
- 42, 153, 41, 42, 46, 38, 41, 42, 41, 42,
721
- 41, 42, 41, 42, 41, 42, 49, 50, 51, 52,
711
+ 82, 132, 83, 42, 42, 41, 41, 65, 65, 42,
712
+ 42, 41, 41, 131, 56, 68, 3, 8, 38, 134,
713
+ 134, 42, 42, 41, 41, 65, 61, 68, 38, 6,
714
+ 32, 7, 84, 77, 135, 135, 20, 22, 23, 24,
715
+ 25, 26, 27, 28, 29, 30, 20, 22, 23, 24,
716
+ 25, 26, 27, 28, 29, 30, 9, 39, 44, 14,
717
+ 12, 13, 15, 16, 17, 18, 46, 46, 19, 20,
718
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 42,
719
+ 42, 41, 41, 46, 68, 68, 42, 42, 41, 41,
720
+ 65, 153, 42, 42, 41, 41, 65, 153, 42, 42,
721
+ 41, 41, 65, 153, 42, 42, 41, 41, 65, 153,
722
+ 42, 42, 41, 41, 65, 153, 42, 42, 41, 41,
723
+ 65, 153, 42, 42, 41, 41, 65, 65, 42, 42,
724
+ 41, 41, 65, 65, 42, 42, 41, 41, 65, 65,
725
+ 42, 42, 41, 41, 42, 42, 41, 41, 42, 42,
726
+ 41, 41, 42, 42, 41, 41, 49, 50, 51, 52,
722
727
  53, 74, 78, 80, 85, 85, 85, 92, 96, 97,
723
728
  105, 106, 108, 109, 110, 111, 112, 113, 116, 118,
724
729
  119, 122, 123, 124, 138, 139, 140, 141, 142, 143,
725
730
  122, 80, 148, 149, 156, 160, 161, 80, 80 ]
726
731
 
727
732
  racc_action_check = [
728
- 33, 2, 13, 13, 2, 40, 121, 25, 25, 25,
729
- 27, 27, 27, 1, 121, 3, 33, 33, 33, 33,
730
- 33, 33, 33, 33, 33, 33, 26, 40, 121, 121,
731
- 144, 120, 121, 7, 33, 40, 55, 55, 144, 28,
732
- 28, 28, 60, 29, 29, 29, 120, 26, 26, 26,
733
- 12, 4, 144, 144, 14, 4, 144, 4, 61, 4,
734
- 4, 4, 4, 4, 60, 60, 4, 4, 4, 4,
735
- 4, 4, 4, 4, 4, 4, 4, 97, 15, 99,
736
- 61, 61, 117, 16, 135, 56, 56, 141, 66, 66,
737
- 142, 67, 67, 143, 68, 68, 150, 71, 71, 97,
738
- 97, 99, 99, 154, 117, 117, 135, 135, 141, 141,
739
- 141, 142, 142, 142, 143, 143, 143, 150, 150, 150,
740
- 155, 30, 30, 30, 154, 154, 154, 9, 9, 9,
741
- 9, 9, 9, 9, 9, 9, 9, 72, 72, 73,
742
- 73, 155, 155, 155, 17, 9, 92, 92, 94, 94,
743
- 100, 100, 102, 102, 114, 114, 18, 20, 22, 23,
733
+ 40, 120, 40, 121, 144, 121, 144, 121, 144, 25,
734
+ 27, 25, 27, 120, 25, 27, 1, 3, 9, 121,
735
+ 144, 26, 28, 26, 28, 26, 26, 28, 33, 2,
736
+ 7, 2, 40, 33, 121, 144, 9, 9, 9, 9,
737
+ 9, 9, 9, 9, 9, 9, 33, 33, 33, 33,
738
+ 33, 33, 33, 33, 33, 33, 4, 12, 14, 4,
739
+ 4, 4, 4, 4, 4, 4, 15, 16, 4, 4,
740
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 29,
741
+ 30, 29, 30, 17, 29, 30, 141, 13, 141, 13,
742
+ 141, 141, 142, 55, 142, 55, 142, 142, 143, 56,
743
+ 143, 56, 143, 143, 150, 66, 150, 66, 150, 150,
744
+ 154, 67, 154, 67, 154, 154, 155, 68, 155, 68,
745
+ 155, 155, 60, 61, 60, 61, 60, 61, 97, 99,
746
+ 97, 99, 97, 99, 117, 135, 117, 135, 117, 135,
747
+ 71, 72, 71, 72, 73, 92, 73, 92, 94, 100,
748
+ 94, 100, 102, 114, 102, 114, 18, 20, 22, 23,
744
749
  24, 31, 36, 37, 45, 47, 48, 54, 58, 59,
745
750
  79, 80, 86, 87, 88, 89, 90, 91, 95, 103,
746
751
  104, 105, 106, 107, 125, 126, 127, 128, 129, 130,
747
752
  131, 133, 136, 137, 146, 157, 159, 160, 161 ]
748
753
 
749
754
  racc_action_pointer = [
750
- nil, 13, -2, 15, 49, nil, nil, 26, nil, 109,
751
- nil, nil, 41, -27, 47, 63, 68, 129, 141, nil,
752
- 142, nil, 143, 144, 145, -21, 19, -18, 11, 15,
753
- 93, 157, nil, -2, nil, nil, 145, 129, nil, nil,
754
- -2, nil, nil, nil, nil, 149, nil, 150, 151, nil,
755
- nil, nil, nil, nil, 139, 7, 56, nil, 159, 141,
756
- 35, 51, nil, nil, nil, nil, 59, 62, 65, nil,
757
- nil, 68, 108, 110, nil, nil, nil, nil, nil, 139,
758
- 142, nil, nil, nil, nil, nil, 168, 169, 170, 171,
759
- 172, 173, 117, nil, 119, 171, nil, 70, nil, 72,
760
- 121, nil, 123, 174, 176, 166, 147, 179, nil, nil,
761
- nil, nil, nil, nil, 125, nil, nil, 75, nil, nil,
762
- 14, -1, nil, nil, nil, 168, 169, 170, 171, 172,
763
- 173, 175, nil, 157, nil, 77, 188, 177, nil, nil,
764
- nil, 80, 83, 86, 23, nil, 190, nil, nil, nil,
765
- 89, nil, nil, nil, 96, 113, nil, 179, nil, 180,
766
- 163, 164, nil, nil ]
755
+ nil, 16, 19, 17, 47, nil, nil, 23, nil, 14,
756
+ nil, nil, 51, 84, 51, 47, 48, 64, 137, nil,
757
+ 138, nil, 139, 140, 141, 6, 18, 7, 19, 76,
758
+ 77, 159, nil, 24, nil, nil, 141, 128, nil, nil,
759
+ -5, nil, nil, nil, nil, 145, nil, 146, 147, nil,
760
+ nil, nil, nil, nil, 159, 90, 96, nil, 162, 161,
761
+ 119, 120, nil, nil, nil, nil, 102, 108, 114, nil,
762
+ nil, 137, 138, 141, nil, nil, nil, nil, nil, 138,
763
+ 166, nil, nil, nil, nil, nil, 170, 171, 172, 173,
764
+ 174, 175, 142, nil, 145, 171, nil, 125, nil, 126,
765
+ 146, nil, 149, 168, 178, 162, 146, 181, nil, nil,
766
+ nil, nil, nil, nil, 150, nil, nil, 131, nil, nil,
767
+ -20, 0, nil, nil, nil, 164, 165, 166, 167, 168,
768
+ 169, 171, nil, 156, nil, 132, 190, 173, nil, nil,
769
+ nil, 83, 89, 95, 1, nil, 192, nil, nil, nil,
770
+ 101, nil, nil, nil, 107, 113, nil, 175, nil, 176,
771
+ 162, 163, nil, nil ]
767
772
 
768
773
  racc_action_default = [
769
774
  -2, -104, -8, -104, -104, -3, -4, -104, 164, -104,
@@ -943,41 +948,41 @@ racc_shift_n = 164
943
948
  racc_token_table = {
944
949
  false => 0,
945
950
  :error => 1,
946
- "%%" => 2,
947
- "%{" => 3,
948
- :C_DECLARATION => 4,
949
- "%}" => 5,
950
- "%require" => 6,
951
+ :C_DECLARATION => 2,
952
+ :CHARACTER => 3,
953
+ :IDENT_COLON => 4,
954
+ :IDENTIFIER => 5,
955
+ :INTEGER => 6,
951
956
  :STRING => 7,
952
- "%expect" => 8,
953
- :INTEGER => 9,
954
- "%define" => 10,
955
- "%param" => 11,
956
- "%lex-param" => 12,
957
- "%parse-param" => 13,
958
- "%initial-action" => 14,
959
- "{" => 15,
960
- "}" => 16,
961
- ";" => 17,
962
- "%union" => 18,
963
- "%destructor" => 19,
964
- "%printer" => 20,
965
- "%error-token" => 21,
966
- "%token" => 22,
967
- "%type" => 23,
968
- "%left" => 24,
969
- "%right" => 25,
970
- "%precedence" => 26,
971
- "%nonassoc" => 27,
972
- :TAG => 28,
973
- :IDENTIFIER => 29,
974
- :CHARACTER => 30,
975
- ":" => 31,
976
- "|" => 32,
977
- "%prec" => 33,
978
- "[" => 34,
979
- "]" => 35,
980
- :IDENT_COLON => 36,
957
+ :TAG => 8,
958
+ "%%" => 9,
959
+ "%{" => 10,
960
+ "%}" => 11,
961
+ "%require" => 12,
962
+ "%expect" => 13,
963
+ "%define" => 14,
964
+ "%param" => 15,
965
+ "%lex-param" => 16,
966
+ "%parse-param" => 17,
967
+ "%initial-action" => 18,
968
+ "{" => 19,
969
+ "}" => 20,
970
+ ";" => 21,
971
+ "%union" => 22,
972
+ "%destructor" => 23,
973
+ "%printer" => 24,
974
+ "%error-token" => 25,
975
+ "%token" => 26,
976
+ "%type" => 27,
977
+ "%left" => 28,
978
+ "%right" => 29,
979
+ "%precedence" => 30,
980
+ "%nonassoc" => 31,
981
+ ":" => 32,
982
+ "|" => 33,
983
+ "%prec" => 34,
984
+ "[" => 35,
985
+ "]" => 36,
981
986
  "{...}" => 37 }
982
987
 
983
988
  racc_nt_base = 38
@@ -1004,14 +1009,18 @@ Ractor.make_shareable(Racc_arg) if defined?(Ractor)
1004
1009
  Racc_token_to_s_table = [
1005
1010
  "$end",
1006
1011
  "error",
1012
+ "C_DECLARATION",
1013
+ "CHARACTER",
1014
+ "IDENT_COLON",
1015
+ "IDENTIFIER",
1016
+ "INTEGER",
1017
+ "STRING",
1018
+ "TAG",
1007
1019
  "\"%%\"",
1008
1020
  "\"%{\"",
1009
- "C_DECLARATION",
1010
1021
  "\"%}\"",
1011
1022
  "\"%require\"",
1012
- "STRING",
1013
1023
  "\"%expect\"",
1014
- "INTEGER",
1015
1024
  "\"%define\"",
1016
1025
  "\"%param\"",
1017
1026
  "\"%lex-param\"",
@@ -1030,15 +1039,11 @@ Racc_token_to_s_table = [
1030
1039
  "\"%right\"",
1031
1040
  "\"%precedence\"",
1032
1041
  "\"%nonassoc\"",
1033
- "TAG",
1034
- "IDENTIFIER",
1035
- "CHARACTER",
1036
1042
  "\":\"",
1037
1043
  "\"|\"",
1038
1044
  "\"%prec\"",
1039
1045
  "\"[\"",
1040
1046
  "\"]\"",
1041
- "IDENT_COLON",
1042
1047
  "\"{...}\"",
1043
1048
  "$start",
1044
1049
  "input",
@@ -1109,7 +1114,7 @@ Racc_debug_parser = false
1109
1114
 
1110
1115
  # reduce 3 omitted
1111
1116
 
1112
- module_eval(<<'.,.,', 'parser.y', 9)
1117
+ module_eval(<<'.,.,', 'parser.y', 10)
1113
1118
  def _reduce_4(val, _values, result)
1114
1119
  @lexer.status = :c_declaration
1115
1120
  @lexer.end_symbol = '%}'
@@ -1119,7 +1124,7 @@ module_eval(<<'.,.,', 'parser.y', 9)
1119
1124
  end
1120
1125
  .,.,
1121
1126
 
1122
- module_eval(<<'.,.,', 'parser.y', 15)
1127
+ module_eval(<<'.,.,', 'parser.y', 16)
1123
1128
  def _reduce_5(val, _values, result)
1124
1129
  @lexer.status = :initial
1125
1130
  @lexer.end_symbol = nil
@@ -1128,7 +1133,7 @@ module_eval(<<'.,.,', 'parser.y', 15)
1128
1133
  end
1129
1134
  .,.,
1130
1135
 
1131
- module_eval(<<'.,.,', 'parser.y', 20)
1136
+ module_eval(<<'.,.,', 'parser.y', 21)
1132
1137
  def _reduce_6(val, _values, result)
1133
1138
  @grammar.prologue = val[2].s_value
1134
1139
 
@@ -1138,7 +1143,7 @@ module_eval(<<'.,.,', 'parser.y', 20)
1138
1143
 
1139
1144
  # reduce 7 omitted
1140
1145
 
1141
- module_eval(<<'.,.,', 'parser.y', 24)
1146
+ module_eval(<<'.,.,', 'parser.y', 25)
1142
1147
  def _reduce_8(val, _values, result)
1143
1148
  result = ""
1144
1149
  result
@@ -1149,7 +1154,7 @@ module_eval(<<'.,.,', 'parser.y', 24)
1149
1154
 
1150
1155
  # reduce 10 omitted
1151
1156
 
1152
- module_eval(<<'.,.,', 'parser.y', 28)
1157
+ module_eval(<<'.,.,', 'parser.y', 29)
1153
1158
  def _reduce_11(val, _values, result)
1154
1159
  @grammar.expect = val[1]
1155
1160
  result
@@ -1162,7 +1167,7 @@ module_eval(<<'.,.,', 'parser.y', 28)
1162
1167
 
1163
1168
  # reduce 14 omitted
1164
1169
 
1165
- module_eval(<<'.,.,', 'parser.y', 34)
1170
+ module_eval(<<'.,.,', 'parser.y', 35)
1166
1171
  def _reduce_15(val, _values, result)
1167
1172
  val[1].each {|token|
1168
1173
  token.references = []
@@ -1173,7 +1178,7 @@ module_eval(<<'.,.,', 'parser.y', 34)
1173
1178
  end
1174
1179
  .,.,
1175
1180
 
1176
- module_eval(<<'.,.,', 'parser.y', 41)
1181
+ module_eval(<<'.,.,', 'parser.y', 42)
1177
1182
  def _reduce_16(val, _values, result)
1178
1183
  val[1].each {|token|
1179
1184
  token.references = []
@@ -1184,7 +1189,7 @@ module_eval(<<'.,.,', 'parser.y', 41)
1184
1189
  end
1185
1190
  .,.,
1186
1191
 
1187
- module_eval(<<'.,.,', 'parser.y', 48)
1192
+ module_eval(<<'.,.,', 'parser.y', 49)
1188
1193
  def _reduce_17(val, _values, result)
1189
1194
  @lexer.status = :c_declaration
1190
1195
  @lexer.end_symbol = '}'
@@ -1193,7 +1198,7 @@ module_eval(<<'.,.,', 'parser.y', 48)
1193
1198
  end
1194
1199
  .,.,
1195
1200
 
1196
- module_eval(<<'.,.,', 'parser.y', 53)
1201
+ module_eval(<<'.,.,', 'parser.y', 54)
1197
1202
  def _reduce_18(val, _values, result)
1198
1203
  @lexer.status = :initial
1199
1204
  @lexer.end_symbol = nil
@@ -1202,7 +1207,7 @@ module_eval(<<'.,.,', 'parser.y', 53)
1202
1207
  end
1203
1208
  .,.,
1204
1209
 
1205
- module_eval(<<'.,.,', 'parser.y', 58)
1210
+ module_eval(<<'.,.,', 'parser.y', 59)
1206
1211
  def _reduce_19(val, _values, result)
1207
1212
  @grammar.initial_action = @grammar.build_code(:initial_action, val[3])
1208
1213
 
@@ -1212,7 +1217,7 @@ module_eval(<<'.,.,', 'parser.y', 58)
1212
1217
 
1213
1218
  # reduce 20 omitted
1214
1219
 
1215
- module_eval(<<'.,.,', 'parser.y', 64)
1220
+ module_eval(<<'.,.,', 'parser.y', 65)
1216
1221
  def _reduce_21(val, _values, result)
1217
1222
  @lexer.status = :c_declaration
1218
1223
  @lexer.end_symbol = '}'
@@ -1221,7 +1226,7 @@ module_eval(<<'.,.,', 'parser.y', 64)
1221
1226
  end
1222
1227
  .,.,
1223
1228
 
1224
- module_eval(<<'.,.,', 'parser.y', 69)
1229
+ module_eval(<<'.,.,', 'parser.y', 70)
1225
1230
  def _reduce_22(val, _values, result)
1226
1231
  @lexer.status = :initial
1227
1232
  @lexer.end_symbol = nil
@@ -1230,7 +1235,7 @@ module_eval(<<'.,.,', 'parser.y', 69)
1230
1235
  end
1231
1236
  .,.,
1232
1237
 
1233
- module_eval(<<'.,.,', 'parser.y', 74)
1238
+ module_eval(<<'.,.,', 'parser.y', 75)
1234
1239
  def _reduce_23(val, _values, result)
1235
1240
  @grammar.set_union(@grammar.build_code(:union, val[3]), val[3].line)
1236
1241
 
@@ -1240,7 +1245,7 @@ module_eval(<<'.,.,', 'parser.y', 74)
1240
1245
 
1241
1246
  # reduce 24 omitted
1242
1247
 
1243
- module_eval(<<'.,.,', 'parser.y', 79)
1248
+ module_eval(<<'.,.,', 'parser.y', 80)
1244
1249
  def _reduce_25(val, _values, result)
1245
1250
  @lexer.status = :c_declaration
1246
1251
  @lexer.end_symbol = '}'
@@ -1249,7 +1254,7 @@ module_eval(<<'.,.,', 'parser.y', 79)
1249
1254
  end
1250
1255
  .,.,
1251
1256
 
1252
- module_eval(<<'.,.,', 'parser.y', 84)
1257
+ module_eval(<<'.,.,', 'parser.y', 85)
1253
1258
  def _reduce_26(val, _values, result)
1254
1259
  @lexer.status = :initial
1255
1260
  @lexer.end_symbol = nil
@@ -1260,7 +1265,7 @@ module_eval(<<'.,.,', 'parser.y', 84)
1260
1265
 
1261
1266
  # reduce 27 omitted
1262
1267
 
1263
- module_eval(<<'.,.,', 'parser.y', 90)
1268
+ module_eval(<<'.,.,', 'parser.y', 91)
1264
1269
  def _reduce_28(val, _values, result)
1265
1270
  @lexer.status = :c_declaration
1266
1271
  @lexer.end_symbol = '}'
@@ -1269,7 +1274,7 @@ module_eval(<<'.,.,', 'parser.y', 90)
1269
1274
  end
1270
1275
  .,.,
1271
1276
 
1272
- module_eval(<<'.,.,', 'parser.y', 95)
1277
+ module_eval(<<'.,.,', 'parser.y', 96)
1273
1278
  def _reduce_29(val, _values, result)
1274
1279
  @lexer.status = :initial
1275
1280
  @lexer.end_symbol = nil
@@ -1278,7 +1283,7 @@ module_eval(<<'.,.,', 'parser.y', 95)
1278
1283
  end
1279
1284
  .,.,
1280
1285
 
1281
- module_eval(<<'.,.,', 'parser.y', 100)
1286
+ module_eval(<<'.,.,', 'parser.y', 101)
1282
1287
  def _reduce_30(val, _values, result)
1283
1288
  @grammar.add_printer(ident_or_tags: val[6], code: @grammar.build_code(:printer, val[3]), lineno: val[3].line)
1284
1289
 
@@ -1286,7 +1291,7 @@ module_eval(<<'.,.,', 'parser.y', 100)
1286
1291
  end
1287
1292
  .,.,
1288
1293
 
1289
- module_eval(<<'.,.,', 'parser.y', 104)
1294
+ module_eval(<<'.,.,', 'parser.y', 105)
1290
1295
  def _reduce_31(val, _values, result)
1291
1296
  @lexer.status = :c_declaration
1292
1297
  @lexer.end_symbol = '}'
@@ -1295,7 +1300,7 @@ module_eval(<<'.,.,', 'parser.y', 104)
1295
1300
  end
1296
1301
  .,.,
1297
1302
 
1298
- module_eval(<<'.,.,', 'parser.y', 109)
1303
+ module_eval(<<'.,.,', 'parser.y', 110)
1299
1304
  def _reduce_32(val, _values, result)
1300
1305
  @lexer.status = :initial
1301
1306
  @lexer.end_symbol = nil
@@ -1304,7 +1309,7 @@ module_eval(<<'.,.,', 'parser.y', 109)
1304
1309
  end
1305
1310
  .,.,
1306
1311
 
1307
- module_eval(<<'.,.,', 'parser.y', 114)
1312
+ module_eval(<<'.,.,', 'parser.y', 115)
1308
1313
  def _reduce_33(val, _values, result)
1309
1314
  @grammar.add_error_token(ident_or_tags: val[6], code: @grammar.build_code(:error_token, val[3]), lineno: val[3].line)
1310
1315
 
@@ -1314,7 +1319,7 @@ module_eval(<<'.,.,', 'parser.y', 114)
1314
1319
 
1315
1320
  # reduce 34 omitted
1316
1321
 
1317
- module_eval(<<'.,.,', 'parser.y', 120)
1322
+ module_eval(<<'.,.,', 'parser.y', 121)
1318
1323
  def _reduce_35(val, _values, result)
1319
1324
  val[1].each {|hash|
1320
1325
  hash[:tokens].each {|id|
@@ -1326,7 +1331,7 @@ module_eval(<<'.,.,', 'parser.y', 120)
1326
1331
  end
1327
1332
  .,.,
1328
1333
 
1329
- module_eval(<<'.,.,', 'parser.y', 128)
1334
+ module_eval(<<'.,.,', 'parser.y', 129)
1330
1335
  def _reduce_36(val, _values, result)
1331
1336
  val[1].each {|hash|
1332
1337
  hash[:tokens].each {|id|
@@ -1340,7 +1345,7 @@ module_eval(<<'.,.,', 'parser.y', 128)
1340
1345
  end
1341
1346
  .,.,
1342
1347
 
1343
- module_eval(<<'.,.,', 'parser.y', 138)
1348
+ module_eval(<<'.,.,', 'parser.y', 139)
1344
1349
  def _reduce_37(val, _values, result)
1345
1350
  val[1].each {|hash|
1346
1351
  hash[:tokens].each {|id|
@@ -1354,7 +1359,7 @@ module_eval(<<'.,.,', 'parser.y', 138)
1354
1359
  end
1355
1360
  .,.,
1356
1361
 
1357
- module_eval(<<'.,.,', 'parser.y', 148)
1362
+ module_eval(<<'.,.,', 'parser.y', 149)
1358
1363
  def _reduce_38(val, _values, result)
1359
1364
  val[1].each {|hash|
1360
1365
  hash[:tokens].each {|id|
@@ -1368,7 +1373,7 @@ module_eval(<<'.,.,', 'parser.y', 148)
1368
1373
  end
1369
1374
  .,.,
1370
1375
 
1371
- module_eval(<<'.,.,', 'parser.y', 158)
1376
+ module_eval(<<'.,.,', 'parser.y', 159)
1372
1377
  def _reduce_39(val, _values, result)
1373
1378
  val[1].each {|hash|
1374
1379
  hash[:tokens].each {|id|
@@ -1382,7 +1387,7 @@ module_eval(<<'.,.,', 'parser.y', 158)
1382
1387
  end
1383
1388
  .,.,
1384
1389
 
1385
- module_eval(<<'.,.,', 'parser.y', 169)
1390
+ module_eval(<<'.,.,', 'parser.y', 170)
1386
1391
  def _reduce_40(val, _values, result)
1387
1392
  val[0].each {|token_declaration|
1388
1393
  @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: nil, replace: true)
@@ -1392,7 +1397,7 @@ module_eval(<<'.,.,', 'parser.y', 169)
1392
1397
  end
1393
1398
  .,.,
1394
1399
 
1395
- module_eval(<<'.,.,', 'parser.y', 175)
1400
+ module_eval(<<'.,.,', 'parser.y', 176)
1396
1401
  def _reduce_41(val, _values, result)
1397
1402
  val[1].each {|token_declaration|
1398
1403
  @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[0], replace: true)
@@ -1402,7 +1407,7 @@ module_eval(<<'.,.,', 'parser.y', 175)
1402
1407
  end
1403
1408
  .,.,
1404
1409
 
1405
- module_eval(<<'.,.,', 'parser.y', 181)
1410
+ module_eval(<<'.,.,', 'parser.y', 182)
1406
1411
  def _reduce_42(val, _values, result)
1407
1412
  val[2].each {|token_declaration|
1408
1413
  @grammar.add_term(id: token_declaration[0], alias_name: token_declaration[2], token_id: token_declaration[1], tag: val[1], replace: true)
@@ -1412,21 +1417,21 @@ module_eval(<<'.,.,', 'parser.y', 181)
1412
1417
  end
1413
1418
  .,.,
1414
1419
 
1415
- module_eval(<<'.,.,', 'parser.y', 186)
1420
+ module_eval(<<'.,.,', 'parser.y', 187)
1416
1421
  def _reduce_43(val, _values, result)
1417
1422
  result = [val[0]]
1418
1423
  result
1419
1424
  end
1420
1425
  .,.,
1421
1426
 
1422
- module_eval(<<'.,.,', 'parser.y', 187)
1427
+ module_eval(<<'.,.,', 'parser.y', 188)
1423
1428
  def _reduce_44(val, _values, result)
1424
1429
  result = val[0].append(val[1])
1425
1430
  result
1426
1431
  end
1427
1432
  .,.,
1428
1433
 
1429
- module_eval(<<'.,.,', 'parser.y', 189)
1434
+ module_eval(<<'.,.,', 'parser.y', 190)
1430
1435
  def _reduce_45(val, _values, result)
1431
1436
  result = val
1432
1437
  result
@@ -1441,7 +1446,7 @@ module_eval(<<'.,.,', 'parser.y', 189)
1441
1446
 
1442
1447
  # reduce 49 omitted
1443
1448
 
1444
- module_eval(<<'.,.,', 'parser.y', 199)
1449
+ module_eval(<<'.,.,', 'parser.y', 200)
1445
1450
  def _reduce_50(val, _values, result)
1446
1451
  result = [{tag: nil, tokens: val[0]}]
1447
1452
 
@@ -1449,7 +1454,7 @@ module_eval(<<'.,.,', 'parser.y', 199)
1449
1454
  end
1450
1455
  .,.,
1451
1456
 
1452
- module_eval(<<'.,.,', 'parser.y', 203)
1457
+ module_eval(<<'.,.,', 'parser.y', 204)
1453
1458
  def _reduce_51(val, _values, result)
1454
1459
  result = [{tag: val[0], tokens: val[1]}]
1455
1460
 
@@ -1457,7 +1462,7 @@ module_eval(<<'.,.,', 'parser.y', 203)
1457
1462
  end
1458
1463
  .,.,
1459
1464
 
1460
- module_eval(<<'.,.,', 'parser.y', 207)
1465
+ module_eval(<<'.,.,', 'parser.y', 208)
1461
1466
  def _reduce_52(val, _values, result)
1462
1467
  result = val[0].append({tag: val[1], tokens: val[2]})
1463
1468
 
@@ -1465,14 +1470,14 @@ module_eval(<<'.,.,', 'parser.y', 207)
1465
1470
  end
1466
1471
  .,.,
1467
1472
 
1468
- module_eval(<<'.,.,', 'parser.y', 210)
1473
+ module_eval(<<'.,.,', 'parser.y', 211)
1469
1474
  def _reduce_53(val, _values, result)
1470
1475
  result = [val[0]]
1471
1476
  result
1472
1477
  end
1473
1478
  .,.,
1474
1479
 
1475
- module_eval(<<'.,.,', 'parser.y', 211)
1480
+ module_eval(<<'.,.,', 'parser.y', 212)
1476
1481
  def _reduce_54(val, _values, result)
1477
1482
  result = val[0].append(val[1])
1478
1483
  result
@@ -1483,7 +1488,7 @@ module_eval(<<'.,.,', 'parser.y', 211)
1483
1488
 
1484
1489
  # reduce 56 omitted
1485
1490
 
1486
- module_eval(<<'.,.,', 'parser.y', 218)
1491
+ module_eval(<<'.,.,', 'parser.y', 219)
1487
1492
  def _reduce_57(val, _values, result)
1488
1493
  @lexer.status = :c_declaration
1489
1494
  @lexer.end_symbol = '}'
@@ -1492,7 +1497,7 @@ module_eval(<<'.,.,', 'parser.y', 218)
1492
1497
  end
1493
1498
  .,.,
1494
1499
 
1495
- module_eval(<<'.,.,', 'parser.y', 223)
1500
+ module_eval(<<'.,.,', 'parser.y', 224)
1496
1501
  def _reduce_58(val, _values, result)
1497
1502
  @lexer.status = :initial
1498
1503
  @lexer.end_symbol = nil
@@ -1501,7 +1506,7 @@ module_eval(<<'.,.,', 'parser.y', 223)
1501
1506
  end
1502
1507
  .,.,
1503
1508
 
1504
- module_eval(<<'.,.,', 'parser.y', 228)
1509
+ module_eval(<<'.,.,', 'parser.y', 229)
1505
1510
  def _reduce_59(val, _values, result)
1506
1511
  result = val[0].append(val[3])
1507
1512
 
@@ -1509,7 +1514,7 @@ module_eval(<<'.,.,', 'parser.y', 228)
1509
1514
  end
1510
1515
  .,.,
1511
1516
 
1512
- module_eval(<<'.,.,', 'parser.y', 232)
1517
+ module_eval(<<'.,.,', 'parser.y', 233)
1513
1518
  def _reduce_60(val, _values, result)
1514
1519
  @lexer.status = :c_declaration
1515
1520
  @lexer.end_symbol = '}'
@@ -1518,7 +1523,7 @@ module_eval(<<'.,.,', 'parser.y', 232)
1518
1523
  end
1519
1524
  .,.,
1520
1525
 
1521
- module_eval(<<'.,.,', 'parser.y', 237)
1526
+ module_eval(<<'.,.,', 'parser.y', 238)
1522
1527
  def _reduce_61(val, _values, result)
1523
1528
  @lexer.status = :initial
1524
1529
  @lexer.end_symbol = nil
@@ -1527,7 +1532,7 @@ module_eval(<<'.,.,', 'parser.y', 237)
1527
1532
  end
1528
1533
  .,.,
1529
1534
 
1530
- module_eval(<<'.,.,', 'parser.y', 242)
1535
+ module_eval(<<'.,.,', 'parser.y', 243)
1531
1536
  def _reduce_62(val, _values, result)
1532
1537
  result = [val[2]]
1533
1538
 
@@ -1535,7 +1540,7 @@ module_eval(<<'.,.,', 'parser.y', 242)
1535
1540
  end
1536
1541
  .,.,
1537
1542
 
1538
- module_eval(<<'.,.,', 'parser.y', 247)
1543
+ module_eval(<<'.,.,', 'parser.y', 248)
1539
1544
  def _reduce_63(val, _values, result)
1540
1545
  result = [{tag: nil, tokens: val[0]}]
1541
1546
 
@@ -1543,7 +1548,7 @@ module_eval(<<'.,.,', 'parser.y', 247)
1543
1548
  end
1544
1549
  .,.,
1545
1550
 
1546
- module_eval(<<'.,.,', 'parser.y', 251)
1551
+ module_eval(<<'.,.,', 'parser.y', 252)
1547
1552
  def _reduce_64(val, _values, result)
1548
1553
  result = [{tag: val[0], tokens: val[1]}]
1549
1554
 
@@ -1551,7 +1556,7 @@ module_eval(<<'.,.,', 'parser.y', 251)
1551
1556
  end
1552
1557
  .,.,
1553
1558
 
1554
- module_eval(<<'.,.,', 'parser.y', 255)
1559
+ module_eval(<<'.,.,', 'parser.y', 256)
1555
1560
  def _reduce_65(val, _values, result)
1556
1561
  result = val[0].append({tag: nil, tokens: val[1]})
1557
1562
 
@@ -1559,14 +1564,14 @@ module_eval(<<'.,.,', 'parser.y', 255)
1559
1564
  end
1560
1565
  .,.,
1561
1566
 
1562
- module_eval(<<'.,.,', 'parser.y', 258)
1567
+ module_eval(<<'.,.,', 'parser.y', 259)
1563
1568
  def _reduce_66(val, _values, result)
1564
1569
  result = [val[0]]
1565
1570
  result
1566
1571
  end
1567
1572
  .,.,
1568
1573
 
1569
- module_eval(<<'.,.,', 'parser.y', 259)
1574
+ module_eval(<<'.,.,', 'parser.y', 260)
1570
1575
  def _reduce_67(val, _values, result)
1571
1576
  result = val[0].append(val[1])
1572
1577
  result
@@ -1575,14 +1580,14 @@ module_eval(<<'.,.,', 'parser.y', 259)
1575
1580
 
1576
1581
  # reduce 68 omitted
1577
1582
 
1578
- module_eval(<<'.,.,', 'parser.y', 263)
1583
+ module_eval(<<'.,.,', 'parser.y', 264)
1579
1584
  def _reduce_69(val, _values, result)
1580
1585
  raise "Ident after %prec" if @prec_seen
1581
1586
  result
1582
1587
  end
1583
1588
  .,.,
1584
1589
 
1585
- module_eval(<<'.,.,', 'parser.y', 264)
1590
+ module_eval(<<'.,.,', 'parser.y', 265)
1586
1591
  def _reduce_70(val, _values, result)
1587
1592
  raise "Char after %prec" if @prec_seen
1588
1593
  result
@@ -1597,7 +1602,7 @@ module_eval(<<'.,.,', 'parser.y', 264)
1597
1602
 
1598
1603
  # reduce 74 omitted
1599
1604
 
1600
- module_eval(<<'.,.,', 'parser.y', 274)
1605
+ module_eval(<<'.,.,', 'parser.y', 275)
1601
1606
  def _reduce_75(val, _values, result)
1602
1607
  lhs = val[0]
1603
1608
  lhs.alias = val[1]
@@ -1609,7 +1614,7 @@ module_eval(<<'.,.,', 'parser.y', 274)
1609
1614
  end
1610
1615
  .,.,
1611
1616
 
1612
- module_eval(<<'.,.,', 'parser.y', 283)
1617
+ module_eval(<<'.,.,', 'parser.y', 284)
1613
1618
  def _reduce_76(val, _values, result)
1614
1619
  result = [{rhs: val[0], lineno: val[0].first&.line || @lexer.line - 1}]
1615
1620
 
@@ -1617,7 +1622,7 @@ module_eval(<<'.,.,', 'parser.y', 283)
1617
1622
  end
1618
1623
  .,.,
1619
1624
 
1620
- module_eval(<<'.,.,', 'parser.y', 287)
1625
+ module_eval(<<'.,.,', 'parser.y', 288)
1621
1626
  def _reduce_77(val, _values, result)
1622
1627
  result = val[0].append({rhs: val[2], lineno: val[2].first&.line || @lexer.line - 1})
1623
1628
 
@@ -1627,7 +1632,7 @@ module_eval(<<'.,.,', 'parser.y', 287)
1627
1632
 
1628
1633
  # reduce 78 omitted
1629
1634
 
1630
- module_eval(<<'.,.,', 'parser.y', 293)
1635
+ module_eval(<<'.,.,', 'parser.y', 294)
1631
1636
  def _reduce_79(val, _values, result)
1632
1637
  result = []
1633
1638
  @prec_seen = false
@@ -1637,17 +1642,17 @@ module_eval(<<'.,.,', 'parser.y', 293)
1637
1642
  end
1638
1643
  .,.,
1639
1644
 
1640
- module_eval(<<'.,.,', 'parser.y', 299)
1645
+ module_eval(<<'.,.,', 'parser.y', 300)
1641
1646
  def _reduce_80(val, _values, result)
1642
1647
  token = val[1]
1643
- val[1].alias = val[2]
1648
+ token.alias = val[2]
1644
1649
  result = val[0].append(token)
1645
1650
 
1646
1651
  result
1647
1652
  end
1648
1653
  .,.,
1649
1654
 
1650
- module_eval(<<'.,.,', 'parser.y', 305)
1655
+ module_eval(<<'.,.,', 'parser.y', 306)
1651
1656
  def _reduce_81(val, _values, result)
1652
1657
  if @prec_seen
1653
1658
  raise "Multiple User_code after %prec" if @code_after_prec
@@ -1660,7 +1665,7 @@ module_eval(<<'.,.,', 'parser.y', 305)
1660
1665
  end
1661
1666
  .,.,
1662
1667
 
1663
- module_eval(<<'.,.,', 'parser.y', 314)
1668
+ module_eval(<<'.,.,', 'parser.y', 315)
1664
1669
  def _reduce_82(val, _values, result)
1665
1670
  @lexer.status = :initial
1666
1671
  @lexer.end_symbol = nil
@@ -1669,7 +1674,7 @@ module_eval(<<'.,.,', 'parser.y', 314)
1669
1674
  end
1670
1675
  .,.,
1671
1676
 
1672
- module_eval(<<'.,.,', 'parser.y', 319)
1677
+ module_eval(<<'.,.,', 'parser.y', 320)
1673
1678
  def _reduce_83(val, _values, result)
1674
1679
  token = val[3]
1675
1680
  token.alias = val[6]
@@ -1679,7 +1684,7 @@ module_eval(<<'.,.,', 'parser.y', 319)
1679
1684
  end
1680
1685
  .,.,
1681
1686
 
1682
- module_eval(<<'.,.,', 'parser.y', 325)
1687
+ module_eval(<<'.,.,', 'parser.y', 326)
1683
1688
  def _reduce_84(val, _values, result)
1684
1689
  if @prec_seen
1685
1690
  raise "Multiple User_code after %prec" if @code_after_prec
@@ -1692,7 +1697,7 @@ module_eval(<<'.,.,', 'parser.y', 325)
1692
1697
  end
1693
1698
  .,.,
1694
1699
 
1695
- module_eval(<<'.,.,', 'parser.y', 334)
1700
+ module_eval(<<'.,.,', 'parser.y', 335)
1696
1701
  def _reduce_85(val, _values, result)
1697
1702
  @lexer.status = :initial
1698
1703
  @lexer.end_symbol = nil
@@ -1701,7 +1706,7 @@ module_eval(<<'.,.,', 'parser.y', 334)
1701
1706
  end
1702
1707
  .,.,
1703
1708
 
1704
- module_eval(<<'.,.,', 'parser.y', 339)
1709
+ module_eval(<<'.,.,', 'parser.y', 340)
1705
1710
  def _reduce_86(val, _values, result)
1706
1711
  token = val[2]
1707
1712
  token.alias = val[5]
@@ -1711,7 +1716,7 @@ module_eval(<<'.,.,', 'parser.y', 339)
1711
1716
  end
1712
1717
  .,.,
1713
1718
 
1714
- module_eval(<<'.,.,', 'parser.y', 345)
1719
+ module_eval(<<'.,.,', 'parser.y', 346)
1715
1720
  def _reduce_87(val, _values, result)
1716
1721
  sym = @grammar.find_symbol_by_id!(val[2])
1717
1722
  result = val[0].append(sym)
@@ -1723,7 +1728,7 @@ module_eval(<<'.,.,', 'parser.y', 345)
1723
1728
 
1724
1729
  # reduce 88 omitted
1725
1730
 
1726
- module_eval(<<'.,.,', 'parser.y', 351)
1731
+ module_eval(<<'.,.,', 'parser.y', 352)
1727
1732
  def _reduce_89(val, _values, result)
1728
1733
  result = val[1].s_value
1729
1734
  result
@@ -1734,7 +1739,7 @@ module_eval(<<'.,.,', 'parser.y', 351)
1734
1739
 
1735
1740
  # reduce 91 omitted
1736
1741
 
1737
- module_eval(<<'.,.,', 'parser.y', 358)
1742
+ module_eval(<<'.,.,', 'parser.y', 359)
1738
1743
  def _reduce_92(val, _values, result)
1739
1744
  @lexer.status = :c_declaration
1740
1745
  @lexer.end_symbol = '\Z'
@@ -1744,7 +1749,7 @@ module_eval(<<'.,.,', 'parser.y', 358)
1744
1749
  end
1745
1750
  .,.,
1746
1751
 
1747
- module_eval(<<'.,.,', 'parser.y', 364)
1752
+ module_eval(<<'.,.,', 'parser.y', 365)
1748
1753
  def _reduce_93(val, _values, result)
1749
1754
  @lexer.status = :initial
1750
1755
  @lexer.end_symbol = nil
@@ -1764,14 +1769,14 @@ module_eval(<<'.,.,', 'parser.y', 364)
1764
1769
 
1765
1770
  # reduce 98 omitted
1766
1771
 
1767
- module_eval(<<'.,.,', 'parser.y', 376)
1772
+ module_eval(<<'.,.,', 'parser.y', 377)
1768
1773
  def _reduce_99(val, _values, result)
1769
1774
  result = [val[0]]
1770
1775
  result
1771
1776
  end
1772
1777
  .,.,
1773
1778
 
1774
- module_eval(<<'.,.,', 'parser.y', 377)
1779
+ module_eval(<<'.,.,', 'parser.y', 378)
1775
1780
  def _reduce_100(val, _values, result)
1776
1781
  result = val[0].append(val[1])
1777
1782
  result
@@ -1782,7 +1787,7 @@ module_eval(<<'.,.,', 'parser.y', 377)
1782
1787
 
1783
1788
  # reduce 102 omitted
1784
1789
 
1785
- module_eval(<<'.,.,', 'parser.y', 382)
1790
+ module_eval(<<'.,.,', 'parser.y', 383)
1786
1791
  def _reduce_103(val, _values, result)
1787
1792
  result = Lrama::Lexer::Token.new(type: Lrama::Lexer::Token::Ident, s_value: val[0])
1788
1793
  result
data/lib/lrama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lrama
2
- VERSION = "0.5.7".freeze
2
+ VERSION = "0.5.8".freeze
3
3
  end
data/parser.y CHANGED
@@ -1,4 +1,5 @@
1
1
  class Lrama::Parser
2
+ token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG
2
3
  rule
3
4
  input: prologue_declarations bison_declarations "%%" grammar epilogue_opt
4
5
 
@@ -298,7 +299,7 @@ rule
298
299
  | rhs symbol named_ref_opt
299
300
  {
300
301
  token = val[1]
301
- val[1].alias = val[2]
302
+ token.alias = val[2]
302
303
  result = val[0].append(token)
303
304
  }
304
305
  | rhs "{"
@@ -387,8 +388,9 @@ end
387
388
 
388
389
  include Lrama::Report::Duration
389
390
 
390
- def initialize(text)
391
+ def initialize(text, path)
391
392
  @text = text
393
+ @path = path
392
394
  end
393
395
 
394
396
  def parse
@@ -411,6 +413,10 @@ def next_token
411
413
  end
412
414
 
413
415
  def on_error(error_token_id, error_value, value_stack)
414
- raise ParseError, sprintf("\n%d:%d: parse error on value %s (%s)",
415
- @lexer.line, @lexer.column, error_value.inspect, token_to_str(error_token_id) || '?')
416
+ source = @text.split("\n")[error_value.line - 1]
417
+ raise ParseError, <<~ERROR
418
+ #{@path}:#{@lexer.line}:#{@lexer.column}: parse error on value #{error_value.inspect} (#{token_to_str(error_token_id) || '?'})
419
+ #{source}
420
+ #{' ' * @lexer.column}^
421
+ ERROR
416
422
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lrama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email: