depager 0.2.3 → 0.3.0.b20250423
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 +7 -0
- data/.rubocop.yml +44 -0
- data/.simplecov +5 -0
- data/Gemfile +12 -0
- data/LICENSE.gpl +339 -0
- data/Manifest.txt +73 -0
- data/README.en +7 -21
- data/README.ja +19 -99
- data/Rakefile +31 -0
- data/bin/depager +7 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +48 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +9 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +46 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
- data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
- data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
- data/examples/tiny_calc/calc.cst.dr +50 -0
- data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
- data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
- data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
- data/lib/depager/cli.rb +44 -0
- data/lib/depager/grammar.rb +253 -291
- data/lib/depager/lr.rb +589 -579
- data/lib/depager/parser.rb +269 -277
- data/lib/depager/plugins/_rie_debug.rb +63 -0
- data/lib/depager/plugins/action.rb +47 -0
- data/lib/depager/plugins/ast.dr +367 -0
- data/lib/depager/plugins/ast.rb +1329 -0
- data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
- data/lib/depager/plugins/cst.rb +591 -0
- data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
- data/lib/depager/plugins/lex.rb +313 -0
- data/lib/depager/plugins/rie.dr +725 -0
- data/lib/depager/plugins/rie.rb +1614 -0
- data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
- data/lib/depager/plugins/slex.rb +769 -0
- data/lib/depager/plugins/srp.rb +46 -0
- data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
- data/lib/depager/utils.rb +158 -318
- data/lib/depager/version.rb +3 -3
- data/lib/depager.rb +572 -670
- metadata +77 -80
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.dr +0 -45
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/action.rb +0 -43
- data/lib/depager/ruby/plugins/ast.dr +0 -269
- data/lib/depager/ruby/plugins/ast.rb +0 -1308
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/cst.rb +0 -626
- data/lib/depager/ruby/plugins/lex.rb +0 -336
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/plugins/slex.rb +0 -817
- data/lib/depager/ruby/plugins/srp.rb +0 -51
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
- /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
@@ -1,180 +1,174 @@
|
|
1
|
-
%defext CSTBuilderExtension
|
2
|
-
%extend Lexer ('plugins/lex.rb')
|
3
|
-
%extend
|
4
|
-
%decorate @
|
5
|
-
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
6
|
-
%inner{
|
7
|
-
attr_accessor :
|
8
|
-
def
|
9
|
-
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
|
15
|
-
|
16
|
-
def modify_action_code code
|
17
|
-
code.gsub(
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
x.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
g_parser.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
g_parser.
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
%
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
expr:
|
176
|
-
ID { [ _ID.value, nil] }
|
177
|
-
| ID '=' LIT { [ _ID.value, _LIT.value ] }
|
178
|
-
;
|
179
|
-
#end-rule
|
180
|
-
%%
|
1
|
+
%defext Depager::CSTBuilderExtension
|
2
|
+
%extend Depager::Lexer ('depager/plugins/lex.rb')
|
3
|
+
%extend Depager::Action ('depager/plugins/action.rb')
|
4
|
+
%decorate @Action
|
5
|
+
#%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
|
6
|
+
%inner{
|
7
|
+
attr_accessor :action_code, :nodes_code, :visitor_code
|
8
|
+
def init_extension
|
9
|
+
@n = 0
|
10
|
+
@visitor_code = ''
|
11
|
+
@nodes_code = ''
|
12
|
+
@action_code = ''
|
13
|
+
@on_reduce = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def modify_action_code code
|
17
|
+
code.gsub(/\$\.([a-z_])/, 'node.\1')
|
18
|
+
end
|
19
|
+
|
20
|
+
def post_rhs
|
21
|
+
code, lineno = '', g_parser.file.lineno
|
22
|
+
if g_parser.line =~ /\s*\{/
|
23
|
+
@original_line, @line = g_parser.original_line, g_parser.line
|
24
|
+
code = parse_block
|
25
|
+
|
26
|
+
g_parser.update_context @line
|
27
|
+
end
|
28
|
+
|
29
|
+
node_name = "#{g_parser.lhs_name}_#{g_parser.nrhs}"
|
30
|
+
accept = ""
|
31
|
+
nodes = g_parser.rhs.map do |i|
|
32
|
+
x = g_parser.int_to_sym(i)
|
33
|
+
if x.class == String
|
34
|
+
"tx#{x.unpack("H*")[0]}"
|
35
|
+
else
|
36
|
+
x = x.to_s
|
37
|
+
accept << "#{x}.accept(v); " if x =~ /\A[a-z_]+\Z/
|
38
|
+
x.downcase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
attrc = nodes.map{|i| ":#{i}" }.join(', ')
|
42
|
+
inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
|
43
|
+
@nodes_code << <<-CODE
|
44
|
+
class Node_#{node_name} < Node_#{g_parser.lhs_name}
|
45
|
+
attr_accessor #{attrc}
|
46
|
+
def initialize #{nodes.join(', ')}
|
47
|
+
super()
|
48
|
+
#{inic}
|
49
|
+
end
|
50
|
+
def accept v
|
51
|
+
#{accept}
|
52
|
+
v.visit_Node_#{node_name}(self)
|
53
|
+
end
|
54
|
+
def children
|
55
|
+
[#{nodes.join(', ')}]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
CODE
|
59
|
+
|
60
|
+
@visitor_code <<
|
61
|
+
expand_inline_code(modify_action_code(code), lineno, :wrap => "def visit_Node_#{node_name} node")
|
62
|
+
|
63
|
+
args = nodes.inject([]){|r, i| r << "val[#{r.size}]"}
|
64
|
+
code = "#{target_namespace}::Node_#{node_name}.new(#{args.join(', ')})"
|
65
|
+
n = g_parser.rules.size-1
|
66
|
+
@action_code <<
|
67
|
+
expand_inline_code(code, lineno, :wrap => "def _cst_#{n} val")
|
68
|
+
|
69
|
+
@on_reduce[n] = ":_cst_#{n}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def term_extension
|
73
|
+
g_parser.outer_code << "module #{target_namespace}\n"
|
74
|
+
g_parser.outer_code << @nodes_code
|
75
|
+
g_parser.outer_code << <<-CODE
|
76
|
+
class Visitor
|
77
|
+
#{@visitor_code}
|
78
|
+
end
|
79
|
+
CODE
|
80
|
+
g_parser.outer_code << "end\n"
|
81
|
+
g_parser.outer_code << generate_action_decorator_code(@on_reduce, @action_code)
|
82
|
+
end
|
83
|
+
%}
|
84
|
+
%hook pre_rule_list /%CST\{\s*\Z/ skip
|
85
|
+
%banner '%CST{ ... }'
|
86
|
+
%%
|
87
|
+
|
88
|
+
%LEX{
|
89
|
+
/\s+/, /#.*/ { }
|
90
|
+
/%\}\s*\Z/ { yield nil,nil }
|
91
|
+
'Node' { yield token(:NODE, $&) }
|
92
|
+
'Visitor' { yield token(:VISITOR, $&) }
|
93
|
+
'{' ! { lineno = file.lineno; yield token(:ACTION, parse_block, lineno) }
|
94
|
+
%}
|
95
|
+
|
96
|
+
#begin-rule
|
97
|
+
start:
|
98
|
+
opt_node opt_visitor
|
99
|
+
{
|
100
|
+
master.nodes_code << <<-CODE
|
101
|
+
class Node
|
102
|
+
def accept
|
103
|
+
end
|
104
|
+
#{_opt_node}
|
105
|
+
end
|
106
|
+
CODE
|
107
|
+
master.visitor_code << _opt_visitor
|
108
|
+
}
|
109
|
+
;
|
110
|
+
opt_node:
|
111
|
+
{ '' }
|
112
|
+
| NODE ACTION { _ACTION.value }
|
113
|
+
;
|
114
|
+
opt_visitor:
|
115
|
+
{ '' }
|
116
|
+
| VISITOR ACTION { _ACTION.value }
|
117
|
+
;
|
118
|
+
#end-rule
|
119
|
+
%%
|
120
|
+
%hook post_lhs /\[/ skip
|
121
|
+
%banner '[ ... ]'
|
122
|
+
%inner{
|
123
|
+
def do_default
|
124
|
+
master.nodes_code << <<-CODE
|
125
|
+
class Node_#{g_parser.lhs_name} < Node
|
126
|
+
def initialize
|
127
|
+
super()
|
128
|
+
end
|
129
|
+
end
|
130
|
+
CODE
|
131
|
+
end
|
132
|
+
%}
|
133
|
+
%%
|
134
|
+
|
135
|
+
%LEX{
|
136
|
+
/\A\s+/ { } #skip blank
|
137
|
+
/""/,/''/,/[0-9]+/,
|
138
|
+
/\{\s*\}/,/\[\s*\]/,
|
139
|
+
/nil/ { yield token(:LIT, $&) }
|
140
|
+
/\A[a-z][a-z_]*/ { yield token(:ID, $&) }
|
141
|
+
/\A(.)/ { yield token($&, $&) }
|
142
|
+
%}
|
143
|
+
|
144
|
+
#begin-rule
|
145
|
+
start:
|
146
|
+
'[' pair ']'
|
147
|
+
{
|
148
|
+
args = []; code = ''
|
149
|
+
_pair.each do |id, lit|
|
150
|
+
args << id
|
151
|
+
code << "#{id} = #{lit}; " if lit
|
152
|
+
end
|
153
|
+
attrc = args.map{|i| ":#{i}"}.join(', ')
|
154
|
+
master.nodes_code << <<-CODE
|
155
|
+
class Node_#{g_parser.lhs_name} < Node
|
156
|
+
attr_accessor #{attrc}
|
157
|
+
def initialize
|
158
|
+
super
|
159
|
+
#{code}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
CODE
|
163
|
+
}
|
164
|
+
;
|
165
|
+
pair:
|
166
|
+
expr { [ _expr ] }
|
167
|
+
| pair ',' expr { _pair << _expr }
|
168
|
+
;
|
169
|
+
expr:
|
170
|
+
ID { [ _ID.value, nil] }
|
171
|
+
| ID '=' LIT { [ _ID.value, _LIT.value ] }
|
172
|
+
;
|
173
|
+
#end-rule
|
174
|
+
%%
|