lrama 0.5.10 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +22 -2
- data/LEGAL.md +1 -0
- data/NEWS.md +167 -0
- data/README.md +1 -1
- data/Steepfile +8 -12
- data/lib/lrama/grammar/code/rule_action.rb +19 -3
- data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +10 -2
- data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +17 -6
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +12 -5
- data/lib/lrama/grammar/parameterizing_rules/builder.rb +23 -6
- data/lib/lrama/grammar/rule.rb +2 -1
- data/lib/lrama/grammar/rule_builder.rb +17 -19
- data/lib/lrama/grammar/symbol.rb +16 -2
- data/lib/lrama/grammar/type.rb +6 -0
- data/lib/lrama/grammar.rb +8 -3
- data/lib/lrama/lexer/token/parameterizing.rb +1 -1
- data/lib/lrama/lexer/token.rb +16 -9
- data/lib/lrama/lexer.rb +1 -2
- data/lib/lrama/parser.rb +359 -346
- data/lib/lrama/version.rb +1 -1
- data/lib/lrama.rb +0 -1
- data/parser.y +17 -15
- data/rbs_collection.lock.yaml +2 -8
- data/sig/lrama/grammar/error_token.rbs +11 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/base.rbs +28 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/list.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/option.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs +13 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs +13 -0
- data/sig/lrama/grammar/parameterizing_rules/builder.rbs +15 -1
- data/sig/lrama/grammar/reference.rbs +2 -2
- data/sig/lrama/grammar/rule.rbs +1 -1
- data/sig/lrama/grammar/rule_builder.rbs +1 -0
- data/sig/lrama/grammar/symbol.rbs +37 -0
- data/sig/lrama/lexer/token/parameterizing.rbs +3 -1
- data/sig/lrama/lexer/token.rbs +3 -3
- data/template/bison/yacc.c +0 -2
- metadata +12 -4
- data/doc/TODO.md +0 -59
- data/lib/lrama/type.rb +0 -4
data/lib/lrama/grammar/symbol.rb
CHANGED
@@ -6,10 +6,23 @@
|
|
6
6
|
|
7
7
|
module Lrama
|
8
8
|
class Grammar
|
9
|
-
class Symbol
|
10
|
-
attr_accessor :first_set, :first_set_bitmap
|
9
|
+
class Symbol
|
10
|
+
attr_accessor :id, :alias_name, :tag, :number, :token_id, :nullable, :precedence, :printer, :error_token, :first_set, :first_set_bitmap
|
11
|
+
attr_reader :term
|
11
12
|
attr_writer :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol
|
12
13
|
|
14
|
+
def initialize(id:, alias_name: nil, number: nil, tag: nil, term:, token_id: nil, nullable: nil, precedence: nil, printer: nil)
|
15
|
+
@id = id
|
16
|
+
@alias_name = alias_name
|
17
|
+
@number = number
|
18
|
+
@tag = tag
|
19
|
+
@term = term
|
20
|
+
@token_id = token_id
|
21
|
+
@nullable = nullable
|
22
|
+
@precedence = precedence
|
23
|
+
@printer = printer
|
24
|
+
end
|
25
|
+
|
13
26
|
def term?
|
14
27
|
term
|
15
28
|
end
|
@@ -41,6 +54,7 @@ module Lrama
|
|
41
54
|
# name for yysymbol_kind_t
|
42
55
|
#
|
43
56
|
# See: b4_symbol_kind_base
|
57
|
+
# @type var name: String
|
44
58
|
def enum_name
|
45
59
|
case
|
46
60
|
when accept_symbol?
|
data/lib/lrama/grammar.rb
CHANGED
@@ -9,9 +9,9 @@ require "lrama/grammar/reference"
|
|
9
9
|
require "lrama/grammar/rule"
|
10
10
|
require "lrama/grammar/rule_builder"
|
11
11
|
require "lrama/grammar/symbol"
|
12
|
+
require "lrama/grammar/type"
|
12
13
|
require "lrama/grammar/union"
|
13
14
|
require "lrama/lexer"
|
14
|
-
require "lrama/type"
|
15
15
|
|
16
16
|
module Lrama
|
17
17
|
# Grammar is the result of parsing an input grammar file
|
@@ -148,7 +148,7 @@ module Lrama
|
|
148
148
|
def prepare
|
149
149
|
normalize_rules
|
150
150
|
collect_symbols
|
151
|
-
|
151
|
+
set_lhs_and_rhs
|
152
152
|
fill_symbol_number
|
153
153
|
fill_default_precedence
|
154
154
|
fill_sym_to_rules
|
@@ -391,6 +391,11 @@ module Lrama
|
|
391
391
|
@rules << rule
|
392
392
|
end
|
393
393
|
|
394
|
+
builder.parameterizing_rules.each do |rule|
|
395
|
+
add_nterm(id: rule._lhs, tag: rule.lhs_tag)
|
396
|
+
@rules << rule
|
397
|
+
end
|
398
|
+
|
394
399
|
builder.midrule_action_rules.each do |rule|
|
395
400
|
add_nterm(id: rule._lhs)
|
396
401
|
end
|
@@ -484,7 +489,7 @@ module Lrama
|
|
484
489
|
end
|
485
490
|
end
|
486
491
|
|
487
|
-
def
|
492
|
+
def set_lhs_and_rhs
|
488
493
|
@rules.each do |rule|
|
489
494
|
rule.lhs = token_to_symbol(rule._lhs) if rule._lhs
|
490
495
|
|
@@ -4,7 +4,7 @@ module Lrama
|
|
4
4
|
class Parameterizing < Token
|
5
5
|
attr_accessor :args
|
6
6
|
|
7
|
-
def initialize(s_value
|
7
|
+
def initialize(s_value:, alias_name: nil, location: nil, args: [])
|
8
8
|
super s_value: s_value, alias_name: alias_name, location: location
|
9
9
|
@args = args
|
10
10
|
end
|
data/lib/lrama/lexer/token.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
require 'lrama/lexer/token/char'
|
2
|
+
require 'lrama/lexer/token/ident'
|
3
|
+
require 'lrama/lexer/token/parameterizing'
|
4
|
+
require 'lrama/lexer/token/tag'
|
5
|
+
require 'lrama/lexer/token/user_code'
|
6
|
+
|
1
7
|
module Lrama
|
2
8
|
class Lexer
|
3
|
-
class Token
|
4
|
-
|
5
|
-
attr_accessor :referred
|
9
|
+
class Token
|
10
|
+
attr_reader :s_value, :location
|
11
|
+
attr_accessor :alias_name, :referred
|
12
|
+
|
13
|
+
def initialize(s_value:, alias_name: nil, location: nil)
|
14
|
+
s_value.freeze
|
15
|
+
@s_value = s_value
|
16
|
+
@alias_name = alias_name
|
17
|
+
@location = location
|
18
|
+
end
|
6
19
|
|
7
20
|
def to_s
|
8
21
|
"#{super} location: #{location}"
|
@@ -36,9 +49,3 @@ module Lrama
|
|
36
49
|
end
|
37
50
|
end
|
38
51
|
end
|
39
|
-
|
40
|
-
require 'lrama/lexer/token/char'
|
41
|
-
require 'lrama/lexer/token/ident'
|
42
|
-
require 'lrama/lexer/token/parameterizing'
|
43
|
-
require 'lrama/lexer/token/tag'
|
44
|
-
require 'lrama/lexer/token/user_code'
|