lrama 0.5.10 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +21 -1
- data/Steepfile +8 -12
- data/lib/lrama/grammar/code/rule_action.rb +1 -1
- data/lib/lrama/grammar/parameterizing_rules/builder/base.rb +10 -2
- data/lib/lrama/grammar/parameterizing_rules/builder/list.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/nonempty_list.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/option.rb +12 -4
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_list.rb +17 -6
- data/lib/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rb +12 -5
- data/lib/lrama/grammar/parameterizing_rules/builder.rb +23 -6
- data/lib/lrama/grammar/rule.rb +2 -1
- data/lib/lrama/grammar/rule_builder.rb +17 -19
- data/lib/lrama/grammar/symbol.rb +16 -2
- data/lib/lrama/grammar/type.rb +6 -0
- data/lib/lrama/grammar.rb +8 -3
- data/lib/lrama/lexer/token/parameterizing.rb +1 -1
- data/lib/lrama/lexer/token.rb +16 -9
- data/lib/lrama/lexer.rb +1 -2
- data/lib/lrama/parser.rb +359 -346
- data/lib/lrama/version.rb +1 -1
- data/lib/lrama.rb +0 -1
- data/parser.y +17 -15
- data/rbs_collection.lock.yaml +2 -8
- data/sig/lrama/grammar/error_token.rbs +11 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/base.rbs +26 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/list.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/option.rbs +10 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs +11 -0
- data/sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs +11 -0
- data/sig/lrama/grammar/parameterizing_rules/builder.rbs +14 -1
- data/sig/lrama/grammar/reference.rbs +2 -2
- data/sig/lrama/grammar/rule.rbs +1 -1
- data/sig/lrama/grammar/rule_builder.rbs +1 -0
- data/sig/lrama/grammar/symbol.rbs +37 -0
- data/sig/lrama/lexer/token/parameterizing.rbs +2 -0
- data/sig/lrama/lexer/token.rbs +3 -3
- data/template/bison/yacc.c +0 -2
- metadata +11 -3
- data/lib/lrama/type.rb +0 -4
data/lib/lrama/version.rb
CHANGED
data/lib/lrama.rb
CHANGED
data/parser.y
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Lrama::Parser
|
2
|
-
expect
|
2
|
+
expect 0
|
3
3
|
|
4
4
|
token C_DECLARATION CHARACTER IDENT_COLON IDENTIFIER INTEGER STRING TAG
|
5
5
|
|
@@ -31,7 +31,6 @@ rule
|
|
31
31
|
bison_declaration: grammar_declaration
|
32
32
|
| "%expect" INTEGER { @grammar.expect = val[1] }
|
33
33
|
| "%define" variable value
|
34
|
-
| "%require" STRING
|
35
34
|
| "%param" params
|
36
35
|
| "%lex-param" params
|
37
36
|
{
|
@@ -327,27 +326,24 @@ rule
|
|
327
326
|
builder.add_rhs(token)
|
328
327
|
result = builder
|
329
328
|
}
|
330
|
-
| rhs IDENTIFIER parameterizing_suffix
|
329
|
+
| rhs IDENTIFIER parameterizing_suffix tag_opt
|
331
330
|
{
|
332
331
|
token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[2], location: @lexer.location, args: [val[1]])
|
333
332
|
builder = val[0]
|
334
333
|
builder.add_rhs(token)
|
334
|
+
builder.lhs_tag = val[3]
|
335
|
+
builder.line = val[1].first_line
|
335
336
|
result = builder
|
336
337
|
}
|
337
|
-
| rhs IDENTIFIER "("
|
338
|
+
| rhs IDENTIFIER "(" parameterizing_args ")" tag_opt
|
338
339
|
{
|
339
|
-
token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args:
|
340
|
+
token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: val[3])
|
340
341
|
builder = val[0]
|
341
342
|
builder.add_rhs(token)
|
343
|
+
builder.lhs_tag = val[5]
|
344
|
+
builder.line = val[1].first_line
|
342
345
|
result = builder
|
343
346
|
}
|
344
|
-
| rhs IDENTIFIER "(" symbol "," symbol ")"
|
345
|
-
{
|
346
|
-
token = Lrama::Lexer::Token::Parameterizing.new(s_value: val[1].s_value, location: @lexer.location, args: [val[3], val[5]])
|
347
|
-
builder = val[0]
|
348
|
-
builder.add_rhs(token)
|
349
|
-
result = builder
|
350
|
-
}
|
351
347
|
| rhs "{"
|
352
348
|
{
|
353
349
|
if @prec_seen
|
@@ -362,10 +358,10 @@ rule
|
|
362
358
|
}
|
363
359
|
"}" named_ref_opt
|
364
360
|
{
|
365
|
-
|
366
|
-
|
361
|
+
user_code = val[3]
|
362
|
+
user_code.alias_name = val[6]
|
367
363
|
builder = val[0]
|
368
|
-
builder.user_code =
|
364
|
+
builder.user_code = user_code
|
369
365
|
result = builder
|
370
366
|
}
|
371
367
|
| rhs "%prec" symbol
|
@@ -381,6 +377,9 @@ rule
|
|
381
377
|
| "+"
|
382
378
|
| "*"
|
383
379
|
|
380
|
+
parameterizing_args: symbol { result = [val[0]] }
|
381
|
+
| parameterizing_args ',' symbol { result = val[0].append(val[2]) }
|
382
|
+
|
384
383
|
named_ref_opt: # empty
|
385
384
|
| '[' IDENTIFIER ']' { result = val[1].s_value }
|
386
385
|
|
@@ -412,6 +411,9 @@ rule
|
|
412
411
|
| TAG
|
413
412
|
|
414
413
|
string_as_id: STRING { result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) }
|
414
|
+
|
415
|
+
tag_opt: # empty
|
416
|
+
| TAG
|
415
417
|
end
|
416
418
|
|
417
419
|
---- inner
|
data/rbs_collection.lock.yaml
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
---
|
2
|
-
sources:
|
3
|
-
- type: git
|
4
|
-
name: ruby/gem_rbs_collection
|
5
|
-
revision: 25286c51a19927f28623aee3cd36655f902399ba
|
6
|
-
remote: https://github.com/ruby/gem_rbs_collection.git
|
7
|
-
repo_dir: gems
|
8
2
|
path: ".gem_rbs_collection"
|
9
3
|
gems:
|
10
4
|
- name: erb
|
@@ -24,7 +18,7 @@ gems:
|
|
24
18
|
source:
|
25
19
|
type: git
|
26
20
|
name: ruby/gem_rbs_collection
|
27
|
-
revision:
|
21
|
+
revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
|
28
22
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
29
23
|
repo_dir: gems
|
30
24
|
- name: stackprof
|
@@ -32,7 +26,7 @@ gems:
|
|
32
26
|
source:
|
33
27
|
type: git
|
34
28
|
name: ruby/gem_rbs_collection
|
35
|
-
revision:
|
29
|
+
revision: 4b0d2f72e63b6c3e92dc54e19ce23dd24524f9a7
|
36
30
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
37
31
|
repo_dir: gems
|
38
32
|
- name: strscan
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class ErrorToken
|
4
|
+
attr_accessor ident_or_tags: Array[Lexer::Token::Ident | Lexer::Token::Tag]
|
5
|
+
attr_accessor token_code: Symbol
|
6
|
+
attr_accessor lineno: Integer
|
7
|
+
|
8
|
+
def translated_code: (Lexer::Token? tag) -> String
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class ParameterizingRules
|
4
|
+
class Builder
|
5
|
+
class Base
|
6
|
+
def initialize: (Lexer::Token::Parameterizing token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
7
|
+
def build: () -> Array[Rule]
|
8
|
+
|
9
|
+
@args: Array[Lexer::Token]
|
10
|
+
@token: Lexer::Token::Parameterizing
|
11
|
+
@key: Symbol
|
12
|
+
@rule_counter: Counter
|
13
|
+
@lhs: Lexer::Token
|
14
|
+
@user_code: Lexer::Token::UserCode?
|
15
|
+
@precedence_sym: Lexer::Token?
|
16
|
+
@line: Integer?
|
17
|
+
@expected_argument_num: Integer
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def validate_argument_number!: () -> void
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class ParameterizingRules
|
4
|
+
class Builder
|
5
|
+
class SeparatedList < Base
|
6
|
+
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class ParameterizingRules
|
4
|
+
class Builder
|
5
|
+
class SeparatedNonemptyList < Base
|
6
|
+
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -2,8 +2,21 @@ module Lrama
|
|
2
2
|
class Grammar
|
3
3
|
class ParameterizingRules
|
4
4
|
class Builder
|
5
|
-
|
5
|
+
RULES: Hash[Symbol, singleton(Base)]
|
6
|
+
|
7
|
+
@token: Lexer::Token::Parameterizing
|
8
|
+
@key: Symbol
|
9
|
+
@rule_counter: Counter
|
10
|
+
@lhs: Lexer::Token
|
11
|
+
@user_code: Lexer::Token::UserCode?
|
12
|
+
@precedence_sym: Lexer::Token?
|
13
|
+
@line: Integer?
|
14
|
+
|
15
|
+
def initialize: (Lexer::Token token, Counter rule_counter, untyped lhs_tag, Lexer::Token::UserCode? user_code, Lexer::Token? precedence_sym, Integer? line) -> void
|
6
16
|
def build: () -> Array[Rule]
|
17
|
+
def build_token: () -> Lrama::Lexer::Token
|
18
|
+
def create_builder: () -> void
|
19
|
+
def validate_key!: () -> void
|
7
20
|
end
|
8
21
|
end
|
9
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Lrama
|
2
2
|
class Grammar
|
3
3
|
class Reference
|
4
|
-
attr_accessor type: Symbol
|
4
|
+
attr_accessor type: ::Symbol
|
5
5
|
attr_accessor name: String
|
6
6
|
attr_accessor index: Integer
|
7
7
|
attr_accessor ex_tag: Lexer::Token?
|
@@ -10,7 +10,7 @@ module Lrama
|
|
10
10
|
attr_accessor position_in_rhs: Integer?
|
11
11
|
|
12
12
|
def initialize: (
|
13
|
-
type: Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
|
13
|
+
type: ::Symbol, ?name: String, ?index: Integer, ?ex_tag: Lexer::Token?,
|
14
14
|
first_column: Integer, last_column: Integer,
|
15
15
|
?position_in_rhs: Integer?
|
16
16
|
) -> void
|
data/sig/lrama/grammar/rule.rbs
CHANGED
@@ -4,7 +4,7 @@ module Lrama
|
|
4
4
|
attr_accessor original_rule: Rule
|
5
5
|
|
6
6
|
def initialize: (
|
7
|
-
?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?_rhs: untyped, ?rhs: untyped,
|
7
|
+
?id: untyped, ?_lhs: untyped, ?lhs: untyped, ?lhs_tag: untyped, ?_rhs: untyped, ?rhs: untyped,
|
8
8
|
?token_code: untyped, ?position_in_original_rule_rhs: untyped, ?nullable: untyped,
|
9
9
|
?precedence_sym: untyped, ?lineno: untyped
|
10
10
|
) -> void
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Lrama
|
2
|
+
class Grammar
|
3
|
+
class Symbol
|
4
|
+
attr_accessor id: Lexer::Token
|
5
|
+
attr_accessor alias_name: String
|
6
|
+
attr_accessor number: Integer
|
7
|
+
attr_accessor tag: Lexer::Token?
|
8
|
+
attr_accessor term: bool
|
9
|
+
attr_accessor token_id: Integer
|
10
|
+
attr_accessor nullable: bool
|
11
|
+
attr_accessor precedence: Precedence?
|
12
|
+
attr_accessor printer: Printer?
|
13
|
+
attr_accessor error_token: ErrorToken
|
14
|
+
|
15
|
+
attr_accessor first_set: Set[Array[Symbol]]
|
16
|
+
attr_accessor first_set_bitmap: Integer
|
17
|
+
attr_writer eof_symbol: Symbol
|
18
|
+
attr_writer error_symbol: Symbol
|
19
|
+
attr_writer undef_symbol: Symbol
|
20
|
+
attr_writer accept_symbol: Symbol
|
21
|
+
|
22
|
+
def initialize: (
|
23
|
+
id: Lexer::Token, alias_name: String?, number: Integer?, tag: Lexer::Token?,
|
24
|
+
term: bool, token_id: Integer?, nullable: bool?, precedence: Precedence?, printer: Printer?) -> void
|
25
|
+
|
26
|
+
def term?: () -> bool
|
27
|
+
def nterm?: () -> bool
|
28
|
+
def eof_symbol?: () -> bool
|
29
|
+
def error_symbol?: () -> bool
|
30
|
+
def undef_symbol?: () -> bool
|
31
|
+
def accept_symbol?: () -> bool
|
32
|
+
def display_name: () -> String
|
33
|
+
def enum_name: () -> String
|
34
|
+
def comment: () -> String
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,6 +4,8 @@ module Lrama
|
|
4
4
|
class Parameterizing < Token
|
5
5
|
attr_accessor args: Array[Lrama::Lexer::Token]
|
6
6
|
|
7
|
+
def initialize: (s_value: String, ?alias_name: String, ?location: Location, ?args: Array[Lrama::Lexer::Token]) -> void
|
8
|
+
|
7
9
|
def option?: () -> bool
|
8
10
|
def nonempty_list?: () -> bool
|
9
11
|
def list?: () -> bool
|
data/sig/lrama/lexer/token.rbs
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Lrama
|
2
2
|
class Lexer
|
3
3
|
class Token
|
4
|
-
|
4
|
+
attr_reader s_value: String
|
5
5
|
attr_accessor alias_name: String
|
6
|
-
|
6
|
+
attr_reader location: Location
|
7
7
|
attr_accessor referred: bool
|
8
8
|
|
9
|
-
def initialize: (
|
9
|
+
def initialize: (s_value: String, ?alias_name: String, ?location: Location) -> void
|
10
10
|
|
11
11
|
def to_s: () -> String
|
12
12
|
def referred_by?: (String string) -> bool
|
data/template/bison/yacc.c
CHANGED
@@ -72,7 +72,6 @@
|
|
72
72
|
<%- if output.aux.prologue -%>
|
73
73
|
/* First part of user prologue. */
|
74
74
|
#line <%= output.aux.prologue_first_lineno %> "<%= output.grammar_file_path %>"
|
75
|
-
|
76
75
|
<%= output.aux.prologue %>
|
77
76
|
#line [@oline@] [@ofile@]
|
78
77
|
<%- end -%>
|
@@ -2048,7 +2047,6 @@ yyreturnlab:
|
|
2048
2047
|
<%# b4_percent_code_get([[epilogue]]) -%>
|
2049
2048
|
<%- if output.aux.epilogue -%>
|
2050
2049
|
#line <%= output.aux.epilogue_first_lineno - 1 %> "<%= output.grammar_file_path %>"
|
2051
|
-
|
2052
2050
|
<%= output.aux.epilogue -%>
|
2053
2051
|
<%- end -%>
|
2054
2052
|
|
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.11
|
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-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: LALR (1) parser generator written by Ruby
|
14
14
|
email:
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/lrama/grammar/rule.rb
|
70
70
|
- lib/lrama/grammar/rule_builder.rb
|
71
71
|
- lib/lrama/grammar/symbol.rb
|
72
|
+
- lib/lrama/grammar/type.rb
|
72
73
|
- lib/lrama/grammar/union.rb
|
73
74
|
- lib/lrama/lexer.rb
|
74
75
|
- lib/lrama/lexer/location.rb
|
@@ -94,7 +95,6 @@ files:
|
|
94
95
|
- lib/lrama/states.rb
|
95
96
|
- lib/lrama/states/item.rb
|
96
97
|
- lib/lrama/states_reporter.rb
|
97
|
-
- lib/lrama/type.rb
|
98
98
|
- lib/lrama/version.rb
|
99
99
|
- lib/lrama/warning.rb
|
100
100
|
- lrama.gemspec
|
@@ -110,13 +110,21 @@ files:
|
|
110
110
|
- sig/lrama/grammar/code.rbs
|
111
111
|
- sig/lrama/grammar/code/printer_code.rbs
|
112
112
|
- sig/lrama/grammar/counter.rbs
|
113
|
+
- sig/lrama/grammar/error_token.rbs
|
113
114
|
- sig/lrama/grammar/parameterizing_rules/builder.rbs
|
115
|
+
- sig/lrama/grammar/parameterizing_rules/builder/base.rbs
|
116
|
+
- sig/lrama/grammar/parameterizing_rules/builder/list.rbs
|
117
|
+
- sig/lrama/grammar/parameterizing_rules/builder/nonempty_list.rbs
|
118
|
+
- sig/lrama/grammar/parameterizing_rules/builder/option.rbs
|
119
|
+
- sig/lrama/grammar/parameterizing_rules/builder/separated_list.rbs
|
120
|
+
- sig/lrama/grammar/parameterizing_rules/builder/separated_nonempty_list.rbs
|
114
121
|
- sig/lrama/grammar/percent_code.rbs
|
115
122
|
- sig/lrama/grammar/precedence.rbs
|
116
123
|
- sig/lrama/grammar/printer.rbs
|
117
124
|
- sig/lrama/grammar/reference.rbs
|
118
125
|
- sig/lrama/grammar/rule.rbs
|
119
126
|
- sig/lrama/grammar/rule_builder.rbs
|
127
|
+
- sig/lrama/grammar/symbol.rbs
|
120
128
|
- sig/lrama/lexer/location.rbs
|
121
129
|
- sig/lrama/lexer/token.rbs
|
122
130
|
- sig/lrama/lexer/token/char.rbs
|
data/lib/lrama/type.rb
DELETED