depager 0.3.0.b20160729 → 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 +5 -5
- 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 +4 -3
- data/README.ja +4 -47
- data/Rakefile +31 -0
- data/bin/depager +3 -38
- data/examples/action_pl0d/pl0d.action.dr +4 -4
- data/examples/action_pl0d/test.pl0ds +2 -3
- data/examples/c89/c89.dr +4 -4
- data/examples/c89/test.c89 +1 -1
- data/examples/extension/astdf.rb +4 -5
- data/examples/extension/atree.dr +3 -3
- data/examples/extension/calc.atree.dr +4 -4
- data/examples/extension/calc.simple_action.dr +3 -3
- data/examples/extension/paction.dr +3 -3
- data/examples/extension/pactiontest.dr +3 -3
- data/examples/extension/simple_action.rb +26 -24
- data/examples/pl0d/pl0ds.dr +5 -5
- data/examples/pl0d/test.pl0ds +2 -2
- data/examples/rie_calc/calc.rie.dr +4 -4
- data/examples/rie_dcuse/dcuse.rie.dr +4 -4
- data/examples/rie_pl0/pl0.rie.dr +3 -3
- data/examples/slex_test/divreg.slex.dr +5 -5
- data/examples/slex_test/ljoin.slex.dr +5 -5
- data/examples/{sample_calc → tiny_calc}/calc.action.dr +4 -4
- data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +20 -9
- data/examples/{sample_calc → tiny_calc}/calc.ast.dr +19 -7
- data/examples/{sample_calc → tiny_calc}/calc.cst.dr +12 -7
- data/examples/{sample_calc → tiny_calc}/calc.dr +1 -1
- data/examples/{sample_calc → tiny_calc}/calc.lex.dr +2 -2
- data/examples/{sample_calc → tiny_calc}/calc_prec.action.dr +4 -4
- data/lib/depager/cli.rb +44 -0
- data/lib/depager/grammar.rb +72 -75
- data/lib/depager/lr.rb +169 -154
- data/lib/depager/parser.rb +90 -103
- data/lib/depager/plugins/_rie_debug.rb +63 -0
- data/lib/depager/plugins/action.rb +47 -0
- data/lib/depager/{ruby/plugins → plugins}/ast.dr +20 -17
- data/lib/depager/{ruby/plugins → plugins}/ast.rb +266 -304
- data/lib/depager/{ruby/plugins → plugins}/cst.dr +18 -16
- data/lib/depager/{ruby/plugins → plugins}/cst.rb +152 -148
- data/lib/depager/{ruby/plugins → plugins}/lex.dr +7 -7
- data/lib/depager/{ruby/plugins → plugins}/lex.rb +72 -69
- data/lib/depager/{ruby/plugins → plugins}/rie.dr +12 -10
- data/lib/depager/{ruby/plugins → plugins}/rie.rb +224 -263
- data/lib/depager/{ruby/plugins → plugins}/slex.dr +13 -14
- data/lib/depager/{ruby/plugins → plugins}/slex.rb +183 -194
- data/lib/depager/plugins/srp.rb +46 -0
- data/lib/depager/ruby/templates/extension_lalr_master.erb +6 -12
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +31 -17
- data/lib/depager/ruby/templates/single_lalr_parser.erb +35 -26
- data/lib/depager/utils.rb +56 -46
- data/lib/depager/version.rb +1 -2
- data/lib/depager.rb +166 -176
- metadata +38 -33
- data/lib/depager/ruby/plugins/_rie_debug.rb +0 -35
- data/lib/depager/ruby/plugins/action.rb +0 -53
- data/lib/depager/ruby/plugins/srp.rb +0 -56
- /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
###
|
4
2
|
### Depager::LexerExtension - Depager Extension (master)
|
5
3
|
###
|
@@ -11,6 +9,7 @@ module Depager ; end
|
|
11
9
|
class Depager::LexerExtension < Depager::Extension
|
12
10
|
|
13
11
|
def initialize
|
12
|
+
super
|
14
13
|
@master = self
|
15
14
|
@slaves = []
|
16
15
|
end
|
@@ -18,24 +17,23 @@ class Depager::LexerExtension < Depager::Extension
|
|
18
17
|
def extension_registered g_parser
|
19
18
|
super g_parser
|
20
19
|
|
21
|
-
@slaves
|
22
|
-
g_parser.hooks[:pre_rule_list].push [@slaves
|
20
|
+
@slaves << Depager::LexerExtension::PreRuleList0::Parser.new(g_parser, self)
|
21
|
+
g_parser.hooks[:pre_rule_list].push [@slaves.last, :do_parse]
|
23
22
|
end
|
24
23
|
|
25
24
|
|
26
25
|
end
|
27
26
|
|
28
27
|
###
|
29
|
-
### Depager::LexerExtension::
|
28
|
+
### Depager::LexerExtension::PreRuleList0 - Part of Depager Extension (slave)
|
30
29
|
###
|
31
30
|
|
32
|
-
module Depager::LexerExtension::
|
31
|
+
module Depager::LexerExtension::PreRuleList0 #:nodoc:all
|
33
32
|
class Parser < Depager::LALR::Basis #:nodoc:all
|
34
33
|
include Depager::Utils::ExtensionSlaveMethods
|
35
|
-
|
36
34
|
|
37
35
|
### Reduce Table
|
38
|
-
|
36
|
+
REDUCE_TABLE = [
|
39
37
|
[ -1, 1 ],
|
40
38
|
[ 0, 1 ],
|
41
39
|
[ 1, 1 ],
|
@@ -46,8 +44,10 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
46
44
|
[ 3, 1 ],
|
47
45
|
[ 3, 3 ],
|
48
46
|
]
|
47
|
+
def reduce_table; REDUCE_TABLE; end
|
48
|
+
|
49
49
|
### Term to Int
|
50
|
-
|
50
|
+
TERM_TO_INT = {
|
51
51
|
nil => 0,
|
52
52
|
false => 1,
|
53
53
|
:ACTION => 2,
|
@@ -55,8 +55,10 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
55
55
|
:LEX => 4,
|
56
56
|
"," => 5,
|
57
57
|
}
|
58
|
+
def term_to_int; TERM_TO_INT; end
|
59
|
+
|
58
60
|
### Int to Term
|
59
|
-
|
61
|
+
INT_TO_TERM = [
|
60
62
|
nil,
|
61
63
|
false,
|
62
64
|
:ACTION,
|
@@ -64,8 +66,10 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
64
66
|
:LEX,
|
65
67
|
",",
|
66
68
|
]
|
69
|
+
def int_to_term; INT_TO_TERM; end
|
70
|
+
|
67
71
|
### Action Table
|
68
|
-
|
72
|
+
ACTION_TABLE = [
|
69
73
|
[ nil, nil, nil, nil, 5, nil, ],
|
70
74
|
[ ACC, nil, nil, nil, nil, nil, ],
|
71
75
|
[ nil, nil, nil, nil, 5, nil, ],
|
@@ -79,8 +83,10 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
79
83
|
[ nil, nil, nil, nil, nil, nil, ],
|
80
84
|
[ nil, nil, nil, nil, nil, nil, ],
|
81
85
|
]
|
86
|
+
def action_table; ACTION_TABLE; end
|
87
|
+
|
82
88
|
### Default Reduce Table
|
83
|
-
|
89
|
+
DEFRED_TABLE = [
|
84
90
|
nil,
|
85
91
|
nil,
|
86
92
|
-1,
|
@@ -94,7 +100,9 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
94
100
|
-4,
|
95
101
|
-8,
|
96
102
|
]
|
97
|
-
|
103
|
+
def defred_table; DEFRED_TABLE; end
|
104
|
+
|
105
|
+
DEFRED_AFTER_SHIFT_TABLE = [
|
98
106
|
nil,
|
99
107
|
nil,
|
100
108
|
nil,
|
@@ -108,24 +116,30 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
108
116
|
-4,
|
109
117
|
-8,
|
110
118
|
]
|
119
|
+
def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end
|
120
|
+
|
111
121
|
### Nonterm to Int
|
112
|
-
|
113
|
-
:start => 0,
|
114
|
-
:lexactlist => 1,
|
115
|
-
:lexact => 2,
|
116
|
-
:lexlist => 3,
|
117
|
-
:opt_noskip => 4,
|
122
|
+
NONTERM_TO_INT = {
|
123
|
+
:start => 0,
|
124
|
+
:lexactlist => 1,
|
125
|
+
:lexact => 2,
|
126
|
+
:lexlist => 3,
|
127
|
+
:opt_noskip => 4,
|
118
128
|
}
|
129
|
+
def nonterm_to_int; NONTERM_TO_INT; end
|
130
|
+
|
119
131
|
### Int to Nonterm
|
120
|
-
|
121
|
-
:start,
|
122
|
-
:lexactlist,
|
123
|
-
:lexact,
|
124
|
-
:lexlist,
|
125
|
-
:opt_noskip,
|
132
|
+
INT_TO_NONTERM = [
|
133
|
+
:start,
|
134
|
+
:lexactlist,
|
135
|
+
:lexact,
|
136
|
+
:lexlist,
|
137
|
+
:opt_noskip,
|
126
138
|
]
|
139
|
+
def int_to_nonterm; INT_TO_NONTERM; end
|
140
|
+
|
127
141
|
### Goto Table
|
128
|
-
|
142
|
+
GOTO_TABLE = [
|
129
143
|
[ 1, 2, 3, 4, nil, ],
|
130
144
|
[ nil, nil, nil, nil, nil, ],
|
131
145
|
[ nil, nil, 6, 4, nil, ],
|
@@ -139,10 +153,7 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
139
153
|
[ nil, nil, nil, nil, nil, ],
|
140
154
|
[ nil, nil, nil, nil, nil, ],
|
141
155
|
]
|
142
|
-
|
143
|
-
Tables = [ reduce_table, action_table,
|
144
|
-
defred_table, defred_after_shift_table, goto_table,
|
145
|
-
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
156
|
+
def goto_table; GOTO_TABLE; end
|
146
157
|
|
147
158
|
def initialize g_parser, master
|
148
159
|
super()
|
@@ -167,7 +178,7 @@ module Depager::LexerExtension::Slave_pre_rule_list #:nodoc:all
|
|
167
178
|
"%LEX{ ... } / Depager::LexerExtension"
|
168
179
|
end
|
169
180
|
|
170
|
-
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/
|
181
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 9
|
171
182
|
def lex
|
172
183
|
until @file.eof?
|
173
184
|
until @line.empty?
|
@@ -204,12 +215,10 @@ DEPAGER_EXPANDED_CODE
|
|
204
215
|
end
|
205
216
|
end
|
206
217
|
|
207
|
-
|
208
|
-
class Depager::LexerExtension::Slave_pre_rule_list::Action < Depager::LALR::Action #:nodoc:all
|
218
|
+
class Depager::LexerExtension::PreRuleList0::Action < Depager::LALR::Action #:nodoc:all
|
209
219
|
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
210
|
-
|
211
|
-
|
212
|
-
nil,
|
220
|
+
ON_REDUCE = [
|
221
|
+
nil,
|
213
222
|
:_act_1,
|
214
223
|
:_act_2,
|
215
224
|
:_act_3,
|
@@ -219,20 +228,19 @@ class Depager::LexerExtension::Slave_pre_rule_list::Action < Depager::LALR::Acti
|
|
219
228
|
:_act_7,
|
220
229
|
:_act_8,
|
221
230
|
|
222
|
-
|
223
|
-
|
231
|
+
]
|
232
|
+
def on_reduce; ON_REDUCE; end
|
224
233
|
|
225
|
-
|
226
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 43
|
234
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 43
|
227
235
|
def _act_1 val
|
228
|
-
_lexactlist, = *val
|
236
|
+
_lexactlist, = *val
|
229
237
|
|
230
|
-
g_parser.inner_code <<
|
238
|
+
g_parser.inner_code << <<~CODE
|
231
239
|
def lex
|
232
240
|
begin
|
233
241
|
until @line.empty?
|
234
242
|
case @line
|
235
|
-
|
243
|
+
#{ _lexactlist }
|
236
244
|
else
|
237
245
|
raise RuntimeError, "must not happen \#{@line}"
|
238
246
|
end
|
@@ -240,71 +248,66 @@ def _act_1 val
|
|
240
248
|
end while @original_line = @line = file.gets
|
241
249
|
yield nil, nil
|
242
250
|
end
|
243
|
-
|
251
|
+
CODE
|
244
252
|
|
245
253
|
end
|
246
254
|
DEPAGER_EXPANDED_CODE
|
247
|
-
|
248
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 61
|
255
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 61
|
249
256
|
def _act_2 val
|
250
|
-
_lexact, = *val
|
257
|
+
_lexact, = *val
|
251
258
|
_lexact
|
252
259
|
|
253
260
|
end
|
254
261
|
DEPAGER_EXPANDED_CODE
|
255
|
-
|
256
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 62
|
262
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 62
|
257
263
|
def _act_3 val
|
258
|
-
_lexactlist, _lexact, = *val
|
264
|
+
_lexactlist, _lexact, = *val
|
259
265
|
_lexactlist << _lexact
|
260
266
|
|
261
267
|
end
|
262
268
|
DEPAGER_EXPANDED_CODE
|
263
|
-
|
264
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 66
|
269
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 66
|
265
270
|
def _act_4 val
|
266
|
-
_lexlist, _opt_noskip, _ACTION, = *val
|
271
|
+
_lexlist, _opt_noskip, _ACTION, = *val
|
267
272
|
|
268
|
-
|
273
|
+
<<-CODE
|
269
274
|
when #{_lexlist.join(', ')}
|
270
275
|
#{ _opt_noskip ? '#' : "@line = $'" }
|
271
276
|
#{ _ACTION }
|
272
|
-
|
277
|
+
CODE
|
273
278
|
|
274
279
|
end
|
275
280
|
DEPAGER_EXPANDED_CODE
|
276
|
-
|
277
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 75
|
281
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 75
|
278
282
|
def _act_5 val
|
283
|
+
# empty rule
|
279
284
|
false
|
280
285
|
|
281
286
|
end
|
282
287
|
DEPAGER_EXPANDED_CODE
|
283
|
-
|
284
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 76
|
288
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 76
|
285
289
|
def _act_6 val
|
286
|
-
_, = *val
|
290
|
+
_, = *val
|
287
291
|
true
|
288
292
|
|
289
293
|
end
|
290
294
|
DEPAGER_EXPANDED_CODE
|
291
|
-
|
292
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 79
|
295
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 79
|
293
296
|
def _act_7 val
|
294
|
-
_LEX, = *val
|
297
|
+
_LEX, = *val
|
295
298
|
[ _LEX ]
|
296
299
|
|
297
300
|
end
|
298
301
|
DEPAGER_EXPANDED_CODE
|
299
|
-
|
300
|
-
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/lex.dr', 80
|
302
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/plugins/lex.dr', 80
|
301
303
|
def _act_8 val
|
302
|
-
_lexlist, _, _LEX, = *val
|
304
|
+
_lexlist, _, _LEX, = *val
|
303
305
|
_lexlist << _LEX
|
304
306
|
|
305
307
|
end
|
306
308
|
DEPAGER_EXPANDED_CODE
|
307
|
-
|
308
|
-
|
309
|
+
|
310
|
+
|
309
311
|
end
|
310
|
-
|
312
|
+
|
313
|
+
|
@@ -1,10 +1,11 @@
|
|
1
1
|
%defext Depager::RieExtension
|
2
|
-
%extend Depager::Lexer ('plugins/lex.rb')
|
3
|
-
%extend Depager::Action ('plugins/action.rb')
|
2
|
+
%extend Depager::Lexer ('depager/plugins/lex.rb')
|
3
|
+
%extend Depager::Action ('depager/plugins/action.rb')
|
4
4
|
%decorate @Action
|
5
|
-
#%decorate Depager::LALR::ShiftReducePrinter ('plugins/srp.rb')
|
6
|
-
%expanded_code_delimiter DEPAGER_EXPANDED_CODE
|
5
|
+
#%decorate Depager::LALR::ShiftReducePrinter ('depager/plugins/srp.rb')
|
7
6
|
%inner{
|
7
|
+
require "pp"
|
8
|
+
|
8
9
|
module Nodes
|
9
10
|
N_THREAD = Struct.new :lineno, :targets, :excepts
|
10
11
|
N_TRANSFER = Struct.new :lineno, :targets, :excepts
|
@@ -16,7 +17,7 @@
|
|
16
17
|
include Nodes
|
17
18
|
|
18
19
|
begin
|
19
|
-
|
20
|
+
require 'depager/plugins/_rie_debug.rb' if Depager.debug_mode?
|
20
21
|
rescue LoadError
|
21
22
|
end
|
22
23
|
|
@@ -32,8 +33,9 @@
|
|
32
33
|
@locals = [{}]
|
33
34
|
@ecs = {}
|
34
35
|
if Depager.debug_mode?
|
35
|
-
|
36
|
-
|
36
|
+
path = g_parser.file == $stdin ? "stdin" : g_parser.file.path
|
37
|
+
@debug_output_path = "#{path}.rie_debug.output"
|
38
|
+
File.write @debug_output_path, ""
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
@@ -464,7 +466,7 @@
|
|
464
466
|
end
|
465
467
|
|
466
468
|
def error_exit_if_error_pending
|
467
|
-
@pending_errors and (
|
469
|
+
@pending_errors and error_exit(@pending_errors.join("\n"))
|
468
470
|
end
|
469
471
|
|
470
472
|
def debug_info s
|
@@ -475,7 +477,7 @@
|
|
475
477
|
on_reduce_code = on_reduce.map{|i| " #{i||'nil'},\n"}
|
476
478
|
on_state_code = on_state.map{|i| " #{i||'nil'},\n"}
|
477
479
|
|
478
|
-
generate_decorator_code(decorator_name, "#{d_parser.parsing_method}::AdvancedParser",
|
480
|
+
generate_decorator_code(decorator_name, "#{d_parser.parsing_method}::AdvancedParser", <<-CODE)
|
479
481
|
on_reduce = [\n#{on_reduce_code.join}
|
480
482
|
]
|
481
483
|
on_state = [\n#{on_state_code.join}
|
@@ -514,7 +516,7 @@
|
|
514
516
|
raise
|
515
517
|
end
|
516
518
|
\n#{action_code}
|
517
|
-
|
519
|
+
CODE
|
518
520
|
end
|
519
521
|
%}
|
520
522
|
%hook post_lhs /\[/
|