lrama 0.6.8 → 0.6.10
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 +19 -0
- data/.gitignore +2 -0
- data/Gemfile +6 -3
- data/NEWS.md +220 -0
- data/README.md +41 -4
- data/Rakefile +2 -0
- data/Steepfile +6 -17
- data/exe/lrama +1 -0
- data/lib/lrama/bitmap.rb +2 -0
- data/lib/lrama/command.rb +8 -14
- data/lib/lrama/context.rb +8 -6
- data/lib/lrama/counterexamples/derivation.rb +2 -0
- data/lib/lrama/counterexamples/example.rb +2 -0
- data/lib/lrama/counterexamples/path.rb +2 -0
- data/lib/lrama/counterexamples/production_path.rb +2 -0
- data/lib/lrama/counterexamples/start_path.rb +2 -0
- data/lib/lrama/counterexamples/state_item.rb +2 -0
- data/lib/lrama/counterexamples/transition_path.rb +2 -0
- data/lib/lrama/counterexamples/triple.rb +2 -0
- data/lib/lrama/counterexamples.rb +17 -15
- data/lib/lrama/diagnostics.rb +36 -0
- data/lib/lrama/digraph.rb +2 -0
- data/lib/lrama/grammar/auxiliary.rb +2 -0
- data/lib/lrama/grammar/binding.rb +12 -1
- data/lib/lrama/grammar/code/destructor_code.rb +2 -0
- data/lib/lrama/grammar/code/initial_action_code.rb +2 -0
- data/lib/lrama/grammar/code/no_reference_code.rb +2 -0
- data/lib/lrama/grammar/code/printer_code.rb +2 -0
- data/lib/lrama/grammar/code/rule_action.rb +7 -3
- data/lib/lrama/grammar/code.rb +7 -5
- data/lib/lrama/grammar/counter.rb +2 -0
- data/lib/lrama/grammar/destructor.rb +2 -0
- data/lib/lrama/grammar/error_token.rb +2 -0
- data/lib/lrama/grammar/parameterizing_rule/resolver.rb +7 -1
- data/lib/lrama/grammar/parameterizing_rule/rhs.rb +25 -0
- data/lib/lrama/grammar/parameterizing_rule/rule.rb +9 -2
- data/lib/lrama/grammar/parameterizing_rule.rb +2 -0
- data/lib/lrama/grammar/percent_code.rb +2 -0
- data/lib/lrama/grammar/precedence.rb +2 -0
- data/lib/lrama/grammar/printer.rb +2 -0
- data/lib/lrama/grammar/reference.rb +2 -0
- data/lib/lrama/grammar/rule.rb +10 -3
- data/lib/lrama/grammar/rule_builder.rb +65 -66
- data/lib/lrama/grammar/symbol.rb +2 -0
- data/lib/lrama/grammar/symbols/resolver.rb +5 -1
- data/lib/lrama/grammar/symbols.rb +2 -0
- data/lib/lrama/grammar/type.rb +2 -0
- data/lib/lrama/grammar/union.rb +2 -0
- data/lib/lrama/grammar.rb +51 -30
- data/lib/lrama/grammar_validator.rb +37 -0
- data/lib/lrama/lexer/grammar_file.rb +2 -0
- data/lib/lrama/lexer/location.rb +2 -0
- data/lib/lrama/lexer/token/char.rb +2 -0
- data/lib/lrama/lexer/token/ident.rb +2 -0
- data/lib/lrama/lexer/token/instantiate_rule.rb +2 -0
- data/lib/lrama/lexer/token/tag.rb +2 -0
- data/lib/lrama/lexer/token/user_code.rb +3 -1
- data/lib/lrama/lexer/token.rb +7 -5
- data/lib/lrama/lexer.rb +11 -8
- data/lib/lrama/{warning.rb → logger.rb} +5 -13
- data/lib/lrama/option_parser.rb +58 -33
- data/lib/lrama/options.rb +5 -2
- data/lib/lrama/output.rb +38 -69
- data/lib/lrama/parser.rb +650 -779
- data/lib/lrama/report/duration.rb +2 -0
- data/lib/lrama/report/profile.rb +2 -0
- data/lib/lrama/report.rb +4 -2
- data/lib/lrama/state/reduce.rb +3 -0
- data/lib/lrama/state/reduce_reduce_conflict.rb +2 -0
- data/lib/lrama/state/resolved_conflict.rb +3 -1
- data/lib/lrama/state/shift.rb +2 -0
- data/lib/lrama/state/shift_reduce_conflict.rb +2 -0
- data/lib/lrama/state.rb +7 -5
- data/lib/lrama/states/item.rb +5 -3
- data/lib/lrama/states.rb +18 -46
- data/lib/lrama/states_reporter.rb +60 -19
- data/lib/lrama/trace_reporter.rb +30 -0
- data/lib/lrama/version.rb +3 -1
- data/lib/lrama.rb +22 -17
- data/lrama.gemspec +3 -1
- data/parser.y +111 -230
- data/sig/lrama/grammar/auxiliary.rbs +10 -0
- data/sig/lrama/grammar/binding.rbs +4 -0
- data/sig/lrama/grammar/code/destructor_code.rbs +3 -4
- data/sig/lrama/grammar/code/initial_action_code.rbs +15 -0
- data/sig/lrama/grammar/code/no_reference_code.rbs +15 -0
- data/sig/lrama/grammar/code/printer_code.rbs +3 -4
- data/sig/lrama/grammar/code/rule_action.rbs +19 -0
- data/sig/lrama/grammar/code.rbs +3 -3
- data/sig/lrama/grammar/destructor.rbs +3 -1
- data/sig/lrama/grammar/error_token.rbs +4 -2
- data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +2 -1
- data/sig/lrama/grammar/parameterizing_rule/rhs.rbs +2 -1
- data/sig/lrama/grammar/parameterizing_rule/rule.rbs +2 -1
- data/sig/lrama/grammar/precedence.rbs +3 -1
- data/sig/lrama/grammar/printer.rbs +3 -1
- data/sig/lrama/grammar/rule.rbs +35 -3
- data/sig/lrama/grammar/rule_builder.rbs +10 -9
- data/sig/lrama/grammar/symbol.rbs +6 -6
- data/sig/lrama/grammar/symbols/resolver.rbs +22 -3
- data/sig/lrama/grammar/type.rbs +2 -2
- data/sig/lrama/grammar/union.rbs +12 -0
- data/sig/lrama/grammar.rbs +91 -1
- data/sig/lrama/options.rbs +3 -2
- data/sig/lrama/state/reduce.rbs +20 -0
- data/sig/lrama/state/reduce_reduce_conflict.rbs +13 -0
- data/sig/lrama/state/resolved_conflict.rbs +14 -0
- data/sig/lrama/state/shift.rbs +14 -0
- data/sig/lrama/state/shift_reduce_conflict.rbs +13 -0
- data/sig/lrama/states/item.rbs +30 -0
- data/template/bison/yacc.c +24 -19
- metadata +17 -6
- data/sample/calc.output +0 -263
- data/sample/calc.y +0 -101
- data/sample/parse.y +0 -59
data/lib/lrama/grammar.rb
CHANGED
@@ -1,43 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "forwardable"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
require_relative "grammar/auxiliary"
|
5
|
+
require_relative "grammar/binding"
|
6
|
+
require_relative "grammar/code"
|
7
|
+
require_relative "grammar/counter"
|
8
|
+
require_relative "grammar/destructor"
|
9
|
+
require_relative "grammar/error_token"
|
10
|
+
require_relative "grammar/parameterizing_rule"
|
11
|
+
require_relative "grammar/percent_code"
|
12
|
+
require_relative "grammar/precedence"
|
13
|
+
require_relative "grammar/printer"
|
14
|
+
require_relative "grammar/reference"
|
15
|
+
require_relative "grammar/rule"
|
16
|
+
require_relative "grammar/rule_builder"
|
17
|
+
require_relative "grammar/symbol"
|
18
|
+
require_relative "grammar/symbols"
|
19
|
+
require_relative "grammar/type"
|
20
|
+
require_relative "grammar/union"
|
21
|
+
require_relative "lexer"
|
20
22
|
|
21
23
|
module Lrama
|
22
24
|
# Grammar is the result of parsing an input grammar file
|
23
25
|
class Grammar
|
24
26
|
extend Forwardable
|
25
27
|
|
26
|
-
attr_reader :percent_codes, :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol, :aux
|
27
|
-
attr_accessor :union, :expect,
|
28
|
-
:printers, :error_tokens,
|
29
|
-
:lex_param, :parse_param, :initial_action,
|
28
|
+
attr_reader :percent_codes, :eof_symbol, :error_symbol, :undef_symbol, :accept_symbol, :aux, :parameterizing_rule_resolver
|
29
|
+
attr_accessor :union, :expect, :printers, :error_tokens, :lex_param, :parse_param, :initial_action,
|
30
30
|
:after_shift, :before_reduce, :after_reduce, :after_shift_error_token, :after_pop_stack,
|
31
|
-
:symbols_resolver, :types,
|
32
|
-
:rules, :rule_builders,
|
33
|
-
:sym_to_rules, :no_stdlib
|
31
|
+
:symbols_resolver, :types, :rules, :rule_builders, :sym_to_rules, :no_stdlib, :locations
|
34
32
|
|
35
33
|
def_delegators "@symbols_resolver", :symbols, :nterms, :terms, :add_nterm, :add_term,
|
36
34
|
:find_symbol_by_number!, :find_symbol_by_id!, :token_to_symbol,
|
37
35
|
:find_symbol_by_s_value!, :fill_symbol_number, :fill_nterm_type,
|
38
36
|
:fill_printer, :fill_destructor, :fill_error_token, :sort_by_number!
|
39
37
|
|
40
|
-
|
41
38
|
def initialize(rule_counter)
|
42
39
|
@rule_counter = rule_counter
|
43
40
|
|
@@ -59,10 +56,15 @@ module Lrama
|
|
59
56
|
@accept_symbol = nil
|
60
57
|
@aux = Auxiliary.new
|
61
58
|
@no_stdlib = false
|
59
|
+
@locations = false
|
62
60
|
|
63
61
|
append_special_symbols
|
64
62
|
end
|
65
63
|
|
64
|
+
def create_rule_builder(rule_counter, midrule_action_counter)
|
65
|
+
RuleBuilder.new(rule_counter, midrule_action_counter, @parameterizing_rule_resolver)
|
66
|
+
end
|
67
|
+
|
66
68
|
def add_percent_code(id:, code:)
|
67
69
|
@percent_codes << PercentCode.new(id.s_value, code.s_value)
|
68
70
|
end
|
@@ -141,6 +143,7 @@ module Lrama
|
|
141
143
|
end
|
142
144
|
|
143
145
|
def prepare
|
146
|
+
resolve_inline_rules
|
144
147
|
normalize_rules
|
145
148
|
collect_symbols
|
146
149
|
set_lhs_and_rhs
|
@@ -149,6 +152,7 @@ module Lrama
|
|
149
152
|
fill_sym_to_rules
|
150
153
|
compute_nullable
|
151
154
|
compute_first_set
|
155
|
+
set_locations
|
152
156
|
end
|
153
157
|
|
154
158
|
# TODO: More validation methods
|
@@ -255,7 +259,7 @@ module Lrama
|
|
255
259
|
|
256
260
|
def setup_rules
|
257
261
|
@rule_builders.each do |builder|
|
258
|
-
builder.setup_rules
|
262
|
+
builder.setup_rules
|
259
263
|
end
|
260
264
|
end
|
261
265
|
|
@@ -289,10 +293,23 @@ module Lrama
|
|
289
293
|
@accept_symbol = term
|
290
294
|
end
|
291
295
|
|
296
|
+
def resolve_inline_rules
|
297
|
+
while @rule_builders.any? {|r| r.has_inline_rules? } do
|
298
|
+
@rule_builders = @rule_builders.flat_map do |builder|
|
299
|
+
if builder.has_inline_rules?
|
300
|
+
builder.resolve_inline_rules
|
301
|
+
else
|
302
|
+
builder
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
292
308
|
def normalize_rules
|
293
309
|
# Add $accept rule to the top of rules
|
294
|
-
|
295
|
-
|
310
|
+
rule_builder = @rule_builders.first # : RuleBuilder
|
311
|
+
lineno = rule_builder ? rule_builder.line : 0
|
312
|
+
@rules << Rule.new(id: @rule_counter.increment, _lhs: @accept_symbol.id, _rhs: [rule_builder.lhs, @eof_symbol.id], token_code: nil, lineno: lineno)
|
296
313
|
|
297
314
|
setup_rules
|
298
315
|
|
@@ -370,12 +387,16 @@ module Lrama
|
|
370
387
|
rules.each do |rule|
|
371
388
|
next if rule.lhs.nterm?
|
372
389
|
|
373
|
-
errors << "[BUG] LHS of #{rule} (line: #{rule.lineno}) is term. It should be nterm."
|
390
|
+
errors << "[BUG] LHS of #{rule.display_name} (line: #{rule.lineno}) is term. It should be nterm."
|
374
391
|
end
|
375
392
|
|
376
393
|
return if errors.empty?
|
377
394
|
|
378
395
|
raise errors.join("\n")
|
379
396
|
end
|
397
|
+
|
398
|
+
def set_locations
|
399
|
+
@locations = @locations || @rules.any? {|rule| rule.contains_at_reference? }
|
400
|
+
end
|
380
401
|
end
|
381
402
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lrama
|
4
|
+
class GrammarValidator
|
5
|
+
def initialize(grammar, states, logger)
|
6
|
+
@grammar = grammar
|
7
|
+
@states = states
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
conflicts_within_threshold?
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def conflicts_within_threshold?
|
18
|
+
return true unless @grammar.expect
|
19
|
+
|
20
|
+
[sr_conflicts_within_threshold(@grammar.expect), rr_conflicts_within_threshold(0)].all?
|
21
|
+
end
|
22
|
+
|
23
|
+
def sr_conflicts_within_threshold(expected)
|
24
|
+
return true if expected == @states.sr_conflicts_count
|
25
|
+
|
26
|
+
@logger.error("shift/reduce conflicts: #{@states.sr_conflicts_count} found, #{expected} expected")
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def rr_conflicts_within_threshold(expected)
|
31
|
+
return true if expected == @states.rr_conflicts_count
|
32
|
+
|
33
|
+
@logger.error("reduce/reduce conflicts: #{@states.rr_conflicts_count} found, #{expected} expected")
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/lrama/lexer/location.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "strscan"
|
2
4
|
|
3
5
|
module Lrama
|
@@ -16,7 +18,7 @@ module Lrama
|
|
16
18
|
scanner = StringScanner.new(s_value)
|
17
19
|
references = []
|
18
20
|
|
19
|
-
|
21
|
+
until scanner.eos? do
|
20
22
|
case
|
21
23
|
when reference = scan_reference(scanner)
|
22
24
|
references << reference
|
data/lib/lrama/lexer/token.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'token/char'
|
4
|
+
require_relative 'token/ident'
|
5
|
+
require_relative 'token/instantiate_rule'
|
6
|
+
require_relative 'token/tag'
|
7
|
+
require_relative 'token/user_code'
|
6
8
|
|
7
9
|
module Lrama
|
8
10
|
class Lexer
|
data/lib/lrama/lexer.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "strscan"
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
require_relative "lexer/grammar_file"
|
6
|
+
require_relative "lexer/location"
|
7
|
+
require_relative "lexer/token"
|
6
8
|
|
7
9
|
module Lrama
|
8
10
|
class Lexer
|
9
11
|
attr_reader :head_line, :head_column, :line
|
10
12
|
attr_accessor :status, :end_symbol
|
11
13
|
|
12
|
-
SYMBOLS = ['%{', '%}', '%%', '{', '}', '\[', '\]', '\(', '\)', '\,', ':', '\|', ';']
|
14
|
+
SYMBOLS = ['%{', '%}', '%%', '{', '}', '\[', '\]', '\(', '\)', '\,', ':', '\|', ';'].freeze
|
13
15
|
PERCENT_TOKENS = %w(
|
14
16
|
%union
|
15
17
|
%token
|
@@ -38,7 +40,8 @@ module Lrama
|
|
38
40
|
%rule
|
39
41
|
%no-stdlib
|
40
42
|
%inline
|
41
|
-
|
43
|
+
%locations
|
44
|
+
).freeze
|
42
45
|
|
43
46
|
def initialize(grammar_file)
|
44
47
|
@grammar_file = grammar_file
|
@@ -71,7 +74,7 @@ module Lrama
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def lex_token
|
74
|
-
|
77
|
+
until @scanner.eos? do
|
75
78
|
case
|
76
79
|
when @scanner.scan(/\n/)
|
77
80
|
newline
|
@@ -126,7 +129,7 @@ module Lrama
|
|
126
129
|
code = ''
|
127
130
|
reset_first_position
|
128
131
|
|
129
|
-
|
132
|
+
until @scanner.eos? do
|
130
133
|
case
|
131
134
|
when @scanner.scan(/{/)
|
132
135
|
code += @scanner.matched
|
@@ -163,7 +166,7 @@ module Lrama
|
|
163
166
|
private
|
164
167
|
|
165
168
|
def lex_comment
|
166
|
-
|
169
|
+
until @scanner.eos? do
|
167
170
|
case
|
168
171
|
when @scanner.scan(/\n/)
|
169
172
|
newline
|
@@ -1,25 +1,17 @@
|
|
1
|
-
|
2
|
-
class Warning
|
3
|
-
attr_reader :errors, :warns
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
3
|
+
module Lrama
|
4
|
+
class Logger
|
5
5
|
def initialize(out = STDERR)
|
6
6
|
@out = out
|
7
|
-
@errors = []
|
8
|
-
@warns = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def error(message)
|
12
|
-
@out << message << "\n"
|
13
|
-
@errors << message
|
14
7
|
end
|
15
8
|
|
16
9
|
def warn(message)
|
17
10
|
@out << message << "\n"
|
18
|
-
@warns << message
|
19
11
|
end
|
20
12
|
|
21
|
-
def
|
22
|
-
|
13
|
+
def error(message)
|
14
|
+
@out << message << "\n"
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
data/lib/lrama/option_parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'optparse'
|
2
4
|
|
3
5
|
module Lrama
|
@@ -16,7 +18,7 @@ module Lrama
|
|
16
18
|
@options.report_opts = validate_report(@report)
|
17
19
|
@options.grammar_file = argv.shift
|
18
20
|
|
19
|
-
|
21
|
+
unless @options.grammar_file
|
20
22
|
abort "File should be specified\n"
|
21
23
|
end
|
22
24
|
|
@@ -63,20 +65,35 @@ module Lrama
|
|
63
65
|
o.separator 'Output:'
|
64
66
|
o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v }
|
65
67
|
o.on('-d', 'also produce a header file') { @options.header = true }
|
66
|
-
o.on('-r', '--report=
|
68
|
+
o.on('-r', '--report=REPORTS', Array, 'also produce details on the automaton') {|v| @report = v }
|
67
69
|
o.on_tail ''
|
68
|
-
o.on_tail '
|
69
|
-
o.on_tail
|
70
|
-
|
70
|
+
o.on_tail 'REPORTS is a list of comma-separated words that can include:'
|
71
|
+
o.on_tail ' states describe the states'
|
72
|
+
o.on_tail ' itemsets complete the core item sets with their closure'
|
73
|
+
o.on_tail ' lookaheads explicitly associate lookahead tokens to items'
|
74
|
+
o.on_tail ' solved describe shift/reduce conflicts solving'
|
75
|
+
o.on_tail ' counterexamples, cex generate conflict counterexamples'
|
76
|
+
o.on_tail ' rules list unused rules'
|
77
|
+
o.on_tail ' terms list unused terminals'
|
78
|
+
o.on_tail ' verbose report detailed internal state and analysis results'
|
79
|
+
o.on_tail ' all include all the above reports'
|
80
|
+
o.on_tail ' none disable all reports'
|
71
81
|
o.on('--report-file=FILE', 'also produce details on the automaton output to a file named FILE') {|v| @options.report_file = v }
|
72
82
|
o.on('-o', '--output=FILE', 'leave output to FILE') {|v| @options.outfile = v }
|
73
|
-
|
74
|
-
o.on('--trace=THINGS', Array, 'also output trace logs at runtime') {|v| @trace = v }
|
83
|
+
o.on('--trace=TRACES', Array, 'also output trace logs at runtime') {|v| @trace = v }
|
75
84
|
o.on_tail ''
|
76
|
-
o.on_tail '
|
77
|
-
o.on_tail
|
78
|
-
|
79
|
-
o.
|
85
|
+
o.on_tail 'TRACES is a list of comma-separated words that can include:'
|
86
|
+
o.on_tail ' automaton display states'
|
87
|
+
o.on_tail ' closure display states'
|
88
|
+
o.on_tail ' rules display grammar rules'
|
89
|
+
o.on_tail ' actions display grammar rules with actions'
|
90
|
+
o.on_tail ' time display generation time'
|
91
|
+
o.on_tail ' all include all the above traces'
|
92
|
+
o.on_tail ' none disable all traces'
|
93
|
+
o.on('-v', '--verbose', "same as '--report=state'") {|_v| @report << 'states' }
|
94
|
+
o.separator ''
|
95
|
+
o.separator 'Diagnostics:'
|
96
|
+
o.on('-W', '--warnings', 'report the warnings') {|v| @options.diagnostic = true }
|
80
97
|
o.separator ''
|
81
98
|
o.separator 'Error Recovery:'
|
82
99
|
o.on('-e', 'enable error recovery') {|v| @options.error_recovery = true }
|
@@ -89,47 +106,55 @@ module Lrama
|
|
89
106
|
end
|
90
107
|
end
|
91
108
|
|
92
|
-
|
93
|
-
|
94
|
-
NOT_SUPPORTED_REPORTS = %w[cex none]
|
95
|
-
VALID_REPORTS = BISON_REPORTS + OTHER_REPORTS - NOT_SUPPORTED_REPORTS
|
109
|
+
ALIASED_REPORTS = { cex: :counterexamples }.freeze
|
110
|
+
VALID_REPORTS = %i[states itemsets lookaheads solved counterexamples rules terms verbose].freeze
|
96
111
|
|
97
112
|
def validate_report(report)
|
98
|
-
list = VALID_REPORTS
|
99
113
|
h = { grammar: true }
|
114
|
+
return h if report.empty?
|
115
|
+
return {} if report == ['none']
|
116
|
+
if report == ['all']
|
117
|
+
VALID_REPORTS.each { |r| h[r] = true }
|
118
|
+
return h
|
119
|
+
end
|
100
120
|
|
101
121
|
report.each do |r|
|
102
|
-
|
103
|
-
|
122
|
+
aliased = aliased_report_option(r)
|
123
|
+
if VALID_REPORTS.include?(aliased)
|
124
|
+
h[aliased] = true
|
104
125
|
else
|
105
126
|
raise "Invalid report option \"#{r}\"."
|
106
127
|
end
|
107
128
|
end
|
108
129
|
|
109
|
-
if h[:all]
|
110
|
-
(BISON_REPORTS - NOT_SUPPORTED_REPORTS).each do |r|
|
111
|
-
h[r.to_sym] = true
|
112
|
-
end
|
113
|
-
|
114
|
-
h.delete(:all)
|
115
|
-
end
|
116
|
-
|
117
130
|
return h
|
118
131
|
end
|
119
132
|
|
133
|
+
def aliased_report_option(opt)
|
134
|
+
(ALIASED_REPORTS[opt.to_sym] || opt).to_sym
|
135
|
+
end
|
136
|
+
|
120
137
|
VALID_TRACES = %w[
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
138
|
+
locations scan parse automaton bitsets closure
|
139
|
+
grammar rules actions resource sets muscles
|
140
|
+
tools m4-early m4 skeleton time ielr cex
|
141
|
+
].freeze
|
142
|
+
NOT_SUPPORTED_TRACES = %w[
|
143
|
+
locations scan parse bitsets grammar resource
|
144
|
+
sets muscles tools m4-early m4 skeleton ielr cex
|
145
|
+
].freeze
|
126
146
|
|
127
147
|
def validate_trace(trace)
|
128
|
-
list = VALID_TRACES
|
129
148
|
h = {}
|
149
|
+
return h if trace.empty? || trace == ['none']
|
150
|
+
supported = VALID_TRACES - NOT_SUPPORTED_TRACES
|
151
|
+
if trace == ['all']
|
152
|
+
supported.each { |t| h[t.to_sym] = true }
|
153
|
+
return h
|
154
|
+
end
|
130
155
|
|
131
156
|
trace.each do |t|
|
132
|
-
if
|
157
|
+
if supported.include?(t)
|
133
158
|
h[t.to_sym] = true
|
134
159
|
else
|
135
160
|
raise "Invalid trace option \"#{t}\"."
|
data/lib/lrama/options.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Lrama
|
2
4
|
# Command line options.
|
3
5
|
class Options
|
4
6
|
attr_accessor :skeleton, :header, :header_file,
|
5
7
|
:report_file, :outfile,
|
6
8
|
:error_recovery, :grammar_file,
|
7
|
-
:trace_opts, :report_opts,
|
8
|
-
:debug
|
9
|
+
:trace_opts, :report_opts,
|
10
|
+
:diagnostic, :y, :debug
|
9
11
|
|
10
12
|
def initialize
|
11
13
|
@skeleton = "bison/yacc.c"
|
@@ -17,6 +19,7 @@ module Lrama
|
|
17
19
|
@grammar_file = nil
|
18
20
|
@trace_opts = nil
|
19
21
|
@report_opts = nil
|
22
|
+
@diagnostic = false
|
20
23
|
@y = STDIN
|
21
24
|
@debug = false
|
22
25
|
end
|