lrama 0.5.9 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yaml +25 -0
  3. data/.gitignore +7 -4
  4. data/Gemfile +9 -5
  5. data/Rakefile +13 -0
  6. data/Steepfile +13 -11
  7. data/lib/lrama/context.rb +1 -3
  8. data/lib/lrama/counterexamples/path.rb +0 -46
  9. data/lib/lrama/counterexamples/production_path.rb +17 -0
  10. data/lib/lrama/counterexamples/start_path.rb +21 -0
  11. data/lib/lrama/counterexamples/transition_path.rb +17 -0
  12. data/lib/lrama/counterexamples.rb +3 -0
  13. data/lib/lrama/grammar/code/initial_action_code.rb +28 -0
  14. data/lib/lrama/grammar/code/no_reference_code.rb +24 -0
  15. data/lib/lrama/grammar/code/printer_code.rb +34 -0
  16. data/lib/lrama/grammar/code/rule_action.rb +62 -0
  17. data/lib/lrama/grammar/code.rb +9 -93
  18. data/lib/lrama/grammar/counter.rb +15 -0
  19. data/lib/lrama/grammar/error_token.rb +3 -3
  20. data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +36 -0
  21. data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +28 -0
  22. data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +28 -0
  23. data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +28 -0
  24. data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +39 -0
  25. data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +34 -0
  26. data/lib/lrama/grammar/parameterizing_rules/builder.rb +60 -0
  27. data/lib/lrama/grammar/printer.rb +3 -3
  28. data/lib/lrama/grammar/reference.rb +7 -16
  29. data/lib/lrama/grammar/rule.rb +19 -2
  30. data/lib/lrama/grammar/rule_builder.rb +177 -0
  31. data/lib/lrama/grammar/symbol.rb +16 -2
  32. data/lib/lrama/grammar/type.rb +6 -0
  33. data/lib/lrama/grammar.rb +115 -325
  34. data/lib/lrama/lexer/location.rb +22 -0
  35. data/lib/lrama/lexer/token/parameterizing.rb +18 -3
  36. data/lib/lrama/lexer/token/tag.rb +4 -0
  37. data/lib/lrama/lexer/token/user_code.rb +54 -4
  38. data/lib/lrama/lexer/token.rb +35 -10
  39. data/lib/lrama/lexer.rb +32 -31
  40. data/lib/lrama/options.rb +1 -2
  41. data/lib/lrama/output.rb +2 -2
  42. data/lib/lrama/parser.rb +514 -424
  43. data/lib/lrama/report/profile.rb +1 -12
  44. data/lib/lrama/version.rb +1 -1
  45. data/lib/lrama.rb +0 -1
  46. data/parser.y +111 -52
  47. data/rbs_collection.lock.yaml +6 -8
  48. data/rbs_collection.yaml +1 -0
  49. data/sig/lrama/grammar/code/printer_code.rbs +15 -0
  50. data/sig/lrama/grammar/code.rbs +24 -0
  51. data/sig/lrama/grammar/counter.rbs +11 -0
  52. data/sig/lrama/grammar/error_token.rbs +11 -0
  53. data/sig/lrama/grammar/parameterizing_rules/builder/base.rbs +26 -0
  54. data/sig/lrama/grammar/parameterizing_rules/builder/list.rbs +10 -0
  55. data/sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs +10 -0
  56. data/sig/lrama/grammar/parameterizing_rules/builder/option.rbs +10 -0
  57. data/sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs +11 -0
  58. data/sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs +11 -0
  59. data/sig/lrama/grammar/parameterizing_rules/builder.rbs +23 -0
  60. data/sig/lrama/grammar/precedence.rbs +11 -0
  61. data/sig/lrama/grammar/printer.rbs +11 -0
  62. data/sig/lrama/grammar/reference.rbs +6 -6
  63. data/sig/lrama/grammar/rule.rbs +13 -0
  64. data/sig/lrama/grammar/rule_builder.rbs +42 -0
  65. data/sig/lrama/grammar/symbol.rbs +37 -0
  66. data/sig/lrama/lexer/location.rbs +14 -0
  67. data/sig/lrama/lexer/token/parameterizing.rbs +9 -0
  68. data/sig/lrama/lexer/token/tag.rbs +1 -0
  69. data/sig/lrama/lexer/token/user_code.rbs +8 -1
  70. data/sig/lrama/lexer/token.rbs +9 -4
  71. data/sig/stdlib/strscan/string_scanner.rbs +5 -0
  72. data/template/bison/yacc.c +5 -2
  73. metadata +38 -3
  74. data/lib/lrama/type.rb +0 -4
