lrama 0.6.1 → 0.6.3
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 +7 -2
- data/NEWS.md +43 -0
- data/README.md +23 -0
- data/Steepfile +2 -0
- data/lib/lrama/command.rb +10 -2
- data/lib/lrama/context.rb +6 -6
- data/lib/lrama/counterexamples/example.rb +2 -2
- data/lib/lrama/grammar/code/initial_action_code.rb +6 -0
- data/lib/lrama/grammar/code/no_reference_code.rb +4 -0
- data/lib/lrama/grammar/code/printer_code.rb +6 -0
- data/lib/lrama/grammar/code/rule_action.rb +11 -1
- data/lib/lrama/grammar/code.rb +1 -1
- data/lib/lrama/grammar/parameterizing_rule/resolver.rb +17 -9
- data/lib/lrama/grammar/reference.rb +4 -3
- data/lib/lrama/grammar/rule.rb +2 -2
- data/lib/lrama/grammar/rule_builder.rb +38 -36
- data/lib/lrama/grammar/stdlib.y +80 -0
- data/lib/lrama/grammar/symbol.rb +1 -1
- data/lib/lrama/grammar/symbols/resolver.rb +276 -0
- data/lib/lrama/grammar/symbols.rb +1 -0
- data/lib/lrama/grammar.rb +36 -246
- data/lib/lrama/lexer/token/user_code.rb +13 -2
- data/lib/lrama/lexer.rb +7 -0
- data/lib/lrama/output.rb +56 -2
- data/lib/lrama/parser.rb +571 -485
- data/lib/lrama/state.rb +4 -4
- data/lib/lrama/states/item.rb +19 -17
- data/lib/lrama/states_reporter.rb +10 -12
- data/lib/lrama/version.rb +1 -1
- data/lrama.gemspec +7 -0
- data/parser.y +24 -5
- data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +1 -0
- data/sig/lrama/grammar/reference.rbs +2 -1
- data/sig/lrama/grammar/symbol.rbs +4 -4
- data/sig/lrama/grammar/symbols/resolver.rbs +41 -0
- data/sig/lrama/grammar/type.rbs +11 -0
- data/template/bison/yacc.c +6 -0
- metadata +13 -17
- data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +0 -36
- data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +0 -28
- data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +0 -28
- data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +0 -28
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +0 -39
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +0 -34
- data/lib/lrama/grammar/parameterizing_rules/builder.rb +0 -60
- data/sig/lrama/grammar/parameterizing_rules/builder/base.rbs +0 -28
- data/sig/lrama/grammar/parameterizing_rules/builder/list.rbs +0 -10
- data/sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs +0 -10
- data/sig/lrama/grammar/parameterizing_rules/builder/option.rbs +0 -10
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs +0 -13
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs +0 -13
- data/sig/lrama/grammar/parameterizing_rules/builder.rbs +0 -24
data/lib/lrama/state.rb
CHANGED
@@ -29,8 +29,8 @@ module Lrama
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def non_default_reduces
|
32
|
-
reduces.
|
33
|
-
reduce.rule
|
32
|
+
reduces.reject do |reduce|
|
33
|
+
reduce.rule == @default_reduction_rule
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -105,8 +105,8 @@ module Lrama
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def selected_term_transitions
|
108
|
-
term_transitions.
|
109
|
-
|
108
|
+
term_transitions.reject do |shift, next_state|
|
109
|
+
shift.not_selected
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
data/lib/lrama/states/item.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# TODO: Validate position is not over rule rhs
|
2
2
|
|
3
|
+
require "forwardable"
|
4
|
+
|
3
5
|
module Lrama
|
4
6
|
class States
|
5
7
|
class Item < Struct.new(:rule, :position, keyword_init: true)
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators "rule", :lhs, :rhs
|
11
|
+
|
6
12
|
# Optimization for States#setup_state
|
7
13
|
def hash
|
8
|
-
[
|
14
|
+
[rule_id, position].hash
|
9
15
|
end
|
10
16
|
|
11
17
|
def rule_id
|
@@ -17,27 +23,23 @@ module Lrama
|
|
17
23
|
end
|
18
24
|
|
19
25
|
def number_of_rest_symbols
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def lhs
|
24
|
-
rule.lhs
|
26
|
+
rhs.count - position
|
25
27
|
end
|
26
28
|
|
27
29
|
def next_sym
|
28
|
-
|
30
|
+
rhs[position]
|
29
31
|
end
|
30
32
|
|
31
33
|
def next_next_sym
|
32
|
-
|
34
|
+
rhs[position + 1]
|
33
35
|
end
|
34
36
|
|
35
37
|
def previous_sym
|
36
|
-
|
38
|
+
rhs[position - 1]
|
37
39
|
end
|
38
40
|
|
39
41
|
def end_of_rule?
|
40
|
-
|
42
|
+
rhs.count == position
|
41
43
|
end
|
42
44
|
|
43
45
|
def beginning_of_rule?
|
@@ -45,7 +47,7 @@ module Lrama
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def start_item?
|
48
|
-
rule.
|
50
|
+
rule.initial_rule? && beginning_of_rule?
|
49
51
|
end
|
50
52
|
|
51
53
|
def new_by_next_position
|
@@ -53,11 +55,11 @@ module Lrama
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def symbols_before_dot
|
56
|
-
|
58
|
+
rhs[0...position]
|
57
59
|
end
|
58
60
|
|
59
61
|
def symbols_after_dot
|
60
|
-
|
62
|
+
rhs[position..-1]
|
61
63
|
end
|
62
64
|
|
63
65
|
def to_s
|
@@ -65,14 +67,14 @@ module Lrama
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def display_name
|
68
|
-
r =
|
69
|
-
"#{r} (rule #{
|
70
|
+
r = rhs.map(&:display_name).insert(position, "•").join(" ")
|
71
|
+
"#{r} (rule #{rule_id})"
|
70
72
|
end
|
71
73
|
|
72
74
|
# Right after position
|
73
75
|
def display_rest
|
74
|
-
r =
|
75
|
-
". #{r} (rule #{
|
76
|
+
r = rhs[position..-1].map(&:display_name).join(" ")
|
77
|
+
". #{r} (rule #{rule_id})"
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
@@ -53,7 +53,7 @@ module Lrama
|
|
53
53
|
last_lhs = nil
|
54
54
|
|
55
55
|
@states.rules.each do |rule|
|
56
|
-
if rule.
|
56
|
+
if rule.empty_rule?
|
57
57
|
r = "ε"
|
58
58
|
else
|
59
59
|
r = rule.rhs.map(&:display_name).join(" ")
|
@@ -84,17 +84,15 @@ module Lrama
|
|
84
84
|
last_lhs = nil
|
85
85
|
list = itemsets ? state.items : state.kernels
|
86
86
|
list.sort_by {|i| [i.rule_id, i.position] }.each do |item|
|
87
|
-
|
88
|
-
position = item.position
|
89
|
-
if rule.rhs.empty?
|
87
|
+
if item.empty_rule?
|
90
88
|
r = "ε •"
|
91
89
|
else
|
92
|
-
r =
|
90
|
+
r = item.rhs.map(&:display_name).insert(item.position, "•").join(" ")
|
93
91
|
end
|
94
|
-
if
|
95
|
-
l = " " *
|
92
|
+
if item.lhs == last_lhs
|
93
|
+
l = " " * item.lhs.id.s_value.length + "|"
|
96
94
|
else
|
97
|
-
l =
|
95
|
+
l = item.lhs.id.s_value + ":"
|
98
96
|
end
|
99
97
|
la = ""
|
100
98
|
if lookaheads && item.end_of_rule?
|
@@ -104,15 +102,15 @@ module Lrama
|
|
104
102
|
la = " [#{look_ahead.map(&:display_name).join(", ")}]"
|
105
103
|
end
|
106
104
|
end
|
107
|
-
last_lhs =
|
105
|
+
last_lhs = item.lhs
|
108
106
|
|
109
|
-
io << sprintf("%5i %s %s%s\n",
|
107
|
+
io << sprintf("%5i %s %s%s\n", item.rule_id, l, r, la)
|
110
108
|
end
|
111
109
|
io << "\n"
|
112
110
|
|
113
111
|
# Report shifts
|
114
|
-
tmp = state.term_transitions.
|
115
|
-
|
112
|
+
tmp = state.term_transitions.reject do |shift, _|
|
113
|
+
shift.not_selected
|
116
114
|
end.map do |shift, next_state|
|
117
115
|
[shift.next_sym, next_state.id]
|
118
116
|
end
|
data/lib/lrama/version.rb
CHANGED
data/lrama.gemspec
CHANGED
@@ -16,6 +16,13 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
17
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
18
18
|
end
|
19
|
+
|
20
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
22
|
+
spec.metadata["documentation_uri"] = spec.homepage
|
23
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
|
24
|
+
spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
|
25
|
+
|
19
26
|
spec.bindir = "exe"
|
20
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
28
|
spec.require_paths = ["lib"]
|
data/parser.y
CHANGED
@@ -69,6 +69,7 @@ rule
|
|
69
69
|
{
|
70
70
|
@grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[3])
|
71
71
|
}
|
72
|
+
| "%no-stdlib" { @grammar.no_stdlib = true }
|
72
73
|
| ";"
|
73
74
|
|
74
75
|
grammar_declaration: "%union" "{"
|
@@ -128,6 +129,26 @@ rule
|
|
128
129
|
lineno: val[3].line
|
129
130
|
)
|
130
131
|
}
|
132
|
+
| "%after-shift" IDENTIFIER
|
133
|
+
{
|
134
|
+
@grammar.after_shift = val[1]
|
135
|
+
}
|
136
|
+
| "%before-reduce" IDENTIFIER
|
137
|
+
{
|
138
|
+
@grammar.before_reduce = val[1]
|
139
|
+
}
|
140
|
+
| "%after-reduce" IDENTIFIER
|
141
|
+
{
|
142
|
+
@grammar.after_reduce = val[1]
|
143
|
+
}
|
144
|
+
| "%after-shift-error-token" IDENTIFIER
|
145
|
+
{
|
146
|
+
@grammar.after_shift_error_token = val[1]
|
147
|
+
}
|
148
|
+
| "%after-pop-stack" IDENTIFIER
|
149
|
+
{
|
150
|
+
@grammar.after_pop_stack = val[1]
|
151
|
+
}
|
131
152
|
|
132
153
|
symbol_declaration: "%token" token_declarations
|
133
154
|
| "%type" symbol_declarations
|
@@ -451,9 +472,9 @@ rule
|
|
451
472
|
result = builder
|
452
473
|
}
|
453
474
|
|
454
|
-
parameterizing_suffix: "?"
|
455
|
-
| "+"
|
456
|
-
| "*"
|
475
|
+
parameterizing_suffix: "?" { result = "option" }
|
476
|
+
| "+" { result = "nonempty_list" }
|
477
|
+
| "*" { result = "list" }
|
457
478
|
|
458
479
|
parameterizing_args: symbol { result = [val[0]] }
|
459
480
|
| parameterizing_args ',' symbol { result = val[0].append(val[2]) }
|
@@ -514,8 +535,6 @@ def parse
|
|
514
535
|
@precedence_number = 0
|
515
536
|
reset_precs
|
516
537
|
do_parse
|
517
|
-
@grammar.prepare
|
518
|
-
@grammar.validate!
|
519
538
|
@grammar
|
520
539
|
end
|
521
540
|
end
|
@@ -3,6 +3,7 @@ module Lrama
|
|
3
3
|
class Reference
|
4
4
|
attr_accessor type: ::Symbol
|
5
5
|
attr_accessor name: String
|
6
|
+
attr_accessor number: Integer
|
6
7
|
attr_accessor index: Integer
|
7
8
|
attr_accessor ex_tag: Lexer::Token?
|
8
9
|
attr_accessor first_column: Integer
|
@@ -10,7 +11,7 @@ module Lrama
|
|
10
11
|
attr_accessor position_in_rhs: Integer?
|
11
12
|
|
12
13
|
def initialize: (
|
13
|
-
type: ::Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
|
14
|
+
type: ::Symbol, ?name: String, ?number: Integer, ?index: Integer, ?ex_tag: Lexer::Token?,
|
14
15
|
first_column: Integer, last_column: Integer,
|
15
16
|
?position_in_rhs: Integer?
|
16
17
|
) -> void
|
@@ -2,7 +2,7 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class Symbol
|
4
4
|
attr_accessor id: Lexer::Token
|
5
|
-
attr_accessor alias_name: String
|
5
|
+
attr_accessor alias_name: String?
|
6
6
|
attr_accessor number: Integer
|
7
7
|
attr_accessor tag: Lexer::Token?
|
8
8
|
attr_accessor term: bool
|
@@ -20,8 +20,8 @@ module Lrama
|
|
20
20
|
attr_writer accept_symbol: Symbol
|
21
21
|
|
22
22
|
def initialize: (
|
23
|
-
id: Lexer::Token, alias_name: String?, number: Integer?, tag: Lexer::Token?,
|
24
|
-
|
23
|
+
id: Lexer::Token, term: bool, ?alias_name: String?, ?number: Integer?, ?tag: Lexer::Token?,
|
24
|
+
?token_id: Integer?, ?nullable: bool?, ?precedence: Precedence?, ?printer: Printer?) -> void
|
25
25
|
|
26
26
|
def term?: () -> bool
|
27
27
|
def nterm?: () -> bool
|
@@ -31,7 +31,7 @@ module Lrama
|
|
31
31
|
def accept_symbol?: () -> bool
|
32
32
|
def display_name: () -> String
|
33
33
|
def enum_name: () -> String
|
34
|
-
def comment: () -> String
|
34
|
+
def comment: () -> String?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Symbols
|
4
|
+
class Resolver
|
5
|
+
attr_reader terms: Array[Grammar::Symbol]
|
6
|
+
attr_reader nterms: Array[Grammar::Symbol]
|
7
|
+
|
8
|
+
@symbols: Array[Grammar::Symbol]?
|
9
|
+
@number: Integer
|
10
|
+
@used_numbers: Hash[Integer, bool]
|
11
|
+
|
12
|
+
def initialize: () -> void
|
13
|
+
def symbols: () -> Array[Grammar::Symbol]
|
14
|
+
def sort_by_number!: () -> void
|
15
|
+
def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
|
16
|
+
def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token?) -> Grammar::Symbol?
|
17
|
+
def find_symbol_by_s_value: (Grammar::Symbol s_value) -> Grammar::Symbol?
|
18
|
+
def find_symbol_by_s_value!: (Grammar::Symbol s_value) -> Grammar::Symbol
|
19
|
+
def find_symbol_by_id: (Lexer::Token id) -> Grammar::Symbol?
|
20
|
+
def find_symbol_by_id!: (Lexer::Token id) -> Grammar::Symbol
|
21
|
+
def find_symbol_by_token_id: (Integer token_id) -> Grammar::Symbol?
|
22
|
+
def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
|
23
|
+
def fill_symbol_number: () -> void
|
24
|
+
def fill_nterm_type: (Array[Grammar::Type] types) -> void
|
25
|
+
def fill_printer: (Array[Grammar::Printer] printers) -> void
|
26
|
+
def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
|
27
|
+
def token_to_symbol: (Lexer::Token token) -> Grammar::Symbol
|
28
|
+
def validate!: () -> void
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def find_nterm_by_id!: (Lexer::Token id) -> Grammar::Symbol
|
33
|
+
def fill_terms_number: () -> void
|
34
|
+
def fill_nterms_number: () -> void
|
35
|
+
def used_numbers: () -> Hash[Integer, bool]
|
36
|
+
def validate_number_uniqueness!: () -> void
|
37
|
+
def validate_alias_name_uniqueness!: () -> void
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/template/bison/yacc.c
CHANGED
@@ -1752,6 +1752,7 @@ yybackup:
|
|
1752
1752
|
*++yyvsp = yylval;
|
1753
1753
|
YY_IGNORE_MAYBE_UNINITIALIZED_END
|
1754
1754
|
*++yylsp = yylloc;
|
1755
|
+
<%= output.after_shift_function("/* %after-shift code. */") %>
|
1755
1756
|
|
1756
1757
|
/* Discard the shifted token. */
|
1757
1758
|
yychar = YYEMPTY;
|
@@ -1784,6 +1785,7 @@ yyreduce:
|
|
1784
1785
|
unconditionally makes the parser a bit smaller, and it avoids a
|
1785
1786
|
GCC warning that YYVAL may be used uninitialized. */
|
1786
1787
|
yyval = yyvsp[1-yylen];
|
1788
|
+
<%= output.before_reduce_function("/* %before-reduce function. */") %>
|
1787
1789
|
|
1788
1790
|
/* Default location. */
|
1789
1791
|
YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
|
@@ -1809,6 +1811,7 @@ yyreduce:
|
|
1809
1811
|
YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc<%= output.user_args %>);
|
1810
1812
|
|
1811
1813
|
YYPOPSTACK (yylen);
|
1814
|
+
<%= output.after_reduce_function("/* %after-reduce function. */") %>
|
1812
1815
|
yylen = 0;
|
1813
1816
|
|
1814
1817
|
*++yyvsp = yyval;
|
@@ -1910,6 +1913,7 @@ yyerrorlab:
|
|
1910
1913
|
/* Do not reclaim the symbols of the rule whose action triggered
|
1911
1914
|
this YYERROR. */
|
1912
1915
|
YYPOPSTACK (yylen);
|
1916
|
+
<%= output.after_pop_stack_function("yylen", "/* %after-pop-stack function. */") %>
|
1913
1917
|
yylen = 0;
|
1914
1918
|
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1915
1919
|
yystate = *yyssp;
|
@@ -1969,6 +1973,7 @@ yyerrlab1:
|
|
1969
1973
|
yydestruct ("Error: popping",
|
1970
1974
|
YY_ACCESSING_SYMBOL (yystate), yyvsp, yylsp<%= output.user_args %>);
|
1971
1975
|
YYPOPSTACK (1);
|
1976
|
+
<%= output.after_pop_stack_function(1, "/* %after-pop-stack function. */") %>
|
1972
1977
|
yystate = *yyssp;
|
1973
1978
|
YY_STACK_PRINT (yyss, yyssp<%= output.user_args %>);
|
1974
1979
|
}
|
@@ -1983,6 +1988,7 @@ yyerrlab1:
|
|
1983
1988
|
|
1984
1989
|
/* Shift the error token. */
|
1985
1990
|
YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp<%= output.user_args %>);
|
1991
|
+
<%= output.after_shift_error_token_function("/* %after-shift-error-token code. */") %>
|
1986
1992
|
|
1987
1993
|
yystate = yyn;
|
1988
1994
|
goto yynewstate;
|
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.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichiro Kaneko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: LALR (1) parser generator written by Ruby
|
14
14
|
email:
|
@@ -60,20 +60,16 @@ files:
|
|
60
60
|
- lib/lrama/grammar/parameterizing_rule/resolver.rb
|
61
61
|
- lib/lrama/grammar/parameterizing_rule/rhs.rb
|
62
62
|
- lib/lrama/grammar/parameterizing_rule/rule.rb
|
63
|
-
- lib/lrama/grammar/parameterizing_rules/builder.rb
|
64
|
-
- lib/lrama/grammar/parameterizing_rules/builder/base.rb
|
65
|
-
- lib/lrama/grammar/parameterizing_rules/builder/list.rb
|
66
|
-
- lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb
|
67
|
-
- lib/lrama/grammar/parameterizing_rules/builder/option.rb
|
68
|
-
- lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb
|
69
|
-
- lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb
|
70
63
|
- lib/lrama/grammar/percent_code.rb
|
71
64
|
- lib/lrama/grammar/precedence.rb
|
72
65
|
- lib/lrama/grammar/printer.rb
|
73
66
|
- lib/lrama/grammar/reference.rb
|
74
67
|
- lib/lrama/grammar/rule.rb
|
75
68
|
- lib/lrama/grammar/rule_builder.rb
|
69
|
+
- lib/lrama/grammar/stdlib.y
|
76
70
|
- lib/lrama/grammar/symbol.rb
|
71
|
+
- lib/lrama/grammar/symbols.rb
|
72
|
+
- lib/lrama/grammar/symbols/resolver.rb
|
77
73
|
- lib/lrama/grammar/type.rb
|
78
74
|
- lib/lrama/grammar/union.rb
|
79
75
|
- lib/lrama/lexer.rb
|
@@ -122,13 +118,6 @@ files:
|
|
122
118
|
- sig/lrama/grammar/parameterizing_rule/resolver.rbs
|
123
119
|
- sig/lrama/grammar/parameterizing_rule/rhs.rbs
|
124
120
|
- sig/lrama/grammar/parameterizing_rule/rule.rbs
|
125
|
-
- sig/lrama/grammar/parameterizing_rules/builder.rbs
|
126
|
-
- sig/lrama/grammar/parameterizing_rules/builder/base.rbs
|
127
|
-
- sig/lrama/grammar/parameterizing_rules/builder/list.rbs
|
128
|
-
- sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs
|
129
|
-
- sig/lrama/grammar/parameterizing_rules/builder/option.rbs
|
130
|
-
- sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs
|
131
|
-
- sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs
|
132
121
|
- sig/lrama/grammar/percent_code.rbs
|
133
122
|
- sig/lrama/grammar/precedence.rbs
|
134
123
|
- sig/lrama/grammar/printer.rbs
|
@@ -136,6 +125,8 @@ files:
|
|
136
125
|
- sig/lrama/grammar/rule.rbs
|
137
126
|
- sig/lrama/grammar/rule_builder.rbs
|
138
127
|
- sig/lrama/grammar/symbol.rbs
|
128
|
+
- sig/lrama/grammar/symbols/resolver.rbs
|
129
|
+
- sig/lrama/grammar/type.rbs
|
139
130
|
- sig/lrama/lexer/grammar_file.rbs
|
140
131
|
- sig/lrama/lexer/location.rbs
|
141
132
|
- sig/lrama/lexer/token.rbs
|
@@ -154,7 +145,12 @@ files:
|
|
154
145
|
homepage: https://github.com/ruby/lrama
|
155
146
|
licenses:
|
156
147
|
- GPL-3.0-or-later
|
157
|
-
metadata:
|
148
|
+
metadata:
|
149
|
+
homepage_uri: https://github.com/ruby/lrama
|
150
|
+
source_code_uri: https://github.com/ruby/lrama
|
151
|
+
documentation_uri: https://github.com/ruby/lrama
|
152
|
+
changelog_uri: https://github.com/ruby/lrama/releases
|
153
|
+
bug_tracker_uri: https://github.com/ruby/lrama/issues
|
158
154
|
post_install_message:
|
159
155
|
rdoc_options: []
|
160
156
|
require_paths:
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Base class for parameterizing rules builder
|
6
|
-
class Base
|
7
|
-
attr_reader :build_token
|
8
|
-
|
9
|
-
def initialize(token, rule_counter, lhs_tag, user_code, precedence_sym, line)
|
10
|
-
@args = token.args
|
11
|
-
@token = @args.first
|
12
|
-
@rule_counter = rule_counter
|
13
|
-
@lhs_tag = lhs_tag
|
14
|
-
@user_code = user_code
|
15
|
-
@precedence_sym = precedence_sym
|
16
|
-
@line = line
|
17
|
-
@expected_argument_num = 1
|
18
|
-
@build_token = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def build
|
22
|
-
raise NotImplementedError
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def validate_argument_number!
|
28
|
-
unless @args.count == @expected_argument_num
|
29
|
-
raise "Invalid number of arguments. expect: #{@expected_argument_num} actual: #{@args.count}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Builder for list of general parameterizing rules
|
6
|
-
class List < Base
|
7
|
-
|
8
|
-
# program: list(number)
|
9
|
-
#
|
10
|
-
# =>
|
11
|
-
#
|
12
|
-
# program: list_number
|
13
|
-
# list_number: ε
|
14
|
-
# list_number: list_number number
|
15
|
-
def build
|
16
|
-
validate_argument_number!
|
17
|
-
|
18
|
-
rules = []
|
19
|
-
@build_token = Lrama::Lexer::Token::Ident.new(s_value: "list_#{@token.s_value}")
|
20
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
21
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [@build_token, @token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
22
|
-
rules
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Builder for nonempty list of general parameterizing rules
|
6
|
-
class NonemptyList < Base
|
7
|
-
|
8
|
-
# program: nonempty_list(number)
|
9
|
-
#
|
10
|
-
# =>
|
11
|
-
#
|
12
|
-
# program: nonempty_list_number
|
13
|
-
# nonempty_list_number: number
|
14
|
-
# nonempty_list_number: nonempty_list_number number
|
15
|
-
def build
|
16
|
-
validate_argument_number!
|
17
|
-
|
18
|
-
rules = []
|
19
|
-
@build_token = Lrama::Lexer::Token::Ident.new(s_value: "nonempty_list_#{@token.s_value}")
|
20
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [@token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
21
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [@build_token, @token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
22
|
-
rules
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Builder for option of general parameterizing rules
|
6
|
-
class Option < Base
|
7
|
-
|
8
|
-
# program: option(number)
|
9
|
-
#
|
10
|
-
# =>
|
11
|
-
#
|
12
|
-
# program: option_number
|
13
|
-
# option_number: ε
|
14
|
-
# option_number: number
|
15
|
-
def build
|
16
|
-
validate_argument_number!
|
17
|
-
|
18
|
-
rules = []
|
19
|
-
@build_token = Lrama::Lexer::Token::Ident.new(s_value: "option_#{@token.s_value}")
|
20
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
21
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [@token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
22
|
-
rules
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Builder for separated list of general parameterizing rules
|
6
|
-
class SeparatedList < Base
|
7
|
-
def initialize(token, rule_counter, lhs_tag, user_code, precedence_sym, line)
|
8
|
-
super
|
9
|
-
@separator = @args[0]
|
10
|
-
@token = @args[1]
|
11
|
-
@expected_argument_num = 2
|
12
|
-
end
|
13
|
-
|
14
|
-
# program: separated_list(',', number)
|
15
|
-
#
|
16
|
-
# =>
|
17
|
-
#
|
18
|
-
# program: separated_list_number
|
19
|
-
# separated_list_number: ε
|
20
|
-
# separated_list_number: separated_nonempty_list_number
|
21
|
-
# separated_nonempty_list_number: number
|
22
|
-
# separated_nonempty_list_number: separated_nonempty_list_number ',' number
|
23
|
-
def build
|
24
|
-
validate_argument_number!
|
25
|
-
|
26
|
-
rules = []
|
27
|
-
@build_token = Lrama::Lexer::Token::Ident.new(s_value: "separated_list_#{@token.s_value}")
|
28
|
-
separated_nonempty_list_token = Lrama::Lexer::Token::Ident.new(s_value: "separated_nonempty_list_#{@token.s_value}")
|
29
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
30
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [separated_nonempty_list_token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
31
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: separated_nonempty_list_token, _rhs: [@token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
32
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: separated_nonempty_list_token, _rhs: [separated_nonempty_list_token, @separator, @token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
33
|
-
rules
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|