lrama 0.6.9 → 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 +5 -2
- data/lib/lrama/grammar/parameterizing_rule/rule.rb +6 -0
- 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 +64 -65
- 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 +110 -229
- 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 +1 -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
@@ -2,12 +2,13 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class ParameterizingRule
|
4
4
|
class Resolver
|
5
|
+
attr_accessor rules: Array[Grammar::ParameterizingRule::Rule]
|
5
6
|
attr_accessor created_lhs_list: Array[Lexer::Token]
|
6
7
|
|
7
8
|
@rules: Array[Grammar::ParameterizingRule::Rule]
|
8
9
|
|
9
10
|
def initialize: () -> void
|
10
|
-
def add_parameterizing_rule: (Grammar::ParameterizingRule::Rule rule) ->
|
11
|
+
def add_parameterizing_rule: (Grammar::ParameterizingRule::Rule rule) -> Array[Grammar::ParameterizingRule::Rule]
|
11
12
|
def find_rule: (Lexer::Token::InstantiateRule token) -> Grammar::ParameterizingRule::Rule?
|
12
13
|
def find_inline: (Lexer::Token token) -> Grammar::ParameterizingRule::Rule?
|
13
14
|
def created_lhs: (String lhs_s_value) -> Lexer::Token?
|
@@ -4,7 +4,7 @@ module Lrama
|
|
4
4
|
class Rhs
|
5
5
|
attr_reader symbols: Array[untyped]
|
6
6
|
attr_reader user_code: Lexer::Token::UserCode?
|
7
|
-
attr_reader precedence_sym:
|
7
|
+
attr_reader precedence_sym: Grammar::Symbol?
|
8
8
|
|
9
9
|
def initialize: () -> void
|
10
10
|
def resolve_user_code: (Grammar::Binding bindings) -> Lexer::Token::UserCode?
|
@@ -2,9 +2,11 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class Precedence
|
4
4
|
include Comparable
|
5
|
-
attr_accessor type: Symbol
|
5
|
+
attr_accessor type: ::Symbol
|
6
6
|
attr_accessor precedence: Integer
|
7
7
|
|
8
|
+
def initialize: (?type: ::Symbol, ?precedence: Integer) -> void
|
9
|
+
|
8
10
|
def <=>: (Precedence other) -> Integer
|
9
11
|
end
|
10
12
|
end
|
@@ -5,7 +5,9 @@ module Lrama
|
|
5
5
|
attr_accessor token_code: Grammar::Code
|
6
6
|
attr_accessor lineno: Integer
|
7
7
|
|
8
|
-
def
|
8
|
+
def initialize: (?ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], ?token_code: Grammar::Code, ?lineno: Integer) -> void
|
9
|
+
|
10
|
+
def translated_code: (Lexer::Token::Tag tag) -> String
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/sig/lrama/grammar/rule.rbs
CHANGED
@@ -1,13 +1,45 @@
|
|
1
1
|
module Lrama
|
2
2
|
class Grammar
|
3
3
|
class Rule
|
4
|
+
attr_accessor id: Integer
|
5
|
+
attr_accessor _lhs: Lexer::Token
|
6
|
+
attr_accessor lhs: Grammar::Symbol
|
7
|
+
attr_accessor lhs_tag: Lexer::Token::Tag?
|
8
|
+
attr_accessor _rhs: Array[Lexer::Token]
|
9
|
+
attr_accessor rhs: Array[Grammar::Symbol]
|
10
|
+
attr_accessor token_code: Grammar::Code?
|
11
|
+
attr_accessor position_in_original_rule_rhs: Integer
|
12
|
+
attr_accessor nullable: bool
|
13
|
+
attr_accessor precedence_sym: Grammar::Symbol?
|
14
|
+
attr_accessor lineno: Integer?
|
4
15
|
attr_accessor original_rule: Rule
|
5
16
|
|
6
17
|
def initialize: (
|
7
|
-
?id:
|
8
|
-
?token_code:
|
9
|
-
?precedence_sym:
|
18
|
+
?id: Integer, ?_lhs: Lexer::Token, ?lhs: Lexer::Token, ?lhs_tag: Lexer::Token::Tag?, ?_rhs: Array[Lexer::Token], ?rhs: Array[Grammar::Symbol],
|
19
|
+
?token_code: Lexer::Token::UserCode?, ?position_in_original_rule_rhs: Integer?, ?nullable: bool,
|
20
|
+
?precedence_sym: Grammar::Symbol?, ?lineno: Integer?
|
10
21
|
) -> void
|
22
|
+
|
23
|
+
def display_name: () -> String
|
24
|
+
|
25
|
+
def as_comment: -> String
|
26
|
+
|
27
|
+
def empty_rule?: -> bool
|
28
|
+
|
29
|
+
def initial_rule?: -> bool
|
30
|
+
|
31
|
+
def precedence: -> Precedence?
|
32
|
+
|
33
|
+
def translated_code: -> String?
|
34
|
+
|
35
|
+
def with_actions: -> String
|
36
|
+
|
37
|
+
def contains_at_reference?: -> bool
|
38
|
+
|
39
|
+
interface _DelegatedMethods
|
40
|
+
def lhs: -> Grammar::Symbol
|
41
|
+
def rhs: -> Array[Grammar::Symbol]
|
42
|
+
end
|
11
43
|
end
|
12
44
|
end
|
13
45
|
end
|
@@ -6,28 +6,29 @@ module Lrama
|
|
6
6
|
attr_reader lhs_tag: Lexer::Token::Tag?
|
7
7
|
attr_reader rhs: Array[Lexer::Token]
|
8
8
|
attr_reader user_code: Lexer::Token::UserCode?
|
9
|
-
attr_reader precedence_sym:
|
9
|
+
attr_reader precedence_sym: Grammar::Symbol?
|
10
10
|
|
11
11
|
@rule_counter: Counter
|
12
12
|
@midrule_action_counter: Counter
|
13
|
+
@parameterizing_rule_resolver: Grammar::ParameterizingRule::Resolver
|
13
14
|
@position_in_original_rule_rhs: Integer?
|
14
15
|
@skip_preprocess_references: bool
|
15
16
|
@user_code: Lexer::Token::UserCode?
|
16
17
|
@rule_builders_for_parameterizing_rules: Array[RuleBuilder]
|
17
18
|
@rule_builders_for_derived_rules: Array[RuleBuilder]
|
18
|
-
@rule_builders_for_inline_rules: Array[RuleBuilder]
|
19
19
|
@rules: Array[Rule]
|
20
20
|
@replaced_rhs: Array[Lexer::Token]
|
21
21
|
@parameterizing_rules: Array[Rule]
|
22
|
-
@inline_rules: Array[Rule]
|
23
22
|
@midrule_action_rules: Array[Rule]
|
24
23
|
|
25
|
-
def initialize: (Counter rule_counter, Counter midrule_action_counter, ?Integer position_in_original_rule_rhs, ?lhs_tag: Lexer::Token::Tag?, ?skip_preprocess_references: bool) -> void
|
24
|
+
def initialize: (Counter rule_counter, Counter midrule_action_counter, Grammar::ParameterizingRule::Resolver parameterizing_rule_resolver, ?Integer position_in_original_rule_rhs, ?lhs_tag: Lexer::Token::Tag?, ?skip_preprocess_references: bool) -> void
|
26
25
|
def add_rhs: (Lexer::Token rhs) -> void
|
26
|
+
def has_inline_rules?: -> bool
|
27
|
+
def resolve_inline_rules: -> Array[RuleBuilder]
|
27
28
|
def user_code=: (Lexer::Token::UserCode? user_code) -> void
|
28
|
-
def precedence_sym=: (
|
29
|
+
def precedence_sym=: (Grammar::Symbol? precedence_sym) -> void
|
29
30
|
def complete_input: () -> void
|
30
|
-
def setup_rules: (
|
31
|
+
def setup_rules: () -> void
|
31
32
|
def rules: () -> Array[Rule]
|
32
33
|
|
33
34
|
private
|
@@ -35,10 +36,10 @@ module Lrama
|
|
35
36
|
def freeze_rhs: () -> void
|
36
37
|
def preprocess_references: () -> void
|
37
38
|
def build_rules: () -> void
|
38
|
-
def process_rhs: (
|
39
|
+
def process_rhs: () -> void
|
39
40
|
def lhs_s_value: (Lexer::Token::InstantiateRule token, Grammar::Binding bindings) -> String
|
40
|
-
def resolve_inline: (
|
41
|
-
def resolve_inline_rhs: (RuleBuilder rule_builder, Grammar::ParameterizingRule::Rhs inline_rhs, Integer index) -> void
|
41
|
+
def resolve_inline: () -> void
|
42
|
+
def resolve_inline_rhs: (RuleBuilder rule_builder, Grammar::ParameterizingRule::Rhs inline_rhs, Integer index, ?Binding bindings) -> void
|
42
43
|
def replace_inline_user_code: (Grammar::ParameterizingRule::Rhs inline_rhs, Integer index) -> Lexer::Token::UserCode?
|
43
44
|
def numberize_references: () -> void
|
44
45
|
def flush_user_code: () -> void
|
@@ -4,7 +4,7 @@ module Lrama
|
|
4
4
|
attr_accessor id: Lexer::Token
|
5
5
|
attr_accessor alias_name: String?
|
6
6
|
attr_accessor number: Integer
|
7
|
-
attr_accessor tag: Lexer::Token?
|
7
|
+
attr_accessor tag: Lexer::Token::Tag?
|
8
8
|
attr_accessor term: bool
|
9
9
|
attr_accessor token_id: Integer
|
10
10
|
attr_accessor nullable: bool
|
@@ -13,12 +13,12 @@ module Lrama
|
|
13
13
|
attr_accessor destructor: Destructor?
|
14
14
|
attr_accessor error_token: ErrorToken
|
15
15
|
|
16
|
-
attr_accessor first_set: Set[Array[Symbol]]
|
16
|
+
attr_accessor first_set: Set[Array[Symbol]] | Set[Symbol]
|
17
17
|
attr_accessor first_set_bitmap: Integer
|
18
|
-
attr_writer eof_symbol:
|
19
|
-
attr_writer error_symbol:
|
20
|
-
attr_writer undef_symbol:
|
21
|
-
attr_writer accept_symbol:
|
18
|
+
attr_writer eof_symbol: bool
|
19
|
+
attr_writer error_symbol: bool
|
20
|
+
attr_writer undef_symbol: bool
|
21
|
+
attr_writer accept_symbol: bool
|
22
22
|
|
23
23
|
def initialize: (
|
24
24
|
id: Lexer::Token, term: bool, ?alias_name: String?, ?number: Integer?, ?tag: Lexer::Token?,
|
@@ -11,9 +11,9 @@ module Lrama
|
|
11
11
|
|
12
12
|
def initialize: () -> void
|
13
13
|
def symbols: () -> Array[Grammar::Symbol]
|
14
|
-
def sort_by_number!: () ->
|
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
|
14
|
+
def sort_by_number!: () -> Array[Grammar::Symbol]
|
15
|
+
def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
|
16
|
+
def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?) -> Grammar::Symbol
|
17
17
|
def find_symbol_by_s_value: (Grammar::Symbol s_value) -> Grammar::Symbol?
|
18
18
|
def find_symbol_by_s_value!: (Grammar::Symbol s_value) -> Grammar::Symbol
|
19
19
|
def find_symbol_by_id: (Lexer::Token id) -> Grammar::Symbol?
|
@@ -21,6 +21,7 @@ module Lrama
|
|
21
21
|
def find_symbol_by_token_id: (Integer token_id) -> Grammar::Symbol?
|
22
22
|
def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
|
23
23
|
def fill_symbol_number: () -> void
|
24
|
+
def fill_destructor: (Array[Destructor] destructors) -> (Array[Grammar::Symbol] | bot)
|
24
25
|
def fill_nterm_type: (Array[Grammar::Type] types) -> void
|
25
26
|
def fill_printer: (Array[Grammar::Printer] printers) -> void
|
26
27
|
def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
|
@@ -36,6 +37,24 @@ module Lrama
|
|
36
37
|
def validate_number_uniqueness!: () -> void
|
37
38
|
def validate_alias_name_uniqueness!: () -> void
|
38
39
|
end
|
40
|
+
|
41
|
+
interface _DelegatedMethods
|
42
|
+
def symbols: () -> Array[Grammar::Symbol]
|
43
|
+
def nterms: () -> Array[Grammar::Symbol]
|
44
|
+
def terms: () -> Array[Grammar::Symbol]
|
45
|
+
def add_nterm: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?) -> Grammar::Symbol
|
46
|
+
def add_term: (id: Lexer::Token, ?alias_name: String?, ?tag: Lexer::Token::Tag?, ?token_id: Integer?, ?replace: bool) -> Grammar::Symbol
|
47
|
+
def find_symbol_by_number!: (Integer number) -> Grammar::Symbol
|
48
|
+
def find_symbol_by_id!: (Lexer::Token id) -> Grammar::Symbol
|
49
|
+
def token_to_symbol: (Lexer::Token token) -> Grammar::Symbol
|
50
|
+
def find_symbol_by_s_value!: (Grammar::Symbol s_value) -> Grammar::Symbol
|
51
|
+
def fill_nterm_type: (Array[Grammar::Type] types) -> void
|
52
|
+
def fill_symbol_number: () -> void
|
53
|
+
def fill_printer: (Array[Grammar::Printer] printers) -> void
|
54
|
+
def fill_destructor: (Array[Destructor] destructors) -> (Destructor | bot)
|
55
|
+
def fill_error_token: (Array[Grammar::ErrorToken] error_tokens) -> void
|
56
|
+
def sort_by_number!: () -> Array[Grammar::Symbol]
|
57
|
+
end
|
39
58
|
end
|
40
59
|
end
|
41
60
|
end
|
data/sig/lrama/grammar/type.rbs
CHANGED
@@ -2,9 +2,9 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class Type
|
4
4
|
attr_reader id: Lexer::Token
|
5
|
-
attr_reader tag: Lexer::Token
|
5
|
+
attr_reader tag: Lexer::Token::Tag
|
6
6
|
|
7
|
-
def initialize: (id: Lexer::Token, tag: Lexer::Token) -> void
|
7
|
+
def initialize: (id: Lexer::Token, tag: Lexer::Token::Tag) -> void
|
8
8
|
def ==: (Grammar::Type other) -> bool
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Union
|
4
|
+
attr_accessor code: Grammar::Code::NoReferenceCode
|
5
|
+
attr_accessor lineno: Integer
|
6
|
+
|
7
|
+
def initialize: (code: Grammar::Code::NoReferenceCode, lineno: Integer) -> void
|
8
|
+
|
9
|
+
def braces_less_code: () -> String
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/sig/lrama/grammar.rbs
CHANGED
@@ -1,5 +1,95 @@
|
|
1
1
|
module Lrama
|
2
2
|
class Grammar
|
3
|
-
|
3
|
+
include Symbols::_DelegatedMethods
|
4
|
+
|
5
|
+
@rule_counter: Counter
|
6
|
+
@percent_codes: Array[PercentCode]
|
7
|
+
@printers: Array[Printer]
|
8
|
+
@destructors: Array[Destructor]
|
9
|
+
@error_tokens: Array[ErrorToken]
|
10
|
+
@symbols_resolver: Symbols::Resolver
|
11
|
+
@types: Array[Type]
|
12
|
+
@rule_builders: Array[RuleBuilder]
|
13
|
+
@rules: Array[Rule]
|
14
|
+
@sym_to_rules: Hash[Integer, Array[Rule]]
|
15
|
+
@parameterizing_rule_resolver: ParameterizingRule::Resolver
|
16
|
+
@empty_symbol: Grammar::Symbol
|
17
|
+
@eof_symbol: Grammar::Symbol
|
18
|
+
@error_symbol: Grammar::Symbol
|
19
|
+
@undef_symbol: Grammar::Symbol
|
20
|
+
@accept_symbol: Grammar::Symbol
|
21
|
+
@aux: Auxiliary
|
22
|
+
@no_stdlib: bool
|
23
|
+
@locations: bool
|
24
|
+
@union: Union
|
25
|
+
|
26
|
+
extend Forwardable
|
27
|
+
|
28
|
+
attr_reader percent_codes: Array[PercentCode]
|
29
|
+
attr_reader eof_symbol: Grammar::Symbol
|
30
|
+
attr_reader error_symbol: Grammar::Symbol
|
31
|
+
attr_reader undef_symbol: Grammar::Symbol
|
32
|
+
attr_reader accept_symbol: Grammar::Symbol
|
33
|
+
attr_reader aux: Auxiliary
|
34
|
+
attr_accessor union: Union
|
35
|
+
attr_accessor expect: Integer
|
36
|
+
attr_accessor printers: Array[Printer]
|
37
|
+
attr_accessor error_tokens: Array[ErrorToken]
|
38
|
+
attr_accessor lex_param: String
|
39
|
+
attr_accessor parse_param: String
|
40
|
+
attr_accessor initial_action: Grammar::Code::InitialActionCode
|
41
|
+
attr_accessor after_shift: Lexer::Token
|
42
|
+
attr_accessor before_reduce: Lexer::Token
|
43
|
+
attr_accessor after_reduce: Lexer::Token
|
44
|
+
attr_accessor after_shift_error_token: Lexer::Token
|
45
|
+
attr_accessor after_pop_stack: Lexer::Token
|
46
|
+
attr_accessor symbols_resolver: Symbols::Resolver
|
47
|
+
attr_accessor types: Array[Type]
|
48
|
+
attr_accessor rules: Array[Rule]
|
49
|
+
attr_accessor rule_builders: Array[RuleBuilder]
|
50
|
+
attr_accessor sym_to_rules: Hash[Integer, Array[Rule]]
|
51
|
+
attr_accessor no_stdlib: bool
|
52
|
+
|
53
|
+
def initialize: (Counter rule_counter) -> void
|
54
|
+
def create_rule_builder: (Counter rule_counter, Counter midrule_action_counter) -> RuleBuilder
|
55
|
+
def add_percent_code: (id: Lexer::Token, code: Lexer::Token::UserCode) -> Array[PercentCode]
|
56
|
+
def add_destructor: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[Destructor]
|
57
|
+
def add_printer: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[Printer]
|
58
|
+
def add_error_token: (ident_or_tags: Array[Lexer::Token::Ident|Lexer::Token::Tag], token_code: Code, lineno: Integer) -> Array[ErrorToken]
|
59
|
+
def add_type: (id: Lexer::Token, tag: Lexer::Token::Tag) -> Array[Type]
|
60
|
+
def add_nonassoc: (Grammar::Symbol sym, Integer precedence) -> Precedence
|
61
|
+
def add_left: (Grammar::Symbol sym, Integer precedence) -> Precedence
|
62
|
+
def add_right: (Grammar::Symbol sym, Integer precedence) -> Precedence
|
63
|
+
def add_precedence: (Grammar::Symbol sym, Integer precedence) -> Precedence
|
64
|
+
def set_precedence: (Grammar::Symbol sym, Precedence precedence) -> (Precedence | bot)
|
65
|
+
def set_union: (Grammar::Code::NoReferenceCode code, Integer lineno) -> Union
|
66
|
+
def add_rule_builder: (RuleBuilder builder) -> Array[RuleBuilder]
|
67
|
+
def add_parameterizing_rule: (ParameterizingRule::Rule rule) -> Array[ParameterizingRule::Rule]
|
68
|
+
def parameterizing_rules: () -> Array[ParameterizingRule::Rule]
|
69
|
+
def insert_before_parameterizing_rules: (Array[ParameterizingRule::Rule] rules) -> Array[ParameterizingRule::Rule]
|
70
|
+
def prologue_first_lineno=: (Integer prologue_first_lineno) -> Integer
|
71
|
+
def prologue=: (String prologue) -> String
|
72
|
+
def epilogue_first_lineno=: (Integer epilogue_first_lineno) -> Integer
|
73
|
+
def epilogue=: (String epilogue) -> String
|
74
|
+
def prepare: () -> void
|
75
|
+
def validate!: () -> void
|
76
|
+
def find_rules_by_symbol!: (Grammar::Symbol sym) -> Array[Rule]
|
77
|
+
def find_rules_by_symbol: (Grammar::Symbol sym) -> Array[Rule]?
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def compute_nullable: () -> Array[Grammar::Symbol]
|
82
|
+
def compute_first_set: () -> Array[Grammar::Symbol]
|
83
|
+
def resolve_inline_rules: () -> void
|
84
|
+
def setup_rules: () -> Array[RuleBuilder]
|
85
|
+
def append_special_symbols: () -> Grammar::Symbol
|
86
|
+
def normalize_rules: () -> Array[Rule]
|
87
|
+
def collect_symbols: () -> Array[Lexer::Token]
|
88
|
+
def set_lhs_and_rhs: () -> void
|
89
|
+
def fill_default_precedence: () -> void
|
90
|
+
def fill_symbols: () -> Array[Grammar::Symbol]
|
91
|
+
def fill_sym_to_rules: () -> Array[Rule]
|
92
|
+
def validate_rule_lhs_is_nterm!: () -> void
|
93
|
+
def set_locations: () -> void
|
4
94
|
end
|
5
95
|
end
|
data/sig/lrama/options.rbs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Lrama
|
2
|
-
|
2
|
+
class Options
|
3
3
|
attr_accessor skeleton: String
|
4
4
|
attr_accessor header: bool
|
5
5
|
attr_accessor header_file: String?
|
@@ -9,9 +9,10 @@ module Lrama
|
|
9
9
|
attr_accessor grammar_file: String?
|
10
10
|
attr_accessor trace_opts: Hash[Symbol, bool]?
|
11
11
|
attr_accessor report_opts: Hash[Symbol, bool]?
|
12
|
+
attr_accessor diagnostic: bool
|
12
13
|
attr_accessor y: IO
|
13
14
|
attr_accessor debug: bool
|
14
15
|
|
15
16
|
def initialize: () -> void
|
16
|
-
|
17
|
+
end
|
17
18
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Lrama
|
2
|
+
class State
|
3
|
+
class Reduce
|
4
|
+
@item: States::Item
|
5
|
+
@look_ahead: Array[Grammar::Symbol]?
|
6
|
+
@not_selected_symbols: Array[Grammar::Symbol]
|
7
|
+
|
8
|
+
attr_reader item: States::Item
|
9
|
+
attr_reader look_ahead: Array[Grammar::Symbol]?
|
10
|
+
attr_reader not_selected_symbols: Array[Grammar::Symbol]
|
11
|
+
attr_accessor default_reduction: bool
|
12
|
+
|
13
|
+
def initialize: (States::Item item) -> void
|
14
|
+
def rule: -> Grammar::Rule
|
15
|
+
def look_ahead=: (Array[Grammar::Symbol] look_ahead) -> Array[Grammar::Symbol]
|
16
|
+
def add_not_selected_symbol: (Grammar::Symbol sym) -> Array[Grammar::Symbol]
|
17
|
+
def selected_look_ahead: () -> (::Array[Grammar::Symbol?])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Lrama
|
2
|
+
class State
|
3
|
+
class ReduceReduceConflict
|
4
|
+
attr_accessor symbols: Array[Grammar::Symbol?]
|
5
|
+
attr_accessor reduce1: State::Reduce
|
6
|
+
attr_accessor reduce2: State::Reduce
|
7
|
+
|
8
|
+
def initialize: (?symbols: Array[Grammar::Symbol?], ?reduce1: State::Reduce, ?reduce2: State::Reduce) -> void
|
9
|
+
|
10
|
+
def type: () -> :reduce_reduce
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lrama
|
2
|
+
class State
|
3
|
+
class ResolvedConflict
|
4
|
+
attr_accessor symbol: Grammar::Symbol
|
5
|
+
attr_accessor reduce: State::Reduce
|
6
|
+
attr_accessor which: (:reduce | :shift)
|
7
|
+
attr_accessor same_prec: bool
|
8
|
+
|
9
|
+
def initialize: (?symbol: Grammar::Symbol, ?reduce: State::Reduce, ?which: (:reduce | :shift), ?same_prec: bool) -> void
|
10
|
+
|
11
|
+
def report_message: () -> (::String | bot)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lrama
|
2
|
+
class State
|
3
|
+
class Shift
|
4
|
+
@next_sym: Grammar::Symbol
|
5
|
+
@next_items: Array[States::Item]
|
6
|
+
|
7
|
+
attr_reader next_sym: Grammar::Symbol
|
8
|
+
attr_reader next_items: Array[States::Item]
|
9
|
+
attr_accessor not_selected: bool
|
10
|
+
|
11
|
+
def initialize: (Grammar::Symbol next_sym, Array[States::Item] next_items) -> void
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Lrama
|
2
|
+
class State
|
3
|
+
class ShiftReduceConflict
|
4
|
+
attr_accessor symbols: Array[Grammar::Symbol]
|
5
|
+
attr_accessor shift: State::Shift
|
6
|
+
attr_accessor reduce: State::Reduce
|
7
|
+
|
8
|
+
def initialize: (?symbols: Array[Grammar::Symbol], ?shift: State::Shift, ?reduce: State::Reduce) -> void
|
9
|
+
|
10
|
+
def type: () -> :shift_reduce
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Lrama
|
2
|
+
class States
|
3
|
+
class Item
|
4
|
+
extend Forwardable
|
5
|
+
include Grammar::Rule::_DelegatedMethods
|
6
|
+
|
7
|
+
attr_accessor rule: Grammar::Rule
|
8
|
+
attr_accessor position: Integer
|
9
|
+
|
10
|
+
def initialize: (?rule: Grammar::Rule, ?position: Integer) -> void
|
11
|
+
|
12
|
+
def hash: () -> Integer
|
13
|
+
def rule_id: () -> Integer
|
14
|
+
def empty_rule?: () -> bool
|
15
|
+
def number_of_rest_symbols: () -> Integer
|
16
|
+
def next_sym: () -> Grammar::Symbol
|
17
|
+
def next_next_sym: () -> Grammar::Symbol
|
18
|
+
def previous_sym: () -> Grammar::Symbol
|
19
|
+
def end_of_rule?: () -> bool
|
20
|
+
def beginning_of_rule?: () -> bool
|
21
|
+
def start_item?: () -> bool
|
22
|
+
def new_by_next_position: () -> States::Item
|
23
|
+
def symbols_before_dot: () -> Array[Grammar::Symbol]
|
24
|
+
def symbols_after_dot: () -> Array[Grammar::Symbol]
|
25
|
+
def to_s: () -> ::String
|
26
|
+
def display_name: () -> ::String
|
27
|
+
def display_rest: () -> ::String
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/template/bison/yacc.c
CHANGED
@@ -1166,9 +1166,9 @@ yydestruct (const char *yymsg,
|
|
1166
1166
|
#endif
|
1167
1167
|
|
1168
1168
|
enum yy_repair_type {
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1169
|
+
inserting,
|
1170
|
+
deleting,
|
1171
|
+
shifting,
|
1172
1172
|
};
|
1173
1173
|
|
1174
1174
|
struct yy_repair {
|
@@ -1401,27 +1401,27 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar<%= output.user_formals
|
|
1401
1401
|
if (current->repair_length + 1 > YYMAXREPAIR(<%= output.parse_param_name %>))
|
1402
1402
|
continue;
|
1403
1403
|
|
1404
|
-
yy_repairs *
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
YYCOPY (
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1404
|
+
yy_repairs *reps = (yy_repairs *) YYMALLOC (sizeof (yy_repairs));
|
1405
|
+
reps->id = count;
|
1406
|
+
reps->next = 0;
|
1407
|
+
reps->stack_length = stack_length;
|
1408
|
+
reps->states = (yy_state_t *) YYMALLOC (sizeof (yy_state_t) * (stack_length));
|
1409
|
+
reps->state = reps->states + (current->state - current->states);
|
1410
|
+
YYCOPY (reps->states, current->states, current->state - current->states + 1);
|
1411
|
+
reps->repair_length = current->repair_length + 1;
|
1412
|
+
reps->prev_repair = current;
|
1413
|
+
reps->repair.type = inserting;
|
1414
|
+
reps->repair.term = (yysymbol_kind_t) yyx;
|
1415
1415
|
|
1416
1416
|
/* Process PDA assuming next token is yyx */
|
1417
|
-
if (! yy_process_repairs (
|
1417
|
+
if (! yy_process_repairs (reps, (yysymbol_kind_t)yyx))
|
1418
1418
|
{
|
1419
|
-
YYFREE (
|
1419
|
+
YYFREE (reps);
|
1420
1420
|
continue;
|
1421
1421
|
}
|
1422
1422
|
|
1423
|
-
tail->next =
|
1424
|
-
tail =
|
1423
|
+
tail->next = reps;
|
1424
|
+
tail = reps;
|
1425
1425
|
count++;
|
1426
1426
|
|
1427
1427
|
if (yyx == yytoken)
|
@@ -1437,7 +1437,7 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar<%= output.user_formals
|
|
1437
1437
|
YYDPRINTF ((stderr,
|
1438
1438
|
"New repairs is enqueued. count: %d, yystate: %d, yyx: %d\n",
|
1439
1439
|
count, yystate, yyx));
|
1440
|
-
yy_print_repairs (
|
1440
|
+
yy_print_repairs (reps<%= output.user_args %>);
|
1441
1441
|
}
|
1442
1442
|
}
|
1443
1443
|
}
|
@@ -1475,7 +1475,12 @@ int yychar;
|
|
1475
1475
|
/* The semantic value of the lookahead symbol. */
|
1476
1476
|
/* Default value used for initialization, for pacifying older GCCs
|
1477
1477
|
or non-GCC compilers. */
|
1478
|
+
#ifdef __cplusplus
|
1479
|
+
static const YYSTYPE yyval_default = {};
|
1480
|
+
(void) yyval_default;
|
1481
|
+
#else
|
1478
1482
|
YY_INITIAL_VALUE (static const YYSTYPE yyval_default;)
|
1483
|
+
#endif
|
1479
1484
|
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
|
1480
1485
|
|
1481
1486
|
/* Location data for the lookahead symbol. */
|
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.10
|
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-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: LALR (1) parser generator written by Ruby
|
14
14
|
email:
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/lrama/counterexamples/state_item.rb
|
46
46
|
- lib/lrama/counterexamples/transition_path.rb
|
47
47
|
- lib/lrama/counterexamples/triple.rb
|
48
|
+
- lib/lrama/diagnostics.rb
|
48
49
|
- lib/lrama/digraph.rb
|
49
50
|
- lib/lrama/grammar.rb
|
50
51
|
- lib/lrama/grammar/auxiliary.rb
|
@@ -74,6 +75,7 @@ files:
|
|
74
75
|
- lib/lrama/grammar/symbols/resolver.rb
|
75
76
|
- lib/lrama/grammar/type.rb
|
76
77
|
- lib/lrama/grammar/union.rb
|
78
|
+
- lib/lrama/grammar_validator.rb
|
77
79
|
- lib/lrama/lexer.rb
|
78
80
|
- lib/lrama/lexer/grammar_file.rb
|
79
81
|
- lib/lrama/lexer/location.rb
|
@@ -83,6 +85,7 @@ files:
|
|
83
85
|
- lib/lrama/lexer/token/instantiate_rule.rb
|
84
86
|
- lib/lrama/lexer/token/tag.rb
|
85
87
|
- lib/lrama/lexer/token/user_code.rb
|
88
|
+
- lib/lrama/logger.rb
|
86
89
|
- lib/lrama/option_parser.rb
|
87
90
|
- lib/lrama/options.rb
|
88
91
|
- lib/lrama/output.rb
|
@@ -99,22 +102,23 @@ files:
|
|
99
102
|
- lib/lrama/states.rb
|
100
103
|
- lib/lrama/states/item.rb
|
101
104
|
- lib/lrama/states_reporter.rb
|
105
|
+
- lib/lrama/trace_reporter.rb
|
102
106
|
- lib/lrama/version.rb
|
103
|
-
- lib/lrama/warning.rb
|
104
107
|
- lrama.gemspec
|
105
108
|
- parser.y
|
106
109
|
- rbs_collection.lock.yaml
|
107
110
|
- rbs_collection.yaml
|
108
|
-
- sample/calc.output
|
109
|
-
- sample/calc.y
|
110
|
-
- sample/parse.y
|
111
111
|
- sig/lrama/bitmap.rbs
|
112
112
|
- sig/lrama/digraph.rbs
|
113
113
|
- sig/lrama/grammar.rbs
|
114
|
+
- sig/lrama/grammar/auxiliary.rbs
|
114
115
|
- sig/lrama/grammar/binding.rbs
|
115
116
|
- sig/lrama/grammar/code.rbs
|
116
117
|
- sig/lrama/grammar/code/destructor_code.rbs
|
118
|
+
- sig/lrama/grammar/code/initial_action_code.rbs
|
119
|
+
- sig/lrama/grammar/code/no_reference_code.rbs
|
117
120
|
- sig/lrama/grammar/code/printer_code.rbs
|
121
|
+
- sig/lrama/grammar/code/rule_action.rbs
|
118
122
|
- sig/lrama/grammar/counter.rbs
|
119
123
|
- sig/lrama/grammar/destructor.rbs
|
120
124
|
- sig/lrama/grammar/error_token.rbs
|
@@ -131,6 +135,7 @@ files:
|
|
131
135
|
- sig/lrama/grammar/symbol.rbs
|
132
136
|
- sig/lrama/grammar/symbols/resolver.rbs
|
133
137
|
- sig/lrama/grammar/type.rbs
|
138
|
+
- sig/lrama/grammar/union.rbs
|
134
139
|
- sig/lrama/lexer/grammar_file.rbs
|
135
140
|
- sig/lrama/lexer/location.rbs
|
136
141
|
- sig/lrama/lexer/token.rbs
|
@@ -142,6 +147,12 @@ files:
|
|
142
147
|
- sig/lrama/options.rbs
|
143
148
|
- sig/lrama/report/duration.rbs
|
144
149
|
- sig/lrama/report/profile.rbs
|
150
|
+
- sig/lrama/state/reduce.rbs
|
151
|
+
- sig/lrama/state/reduce_reduce_conflict.rbs
|
152
|
+
- sig/lrama/state/resolved_conflict.rbs
|
153
|
+
- sig/lrama/state/shift.rbs
|
154
|
+
- sig/lrama/state/shift_reduce_conflict.rbs
|
155
|
+
- sig/lrama/states/item.rbs
|
145
156
|
- sig/lrama/warning.rbs
|
146
157
|
- sig/stdlib/strscan/string_scanner.rbs
|
147
158
|
- template/bison/_yacc.h
|