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
@@ -1,34 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
# Builder for separated nonempty list of general parameterizing rules
|
6
|
-
class SeparatedNonemptyList < 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_nonempty_list(',', number)
|
15
|
-
#
|
16
|
-
# =>
|
17
|
-
#
|
18
|
-
# program: separated_nonempty_list_number
|
19
|
-
# separated_nonempty_list_number: number
|
20
|
-
# separated_nonempty_list_number: separated_nonempty_list_number ',' number
|
21
|
-
def build
|
22
|
-
validate_argument_number!
|
23
|
-
|
24
|
-
rules = []
|
25
|
-
@build_token = Lrama::Lexer::Token::Ident.new(s_value: "separated_nonempty_list_#{@token.s_value}")
|
26
|
-
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)
|
27
|
-
rules << Rule.new(id: @rule_counter.increment, _lhs: @build_token, _rhs: [@build_token, @separator, @token], lhs_tag: @lhs_tag, token_code: @user_code, precedence_sym: @precedence_sym, lineno: @line)
|
28
|
-
rules
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'lrama/grammar/parameterizing_rules/builder/base'
|
2
|
-
require 'lrama/grammar/parameterizing_rules/builder/list'
|
3
|
-
require 'lrama/grammar/parameterizing_rules/builder/nonempty_list'
|
4
|
-
require 'lrama/grammar/parameterizing_rules/builder/option'
|
5
|
-
require 'lrama/grammar/parameterizing_rules/builder/separated_nonempty_list'
|
6
|
-
require 'lrama/grammar/parameterizing_rules/builder/separated_list'
|
7
|
-
|
8
|
-
module Lrama
|
9
|
-
class Grammar
|
10
|
-
class ParameterizingRules
|
11
|
-
# Builder for parameterizing rules
|
12
|
-
class Builder
|
13
|
-
RULES = {
|
14
|
-
option: Lrama::Grammar::ParameterizingRules::Builder::Option,
|
15
|
-
"?": Lrama::Grammar::ParameterizingRules::Builder::Option,
|
16
|
-
nonempty_list: Lrama::Grammar::ParameterizingRules::Builder::NonemptyList,
|
17
|
-
"+": Lrama::Grammar::ParameterizingRules::Builder::NonemptyList,
|
18
|
-
list: Lrama::Grammar::ParameterizingRules::Builder::List,
|
19
|
-
"*": Lrama::Grammar::ParameterizingRules::Builder::List,
|
20
|
-
separated_nonempty_list: Lrama::Grammar::ParameterizingRules::Builder::SeparatedNonemptyList,
|
21
|
-
separated_list: Lrama::Grammar::ParameterizingRules::Builder::SeparatedList,
|
22
|
-
}
|
23
|
-
|
24
|
-
def initialize(token, rule_counter, lhs_tag, user_code, precedence_sym, line)
|
25
|
-
@token = token
|
26
|
-
@key = token.s_value.to_sym
|
27
|
-
@rule_counter = rule_counter
|
28
|
-
@lhs_tag = lhs_tag
|
29
|
-
@user_code = user_code
|
30
|
-
@precedence_sym = precedence_sym
|
31
|
-
@line = line
|
32
|
-
@builder = nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def build
|
36
|
-
create_builder
|
37
|
-
@builder.build
|
38
|
-
end
|
39
|
-
|
40
|
-
def build_token
|
41
|
-
create_builder
|
42
|
-
@builder.build_token
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def create_builder
|
48
|
-
unless @builder
|
49
|
-
validate_key!
|
50
|
-
@builder = RULES[@key].new(@token, @rule_counter, @lhs_tag, @user_code, @precedence_sym, @line)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def validate_key!
|
55
|
-
raise "Parameterizing rule does not exist. `#{@key}`" unless RULES.key?(@key)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
class Base
|
6
|
-
attr_reader build_token: Lexer::Token::Ident
|
7
|
-
|
8
|
-
def initialize: (Lexer::Token::InstantiateRule token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
9
|
-
def build: () -> Array[Rule]
|
10
|
-
|
11
|
-
@args: Array[Lexer::Token]
|
12
|
-
@token: Lexer::Token::InstantiateRule
|
13
|
-
@key: Symbol
|
14
|
-
@rule_counter: Counter
|
15
|
-
@lhs_tag: untyped
|
16
|
-
@user_code: Lexer::Token::UserCode?
|
17
|
-
@precedence_sym: Lexer::Token?
|
18
|
-
@line: Integer?
|
19
|
-
@expected_argument_num: Integer
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def validate_argument_number!: () -> void
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
class SeparatedList < Base
|
6
|
-
@separator: Lexer::Token
|
7
|
-
|
8
|
-
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
class SeparatedNonemptyList < Base
|
6
|
-
@separator: Lexer::Token
|
7
|
-
|
8
|
-
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Grammar
|
3
|
-
class ParameterizingRules
|
4
|
-
class Builder
|
5
|
-
RULES: Hash[Symbol, singleton(Base)]
|
6
|
-
|
7
|
-
@token: Lexer::Token::InstantiateRule
|
8
|
-
@key: Symbol
|
9
|
-
@rule_counter: Counter
|
10
|
-
@lhs_tag: untyped
|
11
|
-
@user_code: Lexer::Token::UserCode?
|
12
|
-
@precedence_sym: Lexer::Token?
|
13
|
-
@line: Integer?
|
14
|
-
@builder: Grammar::ParameterizingRules::Builder::Base
|
15
|
-
|
16
|
-
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
17
|
-
def build: () -> Array[Rule]
|
18
|
-
def build_token: () -> Lexer::Token
|
19
|
-
def create_builder: () -> void
|
20
|
-
def validate_key!: () -> void
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|