depager 0.2.3 → 0.3.0.b20160729
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/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -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/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- 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/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- 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.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- 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/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/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
data/lib/depager/utils.rb
CHANGED
@@ -1,318 +1,148 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
\n
|
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
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
break if line =~ /\A#{ind}\}\s*(#.*)?\Z/
|
150
|
-
val.concat line
|
151
|
-
end
|
152
|
-
if file.eof?
|
153
|
-
error_exit 'syntax error(parse_action).', start_lineno
|
154
|
-
end
|
155
|
-
end
|
156
|
-
@line = $'
|
157
|
-
# warn "--action--\n#{val}"
|
158
|
-
return val
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
#
|
163
|
-
# Utilities for Extension
|
164
|
-
#
|
165
|
-
module ExtensionUtils
|
166
|
-
include CodeUtils
|
167
|
-
# get GrammarParser
|
168
|
-
def g_parser
|
169
|
-
@g_parser
|
170
|
-
end
|
171
|
-
|
172
|
-
# master parser
|
173
|
-
def master
|
174
|
-
@master
|
175
|
-
end
|
176
|
-
|
177
|
-
# get output class name
|
178
|
-
def target_name
|
179
|
-
@g_parser.target_name
|
180
|
-
end
|
181
|
-
|
182
|
-
# get current line
|
183
|
-
def line
|
184
|
-
@g_parser.line
|
185
|
-
end
|
186
|
-
|
187
|
-
# end of file?
|
188
|
-
def eof?
|
189
|
-
@g_parser.eof?
|
190
|
-
end
|
191
|
-
|
192
|
-
# get input file name
|
193
|
-
def fname
|
194
|
-
@g_parser.fname
|
195
|
-
end
|
196
|
-
|
197
|
-
# get input file path
|
198
|
-
def path
|
199
|
-
@g_parser.path
|
200
|
-
end
|
201
|
-
|
202
|
-
# get current line no
|
203
|
-
def lineno
|
204
|
-
@g_parser.lineno
|
205
|
-
end
|
206
|
-
|
207
|
-
# get next line
|
208
|
-
def getline
|
209
|
-
@line0 = @line = @g_parser.getline
|
210
|
-
end
|
211
|
-
|
212
|
-
# get FileManager object
|
213
|
-
def files
|
214
|
-
@g_parser.files
|
215
|
-
end
|
216
|
-
alias file files
|
217
|
-
|
218
|
-
# get nunber of rules
|
219
|
-
def nrules
|
220
|
-
@g_parser.rules.size - 2
|
221
|
-
end
|
222
|
-
|
223
|
-
# get nunber of rhs rules
|
224
|
-
def nrhs
|
225
|
-
@g_parser.nrhs
|
226
|
-
end
|
227
|
-
|
228
|
-
# get lhs name
|
229
|
-
def lhs_name
|
230
|
-
@g_parser.int_to_sym(@g_parser.lhs)
|
231
|
-
end
|
232
|
-
|
233
|
-
# get rhs names
|
234
|
-
def rhs_names
|
235
|
-
@g_parser.rhs.map do |i|
|
236
|
-
@g_parser.int_to_sym(i)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
protected
|
241
|
-
# initialize method
|
242
|
-
def init_parser ; end
|
243
|
-
|
244
|
-
# do default action
|
245
|
-
# for generated extensions
|
246
|
-
def do_default ; end
|
247
|
-
|
248
|
-
# do default action?
|
249
|
-
# for generated extensions
|
250
|
-
def do_parse?
|
251
|
-
true
|
252
|
-
end
|
253
|
-
|
254
|
-
# start parse
|
255
|
-
# for generated extensions
|
256
|
-
def do_parse
|
257
|
-
__init_parser__
|
258
|
-
init_parser
|
259
|
-
@line = @g_parser.oldline
|
260
|
-
if do_parse?
|
261
|
-
ret = @dect.parse @g_parser.files
|
262
|
-
@g_parser.update_context @line
|
263
|
-
ret
|
264
|
-
else
|
265
|
-
do_default
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
# register extension (for users)
|
270
|
-
def regext p ; end
|
271
|
-
|
272
|
-
# register extension (default)
|
273
|
-
def __regext__ p, key=:default, reg_p=true
|
274
|
-
@g_parser = @p = p
|
275
|
-
@nparam = case key
|
276
|
-
when :none ; nil
|
277
|
-
when :default ; @g_parser.getnparam(paramkey)
|
278
|
-
else ; @g_parser.getnparam(key)
|
279
|
-
end
|
280
|
-
self.methods.sort.each do |m| m = m.to_sym
|
281
|
-
p.hooks[m].push [self, m] if GrammarParser.hook_name? m
|
282
|
-
end
|
283
|
-
regext p if reg_p
|
284
|
-
end
|
285
|
-
# get param key
|
286
|
-
def paramkey
|
287
|
-
self.class.name.split('::').last.sub(/Extension$/, '')
|
288
|
-
end
|
289
|
-
|
290
|
-
# error
|
291
|
-
def error_exit *args
|
292
|
-
@g_parser.error_exit(*args)
|
293
|
-
end
|
294
|
-
# warning
|
295
|
-
def warning *args
|
296
|
-
@g_parser.warning(*args)
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
#
|
301
|
-
# Utilities for Decorator
|
302
|
-
#
|
303
|
-
module DecoratorUtils
|
304
|
-
include CodeUtils
|
305
|
-
# get master parser
|
306
|
-
def master
|
307
|
-
@basis.master
|
308
|
-
end
|
309
|
-
# get grammar parser
|
310
|
-
def g_parser
|
311
|
-
@basis.g_parser
|
312
|
-
end
|
313
|
-
# get basis
|
314
|
-
def basis
|
315
|
-
@basis
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Depager
|
3
|
+
module Utils
|
4
|
+
module CommonMethods
|
5
|
+
def file
|
6
|
+
d_parser.file
|
7
|
+
end
|
8
|
+
|
9
|
+
def target_name
|
10
|
+
g_parser.target_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def target_namespace
|
14
|
+
g_parser.target_namespace
|
15
|
+
end
|
16
|
+
|
17
|
+
def full_target_name
|
18
|
+
"#{target_namespace}::#{target_name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def error_message msg, lineno = nil
|
22
|
+
"#{file.path}:#{lineno || file.lineno}: #{msg}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def error_exit msg, lineno = nil
|
26
|
+
warn error_message(msg, lineno)
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def warning msg, lineno = nil
|
31
|
+
warn error_message(" warning: #{msg}", lineno)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module CodeGeneratorMethods
|
36
|
+
def generate_decorator_code name, super_class_name, code
|
37
|
+
if d_parser.generator.is_a?(Depager::ExtensionGenerator)
|
38
|
+
mixin_code = 'include Depager::Utils::ExtensionSlaveDecoratorMethods'
|
39
|
+
else
|
40
|
+
mixin_code = ''
|
41
|
+
end
|
42
|
+
|
43
|
+
%{
|
44
|
+
\ class #{target_namespace}::#{name} < #{super_class_name} #:nodoc:all
|
45
|
+
#{mixin_code}
|
46
|
+
%s
|
47
|
+
end
|
48
|
+
}.unindent % code; #code
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_action_decorator_code on_reduce, code
|
52
|
+
on_reduce_code = on_reduce.map{|i| " #{i || 'nil'},\n"}
|
53
|
+
|
54
|
+
generate_decorator_code(decorator_name, "#{d_parser.parsing_method}::Action", %{
|
55
|
+
on_reduce = [
|
56
|
+
#{ on_reduce_code.join }
|
57
|
+
]
|
58
|
+
Tables = [ on_reduce ]
|
59
|
+
|
60
|
+
%s
|
61
|
+
} % code)
|
62
|
+
end
|
63
|
+
|
64
|
+
def expand_inline_code body, lineno, options = {}
|
65
|
+
delimiter = expanded_code_delimiter
|
66
|
+
|
67
|
+
if wrap = options[:wrap]
|
68
|
+
wrap = [wrap, "end"] if wrap.is_a?(String)
|
69
|
+
body = "#{wrap[0]}\n#{body}\n#{wrap[1]}"
|
70
|
+
end
|
71
|
+
|
72
|
+
delta = options[:delta] || 0
|
73
|
+
|
74
|
+
%{
|
75
|
+
\ module_eval <<\-'#{delimiter}', '#{file.path}', #{lineno - delta - 1}
|
76
|
+
%s
|
77
|
+
#{delimiter}
|
78
|
+
}.unindent % body
|
79
|
+
end
|
80
|
+
|
81
|
+
def expanded_code_delimiter
|
82
|
+
Depager.configuration[:expanded_code_delimiter] || ".,.,#{Time.now.to_i}#{rand(0xffff)}.,.,"
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_block
|
86
|
+
result = ''
|
87
|
+
start_lineno = file.lineno
|
88
|
+
if @line =~ /\A\s*\{(.*)\}\s*(#.*)?\Z/
|
89
|
+
result = " #{$1}\n"
|
90
|
+
else
|
91
|
+
result.concat @line.sub(/\A\s*\{/, '')
|
92
|
+
ind = @original_line.match(/\A([ \t]*)/)[1]
|
93
|
+
until file.eof?
|
94
|
+
line = file.gets
|
95
|
+
break if line =~ /\A#{ind}\}\s*(#.*)?\Z/
|
96
|
+
result.concat line
|
97
|
+
end
|
98
|
+
if file.eof?
|
99
|
+
error_exit 'syntax error(parse_block).', start_lineno
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@line = $'
|
103
|
+
return result
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
module ExtensionSlaveMethods
|
108
|
+
include CommonMethods
|
109
|
+
include CodeGeneratorMethods
|
110
|
+
|
111
|
+
attr_reader :d_parser, :g_parser, :master
|
112
|
+
|
113
|
+
def do_default
|
114
|
+
end
|
115
|
+
|
116
|
+
def do_parse?
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
def do_parse
|
121
|
+
@line = g_parser.old_line
|
122
|
+
if do_parse?
|
123
|
+
ret = @decorated.parse g_parser.file, @line
|
124
|
+
g_parser.update_context @line
|
125
|
+
ret
|
126
|
+
else
|
127
|
+
do_default
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
module ExtensionSlaveDecoratorMethods
|
133
|
+
include CommonMethods
|
134
|
+
|
135
|
+
def master
|
136
|
+
basis.master
|
137
|
+
end
|
138
|
+
|
139
|
+
def g_parser
|
140
|
+
basis.g_parser
|
141
|
+
end
|
142
|
+
|
143
|
+
def d_parser
|
144
|
+
basis.d_parser
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|