@@ -1,18 +1,7 @@
1
1
  module Lrama
2
2
  class Report
3
3
  module Profile
4
- # 1. Wrap target method with Profile.report_profile like below:
5
- #
6
- # Lrama::Report::Profile.report_profile { method }
7
- #
8
- # 2. Run lrama command, for example
9
- #
10
- # $ ./exe/lrama --trace=time spec/fixtures/integration/ruby_3_2_0/parse.tmp.y
11
- #
12
- # 3. Generate html file
13
- #
14
- # $ stackprof --d3-flamegraph tmp/stackprof-cpu-myapp.dump > tmp/flamegraph.html
15
- #
4
+ # See "Profiling Lrama" in README.md for how to use.
16
5
  def self.report_profile
17
6
  require "stackprof"
18
7
 
data/lib/lrama/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lrama
2
- VERSION = "0.5.9".freeze
2
+ VERSION = "0.5.11".freeze
3
3
  end
data/lib/lrama.rb CHANGED
@@ -13,6 +13,5 @@ require "lrama/report"
13
13
  require "lrama/state"
14
14
  require "lrama/states"
15
15
  require "lrama/states_reporter"
16
- require "lrama/type"
17
16
  require "lrama/version"
18
17
  require "lrama/warning"
data/parser.y CHANGED
@@ -1,5 +1,5 @@
1
1
  class Lrama::Parser
2
- expect 7
2
+ expect 0
3
3
 
4
4
  token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG
5
5
 
@@ -31,20 +31,17 @@ rule
31
31
  bison_declaration: grammar_declaration
32
32
  | "%expect" INTEGER { @grammar.expect = val[1] }
33
33
  | "%define" variable value
34
- | "%require" STRING
35
34
  | "%param" params
36
35
  | "%lex-param" params
37
36
  {
38
37
  val[1].each {|token|
39
- token.references = []
40
- @grammar.lex_param = @grammar.build_code(:lex_param, token).token_code.s_value
38
+ @grammar.lex_param = Grammar::Code::NoReferenceCode.new(type: :lex_param, token_code: token).token_code.s_value
41
39
  }
42
40
  }
43
41
  | "%parse-param" params
44
42
  {
45
43
  val[1].each {|token|
46
- token.references = []
47
- @grammar.parse_param = @grammar.build_code(:parse_param, token).token_code.s_value
44
+ @grammar.parse_param = Grammar::Code::NoReferenceCode.new(type: :parse_param, token_code: token).token_code.s_value
48
45
  }
49
46
  }
50
47
  | "%code" IDENTIFIER "{"
@@ -69,7 +66,7 @@ rule
69
66
  }
70
67
  "}"
71
68
  {
72
- @grammar.initial_action = @grammar.build_code(:initial_action, val[3])
69
+ @grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[3])
73
70
  }
74
71
  | ";"
75
72
 
@@ -83,7 +80,10 @@ rule
83
80
  }
84
81
  "}"
85
82
  {
86
- @grammar.set_union(@grammar.build_code(:union, val[3]), val[3].line)
83
+ @grammar.set_union(
84
+ Grammar::Code::NoReferenceCode.new(type: :union, token_code: val[3]),
85
+ val[3].line
86
+ )
87
87
  }
88
88
  | symbol_declaration
89
89
  | "%destructor" "{"
@@ -105,7 +105,11 @@ rule
105
105
  }
106
106
  "}" generic_symlist
107
107
  {
108
- @grammar.add_printer(ident_or_tags: val[6], code: @grammar.build_code(:printer, val[3]), lineno: val[3].line)
108
+ @grammar.add_printer(
109
+ ident_or_tags: val[6],
110
+ token_code: val[3],
111
+ lineno: val[3].line
112
+ )
109
113
  }
110
114
  | "%error-token" "{"
111
115
  {
@@ -117,7 +121,11 @@ rule
117
121
  }
118
122
  "}" generic_symlist
119
123
  {
120
- @grammar.add_error_token(ident_or_tags: val[6], code: @grammar.build_code(:error_token, val[3]), lineno: val[3].line)
124
+ @grammar.add_error_token(
125
+ ident_or_tags: val[6],
126
+ token_code: val[3],
127
+ lineno: val[3].line
128
+ )
121
129
  }
