rusa 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +175 -0
- data/Rakefile +26 -0
- data/Steepfile +9 -0
- data/examples/calc.rb +29 -0
- data/examples/json.rb +55 -0
- data/examples/mini_lang.rb +52 -0
- data/exe/rusa +6 -0
- data/lib/rusa/analysis/automaton.rb +60 -0
- data/lib/rusa/analysis/conflict_resolver.rb +211 -0
- data/lib/rusa/analysis/first_follow.rb +106 -0
- data/lib/rusa/analysis/item.rb +51 -0
- data/lib/rusa/analysis/item_set.rb +64 -0
- data/lib/rusa/analysis/lalr_table.rb +460 -0
- data/lib/rusa/analysis/parse_action.rb +81 -0
- data/lib/rusa/cli.rb +188 -0
- data/lib/rusa/errors.rb +12 -0
- data/lib/rusa/generator/code_generator.rb +334 -0
- data/lib/rusa/grammar/action_capture.rb +128 -0
- data/lib/rusa/grammar/dsl.rb +123 -0
- data/lib/rusa/grammar/grammar.rb +212 -0
- data/lib/rusa/grammar/precedence.rb +29 -0
- data/lib/rusa/grammar/rule.rb +55 -0
- data/lib/rusa/grammar/symbol.rb +71 -0
- data/lib/rusa/version.rb +5 -0
- data/lib/rusa.rb +31 -0
- data/sig/generated/rusa/analysis/automaton.rbs +25 -0
- data/sig/generated/rusa/analysis/conflict_resolver.rbs +57 -0
- data/sig/generated/rusa/analysis/first_follow.rbs +33 -0
- data/sig/generated/rusa/analysis/item.rbs +35 -0
- data/sig/generated/rusa/analysis/item_set.rbs +31 -0
- data/sig/generated/rusa/analysis/lalr_table.rbs +182 -0
- data/sig/generated/rusa/analysis/parse_action.rbs +58 -0
- data/sig/generated/rusa/cli.rbs +68 -0
- data/sig/generated/rusa/errors.rbs +24 -0
- data/sig/generated/rusa/generator/code_generator.rbs +82 -0
- data/sig/generated/rusa/grammar/action_capture.rbs +46 -0
- data/sig/generated/rusa/grammar/dsl.rbs +62 -0
- data/sig/generated/rusa/grammar/grammar.rbs +103 -0
- data/sig/generated/rusa/grammar/precedence.rbs +23 -0
- data/sig/generated/rusa/grammar/rule.rbs +35 -0
- data/sig/generated/rusa/grammar/symbol.rbs +51 -0
- data/sig/generated/rusa/version.rbs +5 -0
- data/sig/generated/rusa.rbs +6 -0
- data/test/test_automaton.rb +27 -0
- data/test/test_code_generator.rb +74 -0
- data/test/test_dsl.rb +77 -0
- data/test/test_e2e.rb +134 -0
- data/test/test_first_follow.rb +70 -0
- data/test/test_grammar_model.rb +60 -0
- data/test/test_helper.rb +6 -0
- data/test/test_lalr_table.rb +64 -0
- metadata +96 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/conflict_resolver.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
class ConflictReport
|
|
6
|
+
attr_reader state_id: Integer
|
|
7
|
+
|
|
8
|
+
attr_reader lookahead: Symbol
|
|
9
|
+
|
|
10
|
+
attr_reader existing_action: Shift | Reduce | Accept
|
|
11
|
+
|
|
12
|
+
attr_reader new_action: Shift | Reduce | Accept
|
|
13
|
+
|
|
14
|
+
attr_reader resolved_action: Shift | Reduce | Accept | nil
|
|
15
|
+
|
|
16
|
+
attr_reader message: String
|
|
17
|
+
|
|
18
|
+
# : (state_id: Integer, lookahead: Symbol, existing_action: Shift | Reduce | Accept, new_action: Shift | Reduce | Accept, resolved_action: Shift | Reduce | Accept | nil, message: String) -> void
|
|
19
|
+
def initialize: (state_id: Integer, lookahead: Symbol, existing_action: Shift | Reduce | Accept, new_action: Shift | Reduce | Accept, resolved_action: Shift | Reduce | Accept | nil, message: String) -> void
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# ConflictResolver applies precedence and associativity rules to ACTION conflicts.
|
|
23
|
+
class ConflictResolver
|
|
24
|
+
# : (Shift | Reduce | Accept, Shift | Reduce | Accept, Symbol, Grammar::Grammar, state_id: Integer, productions_by_id: Hash[Integer?, Grammar::Production]) -> [Shift | Reduce | Accept | nil, ConflictReport]
|
|
25
|
+
def resolve: (Shift | Reduce | Accept, Shift | Reduce | Accept, Symbol, Grammar::Grammar, state_id: Integer, productions_by_id: Hash[Integer?, Grammar::Production]) -> [ Shift | Reduce | Accept | nil, ConflictReport ]
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# : (Shift | Reduce | Accept, Shift | Reduce | Accept, Symbol, Grammar::Grammar, state_id: Integer, productions_by_id: Hash[Integer?, Grammar::Production]) -> ConflictReport
|
|
30
|
+
def build_report: (Shift | Reduce | Accept, Shift | Reduce | Accept, Symbol, Grammar::Grammar, state_id: Integer, productions_by_id: Hash[Integer?, Grammar::Production]) -> ConflictReport
|
|
31
|
+
|
|
32
|
+
# : (Shift, Reduce, Symbol, Grammar::Grammar, Hash[Integer?, Grammar::Production], Integer) -> ConflictReport
|
|
33
|
+
def resolve_shift_reduce: (Shift, Reduce, Symbol, Grammar::Grammar, Hash[Integer?, Grammar::Production], Integer) -> ConflictReport
|
|
34
|
+
|
|
35
|
+
# : (Shift, Reduce, Grammar::Precedence, Grammar::Precedence) -> [Shift | Reduce | nil, String]
|
|
36
|
+
def compare_precedences: (Shift, Reduce, Grammar::Precedence, Grammar::Precedence) -> [ Shift | Reduce | nil, String ]
|
|
37
|
+
|
|
38
|
+
# : (Reduce, Reduce, Symbol, Integer) -> ConflictReport
|
|
39
|
+
def resolve_reduce_reduce: (Reduce, Reduce, Symbol, Integer) -> ConflictReport
|
|
40
|
+
|
|
41
|
+
# : (Integer, Symbol, Shift | Reduce | Accept, Shift | Reduce | Accept) -> ConflictReport
|
|
42
|
+
def duplicate_action_report: (Integer, Symbol, Shift | Reduce | Accept, Shift | Reduce | Accept) -> ConflictReport
|
|
43
|
+
|
|
44
|
+
# : (Shift, Symbol) -> [Shift, String]
|
|
45
|
+
def default_shift_resolution: (Shift, Symbol) -> [ Shift, String ]
|
|
46
|
+
|
|
47
|
+
# : (Shift) -> [Shift, String]
|
|
48
|
+
def higher_token_precedence_result: (Shift) -> [ Shift, String ]
|
|
49
|
+
|
|
50
|
+
# : (Reduce) -> [Reduce, String]
|
|
51
|
+
def higher_production_precedence_result: (Reduce) -> [ Reduce, String ]
|
|
52
|
+
|
|
53
|
+
# : (state_id: Integer, lookahead: Symbol, existing_action: Shift | Reduce | Accept, new_action: Shift | Reduce | Accept, resolved_action: Shift | Reduce | Accept | nil, message: String) -> ConflictReport
|
|
54
|
+
def build_conflict_report: (state_id: Integer, lookahead: Symbol, existing_action: Shift | Reduce | Accept, new_action: Shift | Reduce | Accept, resolved_action: Shift | Reduce | Accept | nil, message: String) -> ConflictReport
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/first_follow.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
# FIRST/FOLLOW sets drive lookahead computation for parser construction.
|
|
6
|
+
class FirstFollow
|
|
7
|
+
EMPTY: ::Symbol
|
|
8
|
+
|
|
9
|
+
attr_reader first_sets: Hash[Symbol, Set[Symbol]]
|
|
10
|
+
|
|
11
|
+
attr_reader follow_sets: Hash[Symbol, Set[Symbol]]
|
|
12
|
+
|
|
13
|
+
# : (Grammar::Grammar) -> void
|
|
14
|
+
def initialize: (Grammar::Grammar) -> void
|
|
15
|
+
|
|
16
|
+
# : (Array[Symbol]) -> Set[Symbol]
|
|
17
|
+
def first_of_sequence: (Array[Symbol]) -> Set[Symbol]
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
attr_reader grammar: Grammar::Grammar
|
|
22
|
+
|
|
23
|
+
# : () -> void
|
|
24
|
+
def initialize_sets: () -> void
|
|
25
|
+
|
|
26
|
+
# : () -> void
|
|
27
|
+
def compute_first_sets: () -> void
|
|
28
|
+
|
|
29
|
+
# : () -> void
|
|
30
|
+
def compute_follow_sets: () -> void
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/item.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
# Item represents a single LR(0) production with a dot position.
|
|
6
|
+
class Item
|
|
7
|
+
attr_reader production: Grammar::Production
|
|
8
|
+
|
|
9
|
+
attr_reader dot: Integer
|
|
10
|
+
|
|
11
|
+
# : (Grammar::Production, ?Integer) -> void
|
|
12
|
+
def initialize: (Grammar::Production, ?Integer) -> void
|
|
13
|
+
|
|
14
|
+
# : () -> Symbol?
|
|
15
|
+
def next_symbol: () -> Symbol?
|
|
16
|
+
|
|
17
|
+
# : () -> Item
|
|
18
|
+
def advance: () -> Item
|
|
19
|
+
|
|
20
|
+
# : () -> bool
|
|
21
|
+
def reduce?: () -> bool
|
|
22
|
+
|
|
23
|
+
# : (Object) -> bool
|
|
24
|
+
def ==: (Object) -> bool
|
|
25
|
+
|
|
26
|
+
alias eql? ==
|
|
27
|
+
|
|
28
|
+
# : () -> Integer
|
|
29
|
+
def hash: () -> Integer
|
|
30
|
+
|
|
31
|
+
# : () -> String
|
|
32
|
+
def to_s: () -> String
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/item_set.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
# ItemSet is a parser state identified by its LR(0) kernel items.
|
|
6
|
+
class ItemSet
|
|
7
|
+
attr_reader id: Integer
|
|
8
|
+
|
|
9
|
+
attr_reader items: Set[Item]
|
|
10
|
+
|
|
11
|
+
attr_reader kernel_items: Set[Item]
|
|
12
|
+
|
|
13
|
+
# : (Integer, Enumerable[Item], Grammar::Grammar) -> void
|
|
14
|
+
def initialize: (Integer, Enumerable[Item], Grammar::Grammar) -> void
|
|
15
|
+
|
|
16
|
+
# : (Object) -> bool
|
|
17
|
+
def ==: (Object) -> bool
|
|
18
|
+
|
|
19
|
+
alias eql? ==
|
|
20
|
+
|
|
21
|
+
# : () -> Integer
|
|
22
|
+
def hash: () -> Integer
|
|
23
|
+
|
|
24
|
+
# : () -> String
|
|
25
|
+
def to_s: () -> String
|
|
26
|
+
|
|
27
|
+
# : (Enumerable[Item], Grammar::Grammar) -> Set[Item]
|
|
28
|
+
def self.closure: (Enumerable[Item], Grammar::Grammar) -> Set[Item]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/lalr_table.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
# LALRTable merges canonical LR(1) states with the same LR(0) core.
|
|
6
|
+
class LALRTable
|
|
7
|
+
class LR1Item
|
|
8
|
+
attr_reader production: Grammar::Production
|
|
9
|
+
|
|
10
|
+
attr_reader dot: Integer
|
|
11
|
+
|
|
12
|
+
attr_reader lookahead: Symbol
|
|
13
|
+
|
|
14
|
+
# : (Grammar::Production, Integer, Symbol) -> void
|
|
15
|
+
def initialize: (Grammar::Production, Integer, Symbol) -> void
|
|
16
|
+
|
|
17
|
+
# : () -> Symbol?
|
|
18
|
+
def next_symbol: () -> Symbol?
|
|
19
|
+
|
|
20
|
+
# : () -> LR1Item
|
|
21
|
+
def advance: () -> LR1Item
|
|
22
|
+
|
|
23
|
+
# : () -> bool
|
|
24
|
+
def reduce?: () -> bool
|
|
25
|
+
|
|
26
|
+
# : () -> [Integer?, Integer]
|
|
27
|
+
def core: () -> [ Integer?, Integer ]
|
|
28
|
+
|
|
29
|
+
# : (Object) -> bool
|
|
30
|
+
def ==: (Object) -> bool
|
|
31
|
+
|
|
32
|
+
alias eql? ==
|
|
33
|
+
|
|
34
|
+
# : () -> Integer
|
|
35
|
+
def hash: () -> Integer
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class MergedItem
|
|
39
|
+
attr_reader production: Grammar::Production
|
|
40
|
+
|
|
41
|
+
attr_reader dot: Integer
|
|
42
|
+
|
|
43
|
+
attr_reader lookaheads: Set[Symbol]
|
|
44
|
+
|
|
45
|
+
# : (Grammar::Production, Integer, Set[Symbol]) -> void
|
|
46
|
+
def initialize: (Grammar::Production, Integer, Set[Symbol]) -> void
|
|
47
|
+
|
|
48
|
+
# : () -> Symbol?
|
|
49
|
+
def next_symbol: () -> Symbol?
|
|
50
|
+
|
|
51
|
+
# : () -> bool
|
|
52
|
+
def reduce?: () -> bool
|
|
53
|
+
|
|
54
|
+
# : () -> [Integer?, Integer]
|
|
55
|
+
def core: () -> [ Integer?, Integer ]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class MergedState
|
|
59
|
+
attr_reader id: Integer
|
|
60
|
+
|
|
61
|
+
attr_reader items: Array[MergedItem]
|
|
62
|
+
|
|
63
|
+
# : (Integer, Array[MergedItem]) -> void
|
|
64
|
+
def initialize: (Integer, Array[MergedItem]) -> void
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
attr_reader action_table: Hash[Integer, Hash[Symbol, Shift | Reduce | Accept]]
|
|
68
|
+
|
|
69
|
+
attr_reader goto_table: Hash[Integer, Hash[Symbol, Integer]]
|
|
70
|
+
|
|
71
|
+
attr_reader conflicts: Array[ConflictReport]
|
|
72
|
+
|
|
73
|
+
attr_reader states: Array[MergedState]
|
|
74
|
+
|
|
75
|
+
attr_reader transitions: Hash[Integer, Hash[Symbol, Integer]]
|
|
76
|
+
|
|
77
|
+
# : (Grammar::Grammar, ?first_follow: FirstFollow) -> void
|
|
78
|
+
def initialize: (Grammar::Grammar, ?first_follow: FirstFollow) -> void
|
|
79
|
+
|
|
80
|
+
# : () -> String
|
|
81
|
+
def report: () -> String
|
|
82
|
+
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
attr_reader grammar: Grammar::Grammar
|
|
86
|
+
|
|
87
|
+
attr_reader first_follow: FirstFollow
|
|
88
|
+
|
|
89
|
+
attr_reader resolver: ConflictResolver
|
|
90
|
+
|
|
91
|
+
# : () -> void
|
|
92
|
+
def build_tables: () -> void
|
|
93
|
+
|
|
94
|
+
# : () -> [Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]]]
|
|
95
|
+
def build_canonical_automaton: () -> [ Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]] ]
|
|
96
|
+
|
|
97
|
+
# : (Enumerable[LR1Item]) -> Set[LR1Item]
|
|
98
|
+
def lr1_closure: (Enumerable[LR1Item]) -> Set[LR1Item]
|
|
99
|
+
|
|
100
|
+
# : (Enumerable[LR1Item]) -> Array[Array[Integer | nil | Symbol]]
|
|
101
|
+
def lr1_state_key: (Enumerable[LR1Item]) -> Array[Array[Integer | nil | Symbol]]
|
|
102
|
+
|
|
103
|
+
# : (Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]]) -> void
|
|
104
|
+
def merge_states: (Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]]) -> void
|
|
105
|
+
|
|
106
|
+
# : (Enumerable[LR1Item]) -> Array[Array[Integer?]]
|
|
107
|
+
def lr0_core_key: (Enumerable[LR1Item]) -> Array[Array[Integer?]]
|
|
108
|
+
|
|
109
|
+
# : () -> void
|
|
110
|
+
def populate_tables: () -> void
|
|
111
|
+
|
|
112
|
+
# : (Integer, Symbol, Shift | Reduce | Accept, Hash[Integer?, Grammar::Production]) -> void
|
|
113
|
+
def add_action: (Integer, Symbol, Shift | Reduce | Accept, Hash[Integer?, Grammar::Production]) -> void
|
|
114
|
+
|
|
115
|
+
# : () -> Set[LR1Item]
|
|
116
|
+
def initial_lr1_state: () -> Set[LR1Item]
|
|
117
|
+
|
|
118
|
+
# : () -> Hash[Integer, Hash[Symbol, Integer]]
|
|
119
|
+
def empty_transition_table: () -> Hash[Integer, Hash[Symbol, Integer]]
|
|
120
|
+
|
|
121
|
+
# : (Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]], Hash[Array[Array[Integer | nil | Symbol]], Integer], Array[Integer], Integer) -> void
|
|
122
|
+
def build_canonical_transitions_for: (Array[Set[LR1Item]], Hash[Integer, Hash[Symbol, Integer]], Hash[Array[Array[Integer | nil | Symbol]], Integer], Array[Integer], Integer) -> void
|
|
123
|
+
|
|
124
|
+
# : (Set[LR1Item]) -> Array[Symbol]
|
|
125
|
+
def next_symbols_for: (Set[LR1Item]) -> Array[Symbol]
|
|
126
|
+
|
|
127
|
+
# : (Set[LR1Item], Symbol) -> Set[LR1Item]
|
|
128
|
+
def target_state_for: (Set[LR1Item], Symbol) -> Set[LR1Item]
|
|
129
|
+
|
|
130
|
+
# : (Array[Set[LR1Item]], Hash[Array[Array[Integer | nil | Symbol]], Integer], Array[Integer], Set[LR1Item]) -> Integer
|
|
131
|
+
def register_state: (Array[Set[LR1Item]], Hash[Array[Array[Integer | nil | Symbol]], Integer], Array[Integer], Set[LR1Item]) -> Integer
|
|
132
|
+
|
|
133
|
+
# : (Set[LR1Item], LR1Item, Symbol) -> bool
|
|
134
|
+
def add_closure_items: (Set[LR1Item], LR1Item, Symbol) -> bool
|
|
135
|
+
|
|
136
|
+
# : (LR1Item) -> Set[Symbol]
|
|
137
|
+
def closure_lookaheads_for: (LR1Item) -> Set[Symbol]
|
|
138
|
+
|
|
139
|
+
# : (Array[Set[LR1Item]]) -> Hash[Array[Array[Integer?]], Array[Integer]]
|
|
140
|
+
def group_states_by_lr0_core: (Array[Set[LR1Item]]) -> Hash[Array[Array[Integer?]], Array[Integer]]
|
|
141
|
+
|
|
142
|
+
# : () -> Hash[Array[Array[Integer?]], Array[Integer]]
|
|
143
|
+
def grouped_state_index: () -> Hash[Array[Array[Integer?]], Array[Integer]]
|
|
144
|
+
|
|
145
|
+
# : (Array[Set[LR1Item]], Array[Integer], Hash[Integer, Integer], Integer) -> MergedState
|
|
146
|
+
def merge_state_group: (Array[Set[LR1Item]], Array[Integer], Hash[Integer, Integer], Integer) -> MergedState
|
|
147
|
+
|
|
148
|
+
# : (Hash[[Integer?, Integer], MergedItem], Set[LR1Item]) -> void
|
|
149
|
+
def merge_items_from_state: (Hash[[ Integer?, Integer ], MergedItem], Set[LR1Item]) -> void
|
|
150
|
+
|
|
151
|
+
# : (Hash[[Integer?, Integer], MergedItem]) -> Array[MergedItem]
|
|
152
|
+
def sorted_merged_items: (Hash[[ Integer?, Integer ], MergedItem]) -> Array[MergedItem]
|
|
153
|
+
|
|
154
|
+
# : (Hash[Integer, Hash[Symbol, Integer]], Hash[Integer, Integer]) -> void
|
|
155
|
+
def merge_transitions: (Hash[Integer, Hash[Symbol, Integer]], Hash[Integer, Integer]) -> void
|
|
156
|
+
|
|
157
|
+
# : () -> Hash[Integer?, Grammar::Production]
|
|
158
|
+
def index_productions_by_id: () -> Hash[Integer?, Grammar::Production]
|
|
159
|
+
|
|
160
|
+
# : (MergedState, Hash[Integer?, Grammar::Production]) -> void
|
|
161
|
+
def populate_actions_for: (MergedState, Hash[Integer?, Grammar::Production]) -> void
|
|
162
|
+
|
|
163
|
+
# : (Integer, Symbol, Hash[Integer?, Grammar::Production]) -> void
|
|
164
|
+
def add_shift_action: (Integer, Symbol, Hash[Integer?, Grammar::Production]) -> void
|
|
165
|
+
|
|
166
|
+
# : (Integer, MergedItem, Hash[Integer?, Grammar::Production]) -> void
|
|
167
|
+
def populate_reduce_actions: (Integer, MergedItem, Hash[Integer?, Grammar::Production]) -> void
|
|
168
|
+
|
|
169
|
+
# : (Integer, Hash[Integer?, Grammar::Production]) -> void
|
|
170
|
+
def add_accept_action: (Integer, Hash[Integer?, Grammar::Production]) -> void
|
|
171
|
+
|
|
172
|
+
# : (Integer, Symbol, MergedItem, Hash[Integer?, Grammar::Production]) -> void
|
|
173
|
+
def add_reduce_action: (Integer, Symbol, MergedItem, Hash[Integer?, Grammar::Production]) -> void
|
|
174
|
+
|
|
175
|
+
# : (MergedState) -> void
|
|
176
|
+
def populate_gotos_for: (MergedState) -> void
|
|
177
|
+
|
|
178
|
+
# : (ConflictReport) -> String
|
|
179
|
+
def conflict_message: (ConflictReport) -> String
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Generated from lib/rusa/analysis/parse_action.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Analysis
|
|
5
|
+
# Parse actions populate ACTION tables.
|
|
6
|
+
class Shift
|
|
7
|
+
attr_reader state: Integer
|
|
8
|
+
|
|
9
|
+
# : (Integer) -> void
|
|
10
|
+
def initialize: (Integer) -> void
|
|
11
|
+
|
|
12
|
+
# : () -> [:shift, Integer]
|
|
13
|
+
def to_a: () -> [ :shift, Integer ]
|
|
14
|
+
|
|
15
|
+
# : (Object) -> bool
|
|
16
|
+
def ==: (Object) -> bool
|
|
17
|
+
|
|
18
|
+
alias eql? ==
|
|
19
|
+
|
|
20
|
+
# : () -> Integer
|
|
21
|
+
def hash: () -> Integer
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Reduce
|
|
25
|
+
attr_reader production_id: Integer?
|
|
26
|
+
|
|
27
|
+
# : (Integer?) -> void
|
|
28
|
+
def initialize: (Integer?) -> void
|
|
29
|
+
|
|
30
|
+
# : () -> [:reduce, Integer?]
|
|
31
|
+
def to_a: () -> [ :reduce, Integer? ]
|
|
32
|
+
|
|
33
|
+
# : (Object) -> bool
|
|
34
|
+
def ==: (Object) -> bool
|
|
35
|
+
|
|
36
|
+
alias eql? ==
|
|
37
|
+
|
|
38
|
+
# : () -> Integer
|
|
39
|
+
def hash: () -> Integer
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Accept
|
|
43
|
+
# : () -> void
|
|
44
|
+
def initialize: () -> void
|
|
45
|
+
|
|
46
|
+
# : () -> [:accept]
|
|
47
|
+
def to_a: () -> [ :accept ]
|
|
48
|
+
|
|
49
|
+
# : (Object) -> bool
|
|
50
|
+
def ==: (Object) -> bool
|
|
51
|
+
|
|
52
|
+
alias eql? ==
|
|
53
|
+
|
|
54
|
+
# : () -> Integer
|
|
55
|
+
def hash: () -> Integer
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Generated from lib/rusa/cli.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
# CLI wires grammar loading, table generation, and code output.
|
|
5
|
+
class CLI
|
|
6
|
+
# : (Array[String]) -> Integer
|
|
7
|
+
def run: (Array[String]) -> Integer
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
# : (Array[String]) -> Integer
|
|
12
|
+
def generate: (Array[String]) -> Integer
|
|
13
|
+
|
|
14
|
+
# : (Array[String]) -> Integer
|
|
15
|
+
def report: (Array[String]) -> Integer
|
|
16
|
+
|
|
17
|
+
# : (Array[String]) -> Integer
|
|
18
|
+
def check: (Array[String]) -> Integer
|
|
19
|
+
|
|
20
|
+
# : (String) -> [Grammar::Grammar, Analysis::LALRTable]
|
|
21
|
+
def build: (String) -> [ Grammar::Grammar, Analysis::LALRTable ]
|
|
22
|
+
|
|
23
|
+
# : (String) -> Grammar::Grammar
|
|
24
|
+
def load_grammar: (String) -> Grammar::Grammar
|
|
25
|
+
|
|
26
|
+
# : (String) -> String
|
|
27
|
+
def default_output_path: (String) -> String
|
|
28
|
+
|
|
29
|
+
# : (String) -> String
|
|
30
|
+
def default_class_name: (String) -> String
|
|
31
|
+
|
|
32
|
+
# : () -> String
|
|
33
|
+
def usage: () -> String
|
|
34
|
+
|
|
35
|
+
# : (Array[String]) -> Hash[Symbol, bool | String]
|
|
36
|
+
def parse_generate_options: (Array[String]) -> Hash[Symbol, bool | String]
|
|
37
|
+
|
|
38
|
+
# : () -> Hash[Symbol, bool | String]
|
|
39
|
+
def default_generate_options: () -> Hash[Symbol, bool | String]
|
|
40
|
+
|
|
41
|
+
# : (Array[String]) -> String
|
|
42
|
+
def required_grammar_file: (Array[String]) -> String
|
|
43
|
+
|
|
44
|
+
# : (Hash[Symbol, bool | String], String) -> String
|
|
45
|
+
def generator_class_name: (Hash[Symbol, bool | String], String) -> String
|
|
46
|
+
|
|
47
|
+
# : (Hash[Symbol, bool | String], String) -> String
|
|
48
|
+
def output_path_for: (Hash[Symbol, bool | String], String) -> String
|
|
49
|
+
|
|
50
|
+
# : (Hash[Symbol, bool | String]) -> bool
|
|
51
|
+
def compact_option: (Hash[Symbol, bool | String]) -> bool
|
|
52
|
+
|
|
53
|
+
# : (Hash[Symbol, bool | String]) -> bool
|
|
54
|
+
def line_tracking_option: (Hash[Symbol, bool | String]) -> bool
|
|
55
|
+
|
|
56
|
+
# : (Hash[Symbol, bool | String]) -> bool
|
|
57
|
+
def verbose_option: (Hash[Symbol, bool | String]) -> bool
|
|
58
|
+
|
|
59
|
+
# : (String, Array[String]) -> void
|
|
60
|
+
def print_section: (String, Array[String]) -> void
|
|
61
|
+
|
|
62
|
+
# : (Analysis::LALRTable) -> Array[String]
|
|
63
|
+
def conflict_messages: (Analysis::LALRTable) -> Array[String]
|
|
64
|
+
|
|
65
|
+
# : (String) -> String
|
|
66
|
+
def classify: (String) -> String
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Generated from lib/rusa/errors.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class GrammarError < Error
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class DuplicateTokenError < GrammarError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class DuplicateRuleError < GrammarError
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class UndefinedSymbolError < GrammarError
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class NoStartSymbolError < GrammarError
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class InvalidGrammarError < GrammarError
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Generated from lib/rusa/generator/code_generator.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Generator
|
|
5
|
+
# CodeGenerator emits a standalone Ruby parser class.
|
|
6
|
+
class CodeGenerator
|
|
7
|
+
TEMPLATE: ::String
|
|
8
|
+
|
|
9
|
+
# : (Grammar::Grammar, Analysis::LALRTable, ?class_name: String, ?compact: bool, ?line_tracking: bool) -> void
|
|
10
|
+
def initialize: (Grammar::Grammar, Analysis::LALRTable, ?class_name: String, ?compact: bool, ?line_tracking: bool) -> void
|
|
11
|
+
|
|
12
|
+
# : () -> String
|
|
13
|
+
def generate: () -> String
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
attr_reader grammar: Grammar::Grammar
|
|
18
|
+
|
|
19
|
+
attr_reader table: Analysis::LALRTable
|
|
20
|
+
|
|
21
|
+
attr_reader class_name: String
|
|
22
|
+
|
|
23
|
+
attr_reader compact: bool
|
|
24
|
+
|
|
25
|
+
attr_reader line_tracking: bool
|
|
26
|
+
|
|
27
|
+
# : () -> Hash[Symbol, String | bool]
|
|
28
|
+
def template_context: () -> Hash[Symbol, String | bool]
|
|
29
|
+
|
|
30
|
+
# : () -> String
|
|
31
|
+
def serialized_action_table: () -> String
|
|
32
|
+
|
|
33
|
+
# : () -> String
|
|
34
|
+
def serialized_productions: () -> String
|
|
35
|
+
|
|
36
|
+
# : () -> String
|
|
37
|
+
def serialized_tokens: () -> String
|
|
38
|
+
|
|
39
|
+
# : () -> String
|
|
40
|
+
def serialized_skip_patterns: () -> String
|
|
41
|
+
|
|
42
|
+
# : (Object) -> String
|
|
43
|
+
def serialized_plain_object: (Object) -> String
|
|
44
|
+
|
|
45
|
+
# : () -> Hash[Integer, Hash[Symbol, [:shift, Integer] | [:reduce, Integer?] | [:accept]]]
|
|
46
|
+
def action_table_payload: () -> Hash[Integer, Hash[Symbol, [ :shift, Integer ] | [ :reduce, Integer? ] | [ :accept ]]]
|
|
47
|
+
|
|
48
|
+
# : () -> Array[[Symbol, Integer]]
|
|
49
|
+
def production_payload: () -> Array[[ Symbol, Integer ]]
|
|
50
|
+
|
|
51
|
+
# : () -> Array[[Symbol, Regexp]]
|
|
52
|
+
def token_payload: () -> Array[[ Symbol, Regexp ]]
|
|
53
|
+
|
|
54
|
+
# : () -> Array[Regexp]
|
|
55
|
+
def skip_payload: () -> Array[Regexp]
|
|
56
|
+
|
|
57
|
+
# : (Object) -> String
|
|
58
|
+
def serialize: (Object) -> String
|
|
59
|
+
|
|
60
|
+
# : (Object) -> Object
|
|
61
|
+
def plain_object: (Object) -> Object
|
|
62
|
+
|
|
63
|
+
# : () -> Hash[Integer, Hash[Symbol, [:shift, Integer] | [:reduce, Integer?] | [:accept]]]
|
|
64
|
+
def action_table_index: () -> Hash[Integer, Hash[Symbol, [ :shift, Integer ] | [ :reduce, Integer? ] | [ :accept ]]]
|
|
65
|
+
|
|
66
|
+
# : () -> Array[Grammar::TerminalSymbol]
|
|
67
|
+
def token_terminals: () -> Array[Grammar::TerminalSymbol]
|
|
68
|
+
|
|
69
|
+
# : () -> String
|
|
70
|
+
def action_cases: () -> String
|
|
71
|
+
|
|
72
|
+
# : (Grammar::Production) -> String
|
|
73
|
+
def action_case_for: (Grammar::Production) -> String
|
|
74
|
+
|
|
75
|
+
# : (Grammar::Production) -> String
|
|
76
|
+
def action_body_for: (Grammar::Production) -> String
|
|
77
|
+
|
|
78
|
+
# : (String?) -> String?
|
|
79
|
+
def normalize_action_source: (String?) -> String?
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Generated from lib/rusa/grammar/action_capture.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Grammar
|
|
5
|
+
# Captures Ruby block source so semantic actions can be emitted into generated parsers.
|
|
6
|
+
module ActionCapture
|
|
7
|
+
BLOCK_OPENERS: untyped
|
|
8
|
+
|
|
9
|
+
PUSH_TOKENS: untyped
|
|
10
|
+
|
|
11
|
+
POP_TOKENS: untyped
|
|
12
|
+
|
|
13
|
+
BLOCK_KEYWORDS: untyped
|
|
14
|
+
|
|
15
|
+
# : (Proc) -> String?
|
|
16
|
+
def self?.capture: (Proc) -> String?
|
|
17
|
+
|
|
18
|
+
# : (String) -> String?
|
|
19
|
+
def self?.extract_block: (String) -> String?
|
|
20
|
+
|
|
21
|
+
# : (Symbol, String) -> bool
|
|
22
|
+
def self?.block_opener?: (Symbol, String) -> bool
|
|
23
|
+
|
|
24
|
+
# : (Symbol, String) -> Symbol?
|
|
25
|
+
def self?.structural_event: (Symbol, String) -> Symbol?
|
|
26
|
+
|
|
27
|
+
# : (Symbol, String) -> [Symbol, String]
|
|
28
|
+
def self?.closing_token_for: (Symbol, String) -> [ Symbol, String ]
|
|
29
|
+
|
|
30
|
+
# : (String, [Integer, Integer]) -> Integer
|
|
31
|
+
def self?.offset_for: (String, [ Integer, Integer ]) -> Integer
|
|
32
|
+
|
|
33
|
+
# : (Array[[[Integer, Integer], Symbol, String, Ripper::Lexer::State]], Integer) -> Array[[[Integer, Integer], Symbol, String, Ripper::Lexer::State]]
|
|
34
|
+
def self?.block_tokens_from: (Array[[ [ Integer, Integer ], Symbol, String, Ripper::Lexer::State ]], Integer) -> Array[[ [ Integer, Integer ], Symbol, String, Ripper::Lexer::State ]]
|
|
35
|
+
|
|
36
|
+
# : (String) -> Array[Integer]
|
|
37
|
+
def self?.cached_line_offsets: (String) -> Array[Integer]
|
|
38
|
+
|
|
39
|
+
# : () -> Hash[Integer, Array[Integer]]
|
|
40
|
+
def self?.line_offsets_cache: () -> Hash[Integer, Array[Integer]]
|
|
41
|
+
|
|
42
|
+
# : (String) -> Array[Integer]
|
|
43
|
+
def self?.build_line_offsets: (String) -> Array[Integer]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Generated from lib/rusa/grammar/dsl.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Rusa
|
|
4
|
+
module Grammar
|
|
5
|
+
# DSL evaluates the Ruby grammar definition and builds a Grammar object.
|
|
6
|
+
class DSL
|
|
7
|
+
attr_reader grammar: Grammar
|
|
8
|
+
|
|
9
|
+
# : () -> void
|
|
10
|
+
def initialize: () -> void
|
|
11
|
+
|
|
12
|
+
# : (Symbol | String, String | Regexp) -> TerminalSymbol
|
|
13
|
+
def token: (Symbol | String, String | Regexp) -> TerminalSymbol
|
|
14
|
+
|
|
15
|
+
# : (Regexp) -> Regexp
|
|
16
|
+
def skip: (Regexp) -> Regexp
|
|
17
|
+
|
|
18
|
+
# : (*Symbol | String) -> Array[Symbol | String]
|
|
19
|
+
def left: (*Symbol | String) -> Array[Symbol | String]
|
|
20
|
+
|
|
21
|
+
# : (*Symbol | String) -> Array[Symbol | String]
|
|
22
|
+
def right: (*Symbol | String) -> Array[Symbol | String]
|
|
23
|
+
|
|
24
|
+
# : (*Symbol | String) -> Array[Symbol | String]
|
|
25
|
+
def nonassoc: (*Symbol | String) -> Array[Symbol | String]
|
|
26
|
+
|
|
27
|
+
# : (Symbol | String) -> NonterminalSymbol
|
|
28
|
+
def start: (Symbol | String) -> NonterminalSymbol
|
|
29
|
+
|
|
30
|
+
# : (Symbol | String) { (self) [self: self] -> void } -> void
|
|
31
|
+
def rule: (Symbol | String) { (self) [self: self] -> void } -> void
|
|
32
|
+
|
|
33
|
+
# : (*Symbol | String) -> AltBuilder
|
|
34
|
+
# : (*Symbol | String) { (*Object) -> Object } -> AltBuilder
|
|
35
|
+
def alt: (*Symbol | String) -> AltBuilder
|
|
36
|
+
| (*Symbol | String) { (*Object) -> Object } -> AltBuilder
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
# : (Symbol, Array[Symbol | String]) -> Array[Symbol | String]
|
|
41
|
+
def register_precedence: (Symbol, Array[Symbol | String]) -> Array[Symbol | String]
|
|
42
|
+
|
|
43
|
+
# : (String | Regexp) -> Regexp
|
|
44
|
+
def normalize_token_pattern: (String | Regexp) -> Regexp
|
|
45
|
+
|
|
46
|
+
# : (Regexp) -> Regexp
|
|
47
|
+
def anchor_regexp: (Regexp) -> Regexp
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# AltBuilder allows precedence and source overrides to be chained from alt.
|
|
51
|
+
class AltBuilder
|
|
52
|
+
# : (Production) -> void
|
|
53
|
+
def initialize: (Production) -> void
|
|
54
|
+
|
|
55
|
+
# : (Symbol | String) -> self
|
|
56
|
+
def prec: (Symbol | String) -> self
|
|
57
|
+
|
|
58
|
+
# : (String) -> self
|
|
59
|
+
def action: (String) -> self
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|