lrama 0.5.8 → 0.5.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 +6 -1
- data/.gitignore +7 -4
- data/Gemfile +10 -6
- data/README.md +3 -3
- data/Rakefile +15 -7
- data/Steepfile +15 -1
- data/lib/lrama/command.rb +6 -1
- data/lib/lrama/context.rb +1 -3
- data/lib/lrama/counterexamples/path.rb +0 -46
- data/lib/lrama/counterexamples/production_path.rb +17 -0
- data/lib/lrama/counterexamples/start_path.rb +21 -0
- data/lib/lrama/counterexamples/transition_path.rb +17 -0
- data/lib/lrama/counterexamples.rb +3 -0
- data/lib/lrama/grammar/code/initial_action_code.rb +28 -0
- data/lib/lrama/grammar/code/no_reference_code.rb +24 -0
- data/lib/lrama/grammar/code/printer_code.rb +34 -0
- data/lib/lrama/grammar/code/rule_action.rb +62 -0
- data/lib/lrama/grammar/code.rb +9 -93
- data/lib/lrama/grammar/counter.rb +15 -0
- data/lib/lrama/grammar/error_token.rb +3 -3
- data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +28 -0
- data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +20 -0
- data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +20 -0
- data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +20 -0
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +28 -0
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +27 -0
- data/lib/lrama/grammar/parameterizing_rules/builder.rb +43 -0
- data/lib/lrama/grammar/percent_code.rb +12 -0
- data/lib/lrama/grammar/printer.rb +3 -3
- data/lib/lrama/grammar/reference.rb +7 -16
- data/lib/lrama/grammar/rule.rb +18 -2
- data/lib/lrama/grammar/rule_builder.rb +179 -0
- data/lib/lrama/grammar/symbol.rb +2 -2
- data/lib/lrama/grammar.rb +132 -302
- data/lib/lrama/lexer/location.rb +22 -0
- data/lib/lrama/lexer/token/char.rb +8 -0
- data/lib/lrama/lexer/token/ident.rb +8 -0
- data/lib/lrama/lexer/token/parameterizing.rb +34 -0
- data/lib/lrama/lexer/token/tag.rb +12 -0
- data/lib/lrama/lexer/token/user_code.rb +64 -0
- data/lib/lrama/lexer/token.rb +23 -63
- data/lib/lrama/lexer.rb +38 -37
- data/lib/lrama/option_parser.rb +2 -1
- data/lib/lrama/options.rb +2 -2
- data/lib/lrama/output.rb +11 -2
- data/lib/lrama/parser.rb +607 -488
- data/lib/lrama/report/profile.rb +1 -12
- data/lib/lrama/version.rb +1 -1
- data/parser.y +177 -96
- data/rbs_collection.lock.yaml +17 -1
- data/rbs_collection.yaml +1 -0
- data/sample/calc.y +3 -1
- data/sample/parse.y +5 -1
- data/sig/lrama/grammar/code/printer_code.rbs +15 -0
- data/sig/lrama/grammar/code.rbs +24 -0
- data/sig/lrama/grammar/counter.rbs +11 -0
- data/sig/lrama/grammar/parameterizing_rules/builder.rbs +10 -0
- data/sig/lrama/grammar/percent_code.rbs +10 -0
- data/sig/lrama/grammar/precedence.rbs +11 -0
- data/sig/lrama/grammar/printer.rbs +11 -0
- data/sig/lrama/grammar/reference.rbs +22 -0
- data/sig/lrama/grammar/rule.rbs +13 -0
- data/sig/lrama/grammar/rule_builder.rbs +41 -0
- data/sig/lrama/grammar.rbs +5 -0
- data/sig/lrama/lexer/location.rbs +14 -0
- data/sig/lrama/lexer/token/char.rbs +8 -0
- data/sig/lrama/lexer/token/ident.rbs +8 -0
- data/sig/lrama/lexer/token/parameterizing.rbs +15 -0
- data/sig/lrama/lexer/token/tag.rbs +9 -0
- data/sig/lrama/lexer/token/user_code.rbs +16 -0
- data/sig/lrama/lexer/token.rbs +22 -0
- data/sig/stdlib/strscan/string_scanner.rbs +5 -0
- data/template/bison/_yacc.h +2 -2
- data/template/bison/yacc.c +5 -2
- metadata +44 -4
- data/lib/lrama/lexer/token/type.rb +0 -8
- data/sig/lrama/lexer/token/type.rbs +0 -17
@@ -0,0 +1,22 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Reference
|
4
|
+
attr_accessor type: Symbol
|
5
|
+
attr_accessor name: String
|
6
|
+
attr_accessor index: Integer
|
7
|
+
attr_accessor ex_tag: Lexer::Token?
|
8
|
+
attr_accessor first_column: Integer
|
9
|
+
attr_accessor last_column: Integer
|
10
|
+
attr_accessor position_in_rhs: Integer?
|
11
|
+
|
12
|
+
def initialize: (
|
13
|
+
type: Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
|
14
|
+
first_column: Integer, last_column: Integer,
|
15
|
+
?position_in_rhs: Integer?
|
16
|
+
) -> void
|
17
|
+
|
18
|
+
def value: () -> (String|Integer)
|
19
|
+
def tag: () -> untyped
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Rule
|
4
|
+
attr_accessor original_rule: Rule
|
5
|
+
|
6
|
+
def initialize: (
|
7
|
+
?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?_rhs: untyped, ?rhs: untyped,
|
8
|
+
?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped,
|
9
|
+
?precedence_sym: untyped, ?lineno: untyped
|
10
|
+
) -> void
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class RuleBuilder
|
4
|
+
attr_accessor lhs: Lexer::Token
|
5
|
+
attr_accessor line: Integer?
|
6
|
+
attr_reader rhs: Array[Lexer::Token]
|
7
|
+
attr_reader user_code: Lexer::Token::UserCode?
|
8
|
+
attr_reader precedence_sym: Lexer::Token?
|
9
|
+
|
10
|
+
@rule_counter: Counter
|
11
|
+
@midrule_action_counter: Counter
|
12
|
+
@position_in_original_rule_rhs: Integer?
|
13
|
+
@skip_preprocess_references: bool
|
14
|
+
@user_code: Lexer::Token::UserCode?
|
15
|
+
@rule_builders_for_derived_rules: Array[RuleBuilder]
|
16
|
+
@rules: Array[Rule]
|
17
|
+
@replaced_rhs: Array[Lexer::Token]
|
18
|
+
@parameterizing_rules: Array[Rule]
|
19
|
+
@midrule_action_rules: Array[Rule]
|
20
|
+
|
21
|
+
def initialize: (Counter rule_counter, Counter midrule_action_counter, ?Integer position_in_original_rule_rhs, ?skip_preprocess_references: bool) -> void
|
22
|
+
def add_rhs: (Lexer::Token rhs) -> void
|
23
|
+
def user_code=: (Lexer::Token::UserCode user_code) -> void
|
24
|
+
def precedence_sym=: (Lexer::Token user_code) -> void
|
25
|
+
def complete_input: () -> void
|
26
|
+
def setup_rules: () -> void
|
27
|
+
def parameterizing_rules: () -> Array[Rule]
|
28
|
+
def midrule_action_rules: () -> Array[Rule]
|
29
|
+
def rules: () -> Array[Rule]
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def freeze_rhs: () -> void
|
34
|
+
def preprocess_references: () -> void
|
35
|
+
def build_rules: () -> void
|
36
|
+
def process_rhs: () -> void
|
37
|
+
def numberize_references: () -> void
|
38
|
+
def flush_user_code: () -> void
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Lexer
|
3
|
+
class Location
|
4
|
+
attr_reader first_line: Integer
|
5
|
+
attr_reader first_column: Integer
|
6
|
+
attr_reader last_line: Integer
|
7
|
+
attr_reader last_column: Integer
|
8
|
+
|
9
|
+
def initialize: (first_line: Integer, first_column: Integer, last_line: Integer, last_column: Integer) -> void
|
10
|
+
|
11
|
+
def ==: (Location other) -> bool
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Lexer
|
3
|
+
class Token
|
4
|
+
class Parameterizing < Token
|
5
|
+
attr_accessor args: Array[Lrama::Lexer::Token]
|
6
|
+
|
7
|
+
def option?: () -> bool
|
8
|
+
def nonempty_list?: () -> bool
|
9
|
+
def list?: () -> bool
|
10
|
+
def separated_nonempty_list?: () -> bool
|
11
|
+
def separated_list?: () -> bool
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Lexer
|
3
|
+
class Token
|
4
|
+
class UserCode < Token
|
5
|
+
@references: Array[Lrama::Grammar::Reference]
|
6
|
+
|
7
|
+
def references: () -> Array[Lrama::Grammar::Reference]
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def _references: () -> Array[Lrama::Grammar::Reference]
|
12
|
+
def scan_reference: (StringScanner scanner) -> Lrama::Grammar::Reference?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Lexer
|
3
|
+
class Token
|
4
|
+
attr_accessor s_value: String
|
5
|
+
attr_accessor alias_name: String
|
6
|
+
attr_accessor location: Location
|
7
|
+
attr_accessor referred: bool
|
8
|
+
|
9
|
+
def initialize: (?s_value: String, ?alias_name: String, ?location: Location) -> void
|
10
|
+
|
11
|
+
def to_s: () -> String
|
12
|
+
def referred_by?: (String string) -> bool
|
13
|
+
def ==: (Token other) -> bool
|
14
|
+
def first_line: () -> Integer
|
15
|
+
def first_column: () -> Integer
|
16
|
+
def last_line: () -> Integer
|
17
|
+
def last_column: () -> Integer
|
18
|
+
alias line first_line
|
19
|
+
alias column first_column
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/template/bison/_yacc.h
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
#if YYDEBUG && !defined(yydebug)
|
13
13
|
extern int yydebug;
|
14
14
|
#endif
|
15
|
-
|
15
|
+
<%= output.percent_code("requires") %>
|
16
16
|
|
17
17
|
<%-# b4_token_enums_defines -%>
|
18
18
|
/* Token kinds. */
|
@@ -64,7 +64,7 @@ struct YYLTYPE
|
|
64
64
|
int yyparse (<%= output.parse_param %>);
|
65
65
|
|
66
66
|
|
67
|
-
|
67
|
+
<%= output.percent_code("provides") %>
|
68
68
|
<%-# b4_cpp_guard_close([b4_spec_mapped_header_file]) -%>
|
69
69
|
<%- if output.spec_mapped_header_file -%>
|
70
70
|
#endif /* !<%= output.b4_cpp_guard__b4_spec_mapped_header_file %> */
|
data/template/bison/yacc.c
CHANGED
@@ -68,14 +68,14 @@
|
|
68
68
|
#define YYPULL 1
|
69
69
|
|
70
70
|
|
71
|
-
|
72
|
-
|
73
71
|
<%# b4_user_pre_prologue -%>
|
72
|
+
<%- if output.aux.prologue -%>
|
74
73
|
/* First part of user prologue. */
|
75
74
|
#line <%= output.aux.prologue_first_lineno %> "<%= output.grammar_file_path %>"
|
76
75
|
|
77
76
|
<%= output.aux.prologue %>
|
78
77
|
#line [@oline@] [@ofile@]
|
78
|
+
<%- end -%>
|
79
79
|
|
80
80
|
<%# b4_cast_define -%>
|
81
81
|
# ifndef YY_CAST
|
@@ -1485,6 +1485,7 @@ YYLTYPE yylloc = yyloc_default;
|
|
1485
1485
|
<%# b4_declare_parser_state_variables -%>
|
1486
1486
|
/* Number of syntax errors so far. */
|
1487
1487
|
int yynerrs = 0;
|
1488
|
+
YY_USE (yynerrs); /* Silence compiler warning. */
|
1488
1489
|
|
1489
1490
|
yy_state_fast_t yystate = 0;
|
1490
1491
|
/* Number of tokens to shift before error messages enabled. */
|
@@ -2045,7 +2046,9 @@ yyreturnlab:
|
|
2045
2046
|
}
|
2046
2047
|
|
2047
2048
|
<%# b4_percent_code_get([[epilogue]]) -%>
|
2049
|
+
<%- if output.aux.epilogue -%>
|
2048
2050
|
#line <%= output.aux.epilogue_first_lineno - 1 %> "<%= output.grammar_file_path %>"
|
2049
2051
|
|
2050
2052
|
<%= output.aux.epilogue -%>
|
2053
|
+
<%- end -%>
|
2051
2054
|
|
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.5.
|
4
|
+
version: 0.5.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: 2023-
|
11
|
+
date: 2023-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: LALR (1) parser generator written by Ruby
|
14
14
|
email:
|
@@ -40,22 +40,44 @@ files:
|
|
40
40
|
- lib/lrama/counterexamples/derivation.rb
|
41
41
|
- lib/lrama/counterexamples/example.rb
|
42
42
|
- lib/lrama/counterexamples/path.rb
|
43
|
+
- lib/lrama/counterexamples/production_path.rb
|
44
|
+
- lib/lrama/counterexamples/start_path.rb
|
43
45
|
- lib/lrama/counterexamples/state_item.rb
|
46
|
+
- lib/lrama/counterexamples/transition_path.rb
|
44
47
|
- lib/lrama/counterexamples/triple.rb
|
45
48
|
- lib/lrama/digraph.rb
|
46
49
|
- lib/lrama/grammar.rb
|
47
50
|
- lib/lrama/grammar/auxiliary.rb
|
48
51
|
- lib/lrama/grammar/code.rb
|
52
|
+
- lib/lrama/grammar/code/initial_action_code.rb
|
53
|
+
- lib/lrama/grammar/code/no_reference_code.rb
|
54
|
+
- lib/lrama/grammar/code/printer_code.rb
|
55
|
+
- lib/lrama/grammar/code/rule_action.rb
|
56
|
+
- lib/lrama/grammar/counter.rb
|
49
57
|
- lib/lrama/grammar/error_token.rb
|
58
|
+
- lib/lrama/grammar/parameterizing_rules/builder.rb
|
59
|
+
- lib/lrama/grammar/parameterizing_rules/builder/base.rb
|
60
|
+
- lib/lrama/grammar/parameterizing_rules/builder/list.rb
|
61
|
+
- lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb
|
62
|
+
- lib/lrama/grammar/parameterizing_rules/builder/option.rb
|
63
|
+
- lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb
|
64
|
+
- lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb
|
65
|
+
- lib/lrama/grammar/percent_code.rb
|
50
66
|
- lib/lrama/grammar/precedence.rb
|
51
67
|
- lib/lrama/grammar/printer.rb
|
52
68
|
- lib/lrama/grammar/reference.rb
|
53
69
|
- lib/lrama/grammar/rule.rb
|
70
|
+
- lib/lrama/grammar/rule_builder.rb
|
54
71
|
- lib/lrama/grammar/symbol.rb
|
55
72
|
- lib/lrama/grammar/union.rb
|
56
73
|
- lib/lrama/lexer.rb
|
74
|
+
- lib/lrama/lexer/location.rb
|
57
75
|
- lib/lrama/lexer/token.rb
|
58
|
-
- lib/lrama/lexer/token/
|
76
|
+
- lib/lrama/lexer/token/char.rb
|
77
|
+
- lib/lrama/lexer/token/ident.rb
|
78
|
+
- lib/lrama/lexer/token/parameterizing.rb
|
79
|
+
- lib/lrama/lexer/token/tag.rb
|
80
|
+
- lib/lrama/lexer/token/user_code.rb
|
59
81
|
- lib/lrama/option_parser.rb
|
60
82
|
- lib/lrama/options.rb
|
61
83
|
- lib/lrama/output.rb
|
@@ -84,10 +106,28 @@ files:
|
|
84
106
|
- sample/parse.y
|
85
107
|
- sig/lrama/bitmap.rbs
|
86
108
|
- sig/lrama/digraph.rbs
|
87
|
-
- sig/lrama/
|
109
|
+
- sig/lrama/grammar.rbs
|
110
|
+
- sig/lrama/grammar/code.rbs
|
111
|
+
- sig/lrama/grammar/code/printer_code.rbs
|
112
|
+
- sig/lrama/grammar/counter.rbs
|
113
|
+
- sig/lrama/grammar/parameterizing_rules/builder.rbs
|
114
|
+
- sig/lrama/grammar/percent_code.rbs
|
115
|
+
- sig/lrama/grammar/precedence.rbs
|
116
|
+
- sig/lrama/grammar/printer.rbs
|
117
|
+
- sig/lrama/grammar/reference.rbs
|
118
|
+
- sig/lrama/grammar/rule.rbs
|
119
|
+
- sig/lrama/grammar/rule_builder.rbs
|
120
|
+
- sig/lrama/lexer/location.rbs
|
121
|
+
- sig/lrama/lexer/token.rbs
|
122
|
+
- sig/lrama/lexer/token/char.rbs
|
123
|
+
- sig/lrama/lexer/token/ident.rbs
|
124
|
+
- sig/lrama/lexer/token/parameterizing.rbs
|
125
|
+
- sig/lrama/lexer/token/tag.rbs
|
126
|
+
- sig/lrama/lexer/token/user_code.rbs
|
88
127
|
- sig/lrama/report/duration.rbs
|
89
128
|
- sig/lrama/report/profile.rbs
|
90
129
|
- sig/lrama/warning.rbs
|
130
|
+
- sig/stdlib/strscan/string_scanner.rbs
|
91
131
|
- template/bison/_yacc.h
|
92
132
|
- template/bison/yacc.c
|
93
133
|
- template/bison/yacc.h
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Lrama
|
2
|
-
class Lexer
|
3
|
-
class Token
|
4
|
-
attr_accessor type: Type
|
5
|
-
attr_accessor s_value: String
|
6
|
-
attr_accessor alias: String
|
7
|
-
|
8
|
-
def initialize: (?type: Type, ?s_value: String, ?alias: String) -> void
|
9
|
-
class Type
|
10
|
-
attr_accessor id: Integer
|
11
|
-
attr_accessor name: String
|
12
|
-
|
13
|
-
def initialize: (?id: Integer, ?name: String) -> void
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|