122
130
 
123
131
  symbol_declaration: "%token" token_declarations
@@ -252,9 +260,9 @@ rule
252
260
  {
253
261
  result = [{tag: val[0], tokens: val[1]}]
254
262
  }
255
- | token_declarations_for_precedence token_declaration_list_for_precedence
263
+ | token_declarations_for_precedence TAG token_declaration_list_for_precedence
256
264
  {
257
- result = val[0].append({tag: nil, tokens: val[1]})
265
+ result = val[0].append({tag: val[1], tokens: val[2]})
258
266
  }
259
267
 
260
268
  token_declaration_list_for_precedence: token_declaration_for_precedence { result = [val[0]] }
@@ -262,8 +270,8 @@ rule
262
270
 
263
271
  token_declaration_for_precedence: id
264
272
 
265
- id: IDENTIFIER { raise "Ident after %prec" if @prec_seen }
266
- | CHARACTER { raise "Char after %prec" if @prec_seen }
273
+ id: IDENTIFIER { on_action_error("ident after %prec", val[0]) if @prec_seen }
274
+ | CHARACTER { on_action_error("char after %prec", val[0]) if @prec_seen }
267
275
 
268
276
  grammar: rules_or_grammar_declaration
269
277
  | grammar rules_or_grammar_declaration
@@ -275,56 +283,71 @@ rule
275
283
  {
276
284
  lhs = val[0]
277
285
  lhs.alias_name = val[1]
278
- val[3].each {|hash|
279
- @grammar.add_rule(lhs: lhs, rhs: hash[:rhs], lineno: hash[:lineno])
280
- }
286
+ val[3].each do |builder|
287
+ builder.lhs = lhs
288
+ builder.complete_input
289
+ @grammar.add_rule_builder(builder)
290
+ end
281
291
  }
282
292
 
283
293
  rhs_list: rhs
284
294
  {
285
- result = [{rhs: val[0], lineno: val[0].first&.line || @lexer.line - 1}]
295
+ builder = val[0]
296
+ if !builder.line
297
+ builder.line = @lexer.line - 1
298
+ end
299
+ result = [builder]
286
300
  }
287
301
  | rhs_list "|" rhs
288
302
  {
289
- result = val[0].append({rhs: val[2], lineno: val[2].first&.line || @lexer.line - 1})
303
+ builder = val[2]
304
+ if !builder.line
305
+ builder.line = @lexer.line - 1
306
+ end
307
+ result = val[0].append(builder)
290
308
  }
291
309
  | rhs_list ";"
292
310
 
293
311
  rhs: /* empty */
294
312
  {
295
313
  reset_precs
296
- result = []
314
+ result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter)
297
315
  }
298
316
  | "%empty"
299
317
  {
300
318
  reset_precs
301
- result = []
319
+ result = Grammar::RuleBuilder.new(@rule_counter, @midrule_action_counter)
302
320
  }
303
321
  | rhs symbol named_ref_opt
304
322
  {
305
323
  token = val[1]
306
324
  token.alias_name = val[2]
307
- result = val[0].append(token)
325
+ builder = val[0]
326
+ builder.add_rhs(token)
327
+ result = builder
328
+ }
329
+ | rhs IDENTIFIER parameterizing_suffix tag_opt
330
+ {
331
+ token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[2], location: @lexer.location, args: [val[1]])
332
+ builder = val[0]
333
+ builder.add_rhs(token)
334
+ builder.lhs_tag = val[3]
335
+ builder.line = val[1].first_line
336
+ result = builder
337
+ }
338
+ | rhs IDENTIFIER "(" parameterizing_args ")" tag_opt
339
+ {
340
+ token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: val[3])
341
+ builder = val[0]
342
+ builder.add_rhs(token)
343
+ builder.lhs_tag = val[5]
344
+ builder.line = val[1].first_line
345
+ result = builder
308
346
  }
309
- | rhs "?"
310
- {
311
- token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1])
312
- result = val[0].append(token)
313
- }
314
- | rhs "+"
315
- {
316
- token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1])
317
- result = val[0].append(token)
318
- }
319
- | rhs "*"
320
- {
321
- token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1])
322
- result = val[0].append(token)
323
- }
324
347
  | rhs "{"
