lrama 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codespellignore +0 -0
- data/.github/workflows/codespell.yaml +16 -0
- data/.github/workflows/test.yaml +23 -7
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +69 -3
- data/Rakefile +12 -0
- data/Steepfile +3 -0
- data/exe/lrama +1 -1
- data/lib/lrama/command.rb +16 -137
- data/lib/lrama/context.rb +4 -4
- data/lib/lrama/digraph.rb +1 -2
- data/lib/lrama/grammar/union.rb +2 -2
- data/lib/lrama/grammar.rb +187 -1
- data/lib/lrama/lexer/token.rb +7 -1
- data/lib/lrama/lexer.rb +131 -289
- data/lib/lrama/option_parser.rb +128 -0
- data/lib/lrama/options.rb +23 -0
- data/lib/lrama/output.rb +27 -15
- data/lib/lrama/parser.rb +1759 -255
- data/lib/lrama/version.rb +1 -1
- data/lib/lrama.rb +2 -0
- data/parser.y +416 -0
- data/rbs_collection.lock.yaml +1 -1
- data/sample/calc.y +0 -2
- data/sample/parse.y +0 -3
- data/sig/lrama/digraph.rbs +23 -0
- data/sig/lrama/lexer/token/type.rbs +17 -0
- data/template/bison/_yacc.h +71 -0
- data/template/bison/yacc.c +6 -71
- data/template/bison/yacc.h +1 -73
- metadata +11 -4
- data/lib/lrama/parser/token_scanner.rb +0 -56
data/lib/lrama/output.rb
CHANGED
@@ -7,7 +7,7 @@ module Lrama
|
|
7
7
|
extend Forwardable
|
8
8
|
include Report::Duration
|
9
9
|
|
10
|
-
attr_reader :grammar_file_path, :context, :grammar, :error_recovery
|
10
|
+
attr_reader :grammar_file_path, :context, :grammar, :error_recovery, :include_header
|
11
11
|
|
12
12
|
def_delegators "@context", :yyfinal, :yylast, :yyntokens, :yynnts, :yynrules, :yynstates,
|
13
13
|
:yymaxutok, :yypact_ninf, :yytable_ninf
|
@@ -28,6 +28,7 @@ module Lrama
|
|
28
28
|
@context = context
|
29
29
|
@grammar = grammar
|
30
30
|
@error_recovery = error_recovery
|
31
|
+
@include_header = header_file_path ? header_file_path.sub("./", "") : nil
|
31
32
|
end
|
32
33
|
|
33
34
|
if ERB.instance_method(:initialize).parameters.last.first == :key
|
@@ -40,11 +41,8 @@ module Lrama
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
def
|
44
|
-
|
45
|
-
erb.filename = file
|
46
|
-
tmp = erb.result_with_hash(context: @context, output: self)
|
47
|
-
replace_special_variables(tmp, path)
|
44
|
+
def render_partial(file)
|
45
|
+
render_template(partial_file(file))
|
48
46
|
end
|
49
47
|
|
50
48
|
def render
|
@@ -143,7 +141,7 @@ module Lrama
|
|
143
141
|
str << <<-STR
|
144
142
|
case #{sym.enum_name}: /* #{sym.comment} */
|
145
143
|
#line #{sym.printer.lineno} "#{@grammar_file_path}"
|
146
|
-
#{sym.printer.translated_code(sym.tag)}
|
144
|
+
{#{sym.printer.translated_code(sym.tag)}}
|
147
145
|
#line [@oline@] [@ofile@]
|
148
146
|
break;
|
149
147
|
|
@@ -160,7 +158,7 @@ module Lrama
|
|
160
158
|
<<-STR
|
161
159
|
#{comment}
|
162
160
|
#line #{@grammar.initial_action.line} "#{@grammar_file_path}"
|
163
|
-
#{@grammar.initial_action.translated_code}
|
161
|
+
{#{@grammar.initial_action.translated_code}}
|
164
162
|
STR
|
165
163
|
end
|
166
164
|
|
@@ -173,7 +171,7 @@ module Lrama
|
|
173
171
|
str << <<-STR
|
174
172
|
case #{sym.enum_name}: /* #{sym.comment} */
|
175
173
|
#line #{sym.error_token.lineno} "#{@grammar_file_path}"
|
176
|
-
#{sym.error_token.translated_code(sym.tag)}
|
174
|
+
{#{sym.error_token.translated_code(sym.tag)}}
|
177
175
|
#line [@oline@] [@ofile@]
|
178
176
|
break;
|
179
177
|
|
@@ -190,14 +188,13 @@ module Lrama
|
|
190
188
|
@context.states.rules.each do |rule|
|
191
189
|
next unless rule.code
|
192
190
|
|
193
|
-
rule = rule
|
194
191
|
code = rule.code
|
195
192
|
spaces = " " * (code.column - 1)
|
196
193
|
|
197
194
|
str << <<-STR
|
198
195
|
case #{rule.id + 1}: /* #{rule.as_comment} */
|
199
196
|
#line #{code.line} "#{@grammar_file_path}"
|
200
|
-
#{spaces}#{rule.translated_code}
|
197
|
+
#{spaces}{#{rule.translated_code}}
|
201
198
|
#line [@oline@] [@ofile@]
|
202
199
|
break;
|
203
200
|
|
@@ -212,14 +209,14 @@ module Lrama
|
|
212
209
|
str
|
213
210
|
end
|
214
211
|
|
215
|
-
def
|
216
|
-
param
|
212
|
+
def omit_blanks(param)
|
213
|
+
param.strip
|
217
214
|
end
|
218
215
|
|
219
216
|
# b4_parse_param
|
220
217
|
def parse_param
|
221
218
|
if @grammar.parse_param
|
222
|
-
|
219
|
+
omit_blanks(@grammar.parse_param)
|
223
220
|
else
|
224
221
|
""
|
225
222
|
end
|
@@ -227,7 +224,7 @@ module Lrama
|
|
227
224
|
|
228
225
|
def lex_param
|
229
226
|
if @grammar.lex_param
|
230
|
-
|
227
|
+
omit_blanks(@grammar.lex_param)
|
231
228
|
else
|
232
229
|
""
|
233
230
|
end
|
@@ -354,6 +351,17 @@ module Lrama
|
|
354
351
|
|
355
352
|
private
|
356
353
|
|
354
|
+
def eval_template(file, path)
|
355
|
+
tmp = render_template(file)
|
356
|
+
replace_special_variables(tmp, path)
|
357
|
+
end
|
358
|
+
|
359
|
+
def render_template(file)
|
360
|
+
erb = self.class.erb(File.read(file))
|
361
|
+
erb.filename = file
|
362
|
+
erb.result_with_hash(context: @context, output: self)
|
363
|
+
end
|
364
|
+
|
357
365
|
def template_file
|
358
366
|
File.join(template_dir, @template_name)
|
359
367
|
end
|
@@ -362,6 +370,10 @@ module Lrama
|
|
362
370
|
File.join(template_dir, "bison/yacc.h")
|
363
371
|
end
|
364
372
|
|
373
|
+
def partial_file(file)
|
374
|
+
File.join(template_dir, file)
|
375
|
+
end
|
376
|
+
|
365
377
|
def template_dir
|
366
378
|
File.expand_path("../../../template", __FILE__)
|
367
379
|
end
|