325
348
  {
326
349
  if @prec_seen
327
- raise "Multiple User_code after %prec" if @code_after_prec
350
+ on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec
328
351
  @code_after_prec = true
329
352
  end
330
353
  begin_c_declaration("}")
@@ -335,17 +358,28 @@ rule
335
358
  }
336
359
  "}" named_ref_opt
337
360
  {
338
- token = val[3]
339
- token.alias_name = val[6]
340
- result = val[0].append(token)
361
+ user_code = val[3]
362
+ user_code.alias_name = val[6]
363
+ builder = val[0]
364
+ builder.user_code = user_code
365
+ result = builder
341
366
  }
342
367
  | rhs "%prec" symbol
343
368
  {
344
369
  sym = @grammar.find_symbol_by_id!(val[2])
345
- result = val[0].append(sym)
346
370
  @prec_seen = true
371
+ builder = val[0]
372
+ builder.precedence_sym = sym
373
+ result = builder
347
374
  }
348
375
 
376
+ parameterizing_suffix: "?"
377
+ | "+"
378
+ | "*"
379
+
380
+ parameterizing_args: symbol { result = [val[0]] }
381
+ | parameterizing_args ',' symbol { result = val[0].append(val[2]) }
382
+
349
383
  named_ref_opt: # empty
350
384
  | '[' IDENTIFIER ']' { result = val[1].s_value }
351
385
 
@@ -377,6 +411,9 @@ rule
377
411
  | TAG
378
412
 
379
413
  string_as_id: STRING { result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) }
414
+
415
+ tag_opt: # empty
416
+ | TAG
380
417
  end
381
418
 
382
419
  ---- inner
@@ -387,18 +424,18 @@ def initialize(text, path, debug = false)
387
424
  @text = text
388
425
  @path = path
389
426
  @yydebug = debug
427
+ @rule_counter = Lrama::Grammar::Counter.new(0)
428
+ @midrule_action_counter = Lrama::Grammar::Counter.new(1)
390
429
  end
391
430
 
392
431
  def parse
393
432
  report_duration(:parse) do
394
433
  @lexer = Lrama::Lexer.new(@text)
395
- @grammar = Lrama::Grammar.new
434
+ @grammar = Lrama::Grammar.new(@rule_counter)
396
435
  @precedence_number = 0
397
436
  reset_precs
398
437
  do_parse
399
438
  @grammar.prepare
400
- @grammar.compute_nullable
401
- @grammar.compute_first_set
402
439
  @grammar.validate!
403
440
  @grammar
404
441
  end
@@ -409,18 +446,40 @@ def next_token
409
446
  end
410
447
 
411
448
  def on_error(error_token_id, error_value, value_stack)
412
- if error_value.respond_to?(:line) && error_value.respond_to?(:column)
413
- line = error_value.line
414
- first_column = error_value.column
449
+ if error_value.is_a?(Lrama::Lexer::Token)
450
+ line = error_value.first_line
451
+ first_column = error_value.first_column
452
+ last_column = error_value.last_column
453
+ value = "'#{error_value.s_value}'"
454
+ else
455
+ line = @lexer.line
456
+ first_column = @lexer.head_column
457
+ last_column = @lexer.column
458
+ value = error_value.inspect
459
+ end
460
+
461
+ raise ParseError, <<~ERROR
462
+ #{@path}:#{line}:#{first_column}: parse error on value #{value} (#{token_to_str(error_token_id) || '?'})
463
+ #{@text.split("\n")[line - 1]}
464
+ #{carrets(first_column, last_column)}
465
+ ERROR
466
+ end
467
+
468
+ def on_action_error(error_message, error_value)
469
+ if error_value.is_a?(Lrama::Lexer::Token)
470
+ line = error_value.first_line
471
+ first_column = error_value.first_column
472
+ last_column = error_value.last_column
415
473
  else
416
474
  line = @lexer.line
417
475
  first_column = @lexer.head_column
476
+ last_column = @lexer.column
418
477
  end
419
478
 
420
479
  raise ParseError, <<~ERROR
421
- #{@path}:#{line}:#{first_column}: parse error on value #{error_value.inspect} (#{token_to_str(error_token_id) || '?'})
480
+ #{@path}:#{line}: #{error_message}
422
481
  #{@text.split("\n")[line - 1]}
423
- #{carrets(first_column)}
482
+ #{carrets(first_column, last_column)}
424
483
  ERROR
425
484
  end
426
485
 
@@ -441,6 +500,6 @@ def end_c_declaration
441
500
  @lexer.end_symbol = nil
442
501
  end
443
502
 
444
- def carrets(first_column)
445
- ' ' * (first_column + 1) + '^' * (@lexer.column - first_column)
503
+ def carrets(first_column, last_column)
504
+ ' ' * (first_column + 1) + '^' * (last_column - first_column)
446
505
  end
@@ -1,10 +1,4 @@
1
1
  ---
2
- sources:
3
- - type: git
4
- name: ruby/gem_rbs_collection
5
- revision: 2de2d4535caba275f3b8533684aab110d921f553
6
- remote: https://github.com/ruby/gem_rbs_collection.git
7
- repo_dir: gems
8
2
  path: ".gem_rbs_collection"
9
3
  gems:
10
4
  - name: erb
@@ -15,12 +9,16 @@ gems:
15
9
  version: '0'
16
10
  source:
17
11
  type: stdlib
12
+ - name: forwardable
13
+ version: '0'
14
+ source:
15
+ type: stdlib
18
16
  - name: rake
19
17
  version: '13.0'
20
18
  source:
21
19
  type: git
22
20
  name: ruby/gem_rbs_collection
23
- revision: 2de2d4535caba275f3b8533684aab110d921f553
21
+ revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
24
22
  remote: https://github.com/ruby/gem_rbs_collection.git
25
23
  repo_dir: gems
26
24
  - name: stackprof
@@ -28,7 +26,7 @@ gems:
28
26
  source:
29
27
  type: git
30
28
  name: ruby/gem_rbs_collection
31
- revision: 28208148c7e64a25e9b86b9723b4c3a2cef14e81
29
+ revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
32
30
  remote: https://github.com/ruby/gem_rbs_collection.git
33
31
  repo_dir: gems
34
32
  - name: strscan
data/rbs_collection.yaml CHANGED
@@ -20,3 +20,4 @@ gems:
20
20
  # It's unnecessary if you don't use rbs as a library.
21
21
  - name: rbs
22
22
  ignore: true
23
+ - name: forwardable
@@ -0,0 +1,15 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Code
4
+ class PrinterCode < Code
5
+ @tag: untyped
6
+ def initialize: (?type: untyped, ?token_code: untyped, ?tag: untyped) -> void
7
+
8
+ private
9
+
10
+ # ref: Lrama::Grammar::Code.token_code.references
11
+ def reference_to_c: (untyped ref) -> untyped
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Code
4
+ extend Forwardable
5
+
6
+ attr_accessor type: untyped
7
+ attr_accessor token_code: untyped
8
+
9
+ # delegated
10
+ def s_value: -> String
11
+ def line: -> Integer
12
+ def column: -> untyped
13
+ def references: -> untyped
14
+
15
+ def initialize: (?type: untyped, ?token_code: untyped) -> void
16
+
17
+ def translated_code: () -> String
18
+
19
+ private
20
+
21
+ def reference_to_c: (untyped ref) -> untyped
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Counter
4
+ @number: Integer
5
+
6
+ def initialize: (Integer number) -> void
7
+
8
+ def increment: () -> Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ErrorToken
4
+ attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag]
5
+ attr_accessor token_code: Symbol
6
+ attr_accessor lineno: Integer
7
+
8
+ def translated_code: (Lexer::Token? tag) -> String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class Base
6
+ def initialize: (Lexer::Token::Parameterizing token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
+ def build: () -> Array[Rule]
8
+
9
+ @args: Array[Lexer::Token]
10
+ @token: Lexer::Token::Parameterizing
11
+ @key: Symbol
12
+ @rule_counter: Counter
13
+ @lhs: Lexer::Token
14
+ @user_code: Lexer::Token::UserCode?
15
+ @precedence_sym: Lexer::Token?
16
+ @line: Integer?
17
+ @expected_argument_num: Integer
18
+
19
+ private
20
+
21
+ def validate_argument_number!: () -> void
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class List < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class NonemptyList < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class Option < Base
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class SeparatedList < Base
6
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ class SeparatedNonemptyList < Base
6
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ module Lrama
2
+ class Grammar
3
+ class ParameterizingRules
4
+ class Builder
5
+ RULES: Hash[Symbol, singleton(Base)]
6
+
7
+ @token: Lexer::Token::Parameterizing
8
+ @key: Symbol
9
+ @rule_counter: Counter
10
+ @lhs: Lexer::Token
11
+ @user_code: Lexer::Token::UserCode?
12
+ @precedence_sym: Lexer::Token?
13
+ @line: Integer?
14
+
15
+ def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
16
+ def build: () -> Array[Rule]
17
+ def build_token: () -> Lrama::Lexer::Token
18
+ def create_builder: () -> void
19
+ def validate_key!: () -> void
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Precedence
4
+ include Comparable
5
+ attr_accessor type: Symbol
6
+ attr_accessor precedence: Integer
7
+
8
+ def <=>: (Precedence other) -> Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Printer
4
+ attr_accessor ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag]
5
+ attr_accessor token_code: Grammar::Code
6
+ attr_accessor lineno: Integer
7
+
8
+ def translated_code: (Lexer::Token member) -> String
9
+ end
10
+ end
11
+ end
@@ -1,21 +1,21 @@
1
1
  module Lrama
2
2
  class Grammar
3
3
  class Reference
4
- # TODO: Replace untyped referring_symbol with (Grammar::Symbol|Lexer::Token)
5
- attr_accessor type: Symbol
6
- attr_accessor value: (String|Integer)
4
+ attr_accessor type: ::Symbol
5
+ attr_accessor name: String
6
+ attr_accessor index: Integer
7
7
  attr_accessor ex_tag: Lexer::Token?
8
8
  attr_accessor first_column: Integer
9
9
  attr_accessor last_column: Integer
10
- attr_accessor referring_symbol: untyped
11
10
  attr_accessor position_in_rhs: Integer?
12
11
 
13
12
  def initialize: (
14
- type: Symbol, value: (String|Integer), ex_tag: Lexer::Token?,
13
+ type: ::Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
15
14
  first_column: Integer, last_column: Integer,
16
- referring_symbol: untyped, position_in_rhs: Integer?
15
+ ?position_in_rhs: Integer?
17
16
  ) -> void
18
17
 
18
+ def value: () -> (String|Integer)
19
19
  def tag: () -> untyped
20
20
  end
21
21
  end
@@ -0,0 +1,13 @@
1
+ module Lrama
2
+ class Grammar
3
+ class Rule
4
+ attr_accessor original_rule: Rule
5
+
6
+ def initialize: (
7
+ ?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped,
8
+ ?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped,
9
+ ?precedence_sym: untyped, ?lineno: untyped
10
+ ) -> void
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ module Lrama
2
+ class Grammar
3
+ class RuleBuilder
4
+ attr_accessor lhs: Lexer::Token
5
+ attr_accessor lhs_tag: untyped
6
+ attr_accessor line: Integer?
7
+ attr_reader rhs: Array[Lexer::Token]
8
+ attr_reader user_code: Lexer::Token::UserCode?
9
+ attr_reader precedence_sym: Lexer::Token?
10
+
11
+ @rule_counter: Counter
12
+ @midrule_action_counter: Counter
13
+ @position_in_original_rule_rhs: Integer?
14
+ @skip_preprocess_references: bool
15
+ @user_code: Lexer::Token::UserCode?
16
+ @rule_builders_for_derived_rules: Array[RuleBuilder]
17
+ @rules: Array[Rule]
18
+ @replaced_rhs: Array[Lexer::Token]
19
+ @parameterizing_rules: Array[Rule]
20
+ @midrule_action_rules: Array[Rule]
21
+
22
+ def initialize: (Counter rule_counter, Counter midrule_action_counter, ?Integer position_in_original_rule_rhs, ?skip_preprocess_references: bool) -> void
23
+ def add_rhs: (Lexer::Token rhs) -> void
24
+ def user_code=: (Lexer::Token::UserCode user_code) -> void
25
+ def precedence_sym=: (Lexer::Token user_code) -> void
26
+ def complete_input: () -> void
27
+ def setup_rules: () -> void
28
+ def parameterizing_rules: () -> Array[Rule]
29
+ def midrule_action_rules: () -> Array[Rule]
30
+ def rules: () -> Array[Rule]
31
+
32
+ private
33
+
34
+ def freeze_rhs: () -> void
35
+ def preprocess_references: () -> void
36
+ def build_rules: () -> void
37
+ def process_rhs: () -> void
38
+ def numberize_references: () -> void
39
+ def flush_user_code: () -> void
40
+ end
41
+ end
42
+ end