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.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/README.en +4 -19
  3. data/README.ja +42 -79
  4. data/bin/depager +42 -45
  5. data/examples/action_pl0d/pl0d.action.dr +421 -0
  6. data/examples/action_pl0d/test.pl0ds +49 -0
  7. data/examples/c89/c89.dr +493 -496
  8. data/examples/c89/test.c89 +10 -10
  9. data/examples/extension/astdf.rb +10 -0
  10. data/examples/extension/atree.dr +55 -0
  11. data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
  12. data/examples/extension/calc.simple_action.dr +33 -0
  13. data/examples/extension/paction.dr +16 -15
  14. data/examples/extension/pactiontest.dr +14 -14
  15. data/examples/extension/simple_action.rb +44 -0
  16. data/examples/pl0d/pl0ds.dr +337 -334
  17. data/examples/pl0d/test.pl0ds +33 -33
  18. data/examples/rie_calc/calc.rie.dr +57 -0
  19. data/examples/rie_calc/test.calc +4 -0
  20. data/examples/rie_dcuse/dcuse.rie.dr +71 -0
  21. data/examples/rie_dcuse/test.dcuse +1 -0
  22. data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
  23. data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
  24. data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
  25. data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
  26. data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
  27. data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
  28. data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
  29. data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
  30. data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
  31. data/examples/rie_pl0/pl0.rie.dr +450 -0
  32. data/examples/rie_pl0/test.pl0 +10 -0
  33. data/examples/sample_calc/calc.action.dr +33 -33
  34. data/examples/sample_calc/calc.ast.action.dr +65 -66
  35. data/examples/sample_calc/calc.ast.dr +55 -55
  36. data/examples/sample_calc/calc.cst.dr +45 -45
  37. data/examples/sample_calc/calc.dr +43 -43
  38. data/examples/sample_calc/calc.lex.dr +29 -29
  39. data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
  40. data/examples/slex_test/divreg.slex.dr +29 -29
  41. data/examples/slex_test/ljoin.slex.dr +36 -36
  42. data/examples/slex_test/test.divreg +1 -1
  43. data/examples/slex_test/test.ljoin +3 -3
  44. data/lib/depager.rb +582 -670
  45. data/lib/depager/grammar.rb +256 -291
  46. data/lib/depager/lr.rb +574 -579
  47. data/lib/depager/parser.rb +282 -277
  48. data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
  49. data/lib/depager/ruby/plugins/action.rb +53 -43
  50. data/lib/depager/ruby/plugins/ast.dr +364 -269
  51. data/lib/depager/ruby/plugins/ast.rb +1367 -1308
  52. data/lib/depager/ruby/plugins/cst.dr +172 -180
  53. data/lib/depager/ruby/plugins/cst.rb +587 -626
  54. data/lib/depager/ruby/plugins/lex.dr +85 -89
  55. data/lib/depager/ruby/plugins/lex.rb +310 -336
  56. data/lib/depager/ruby/plugins/rie.dr +723 -0
  57. data/lib/depager/ruby/plugins/rie.rb +1653 -0
  58. data/lib/depager/ruby/plugins/slex.dr +202 -200
  59. data/lib/depager/ruby/plugins/slex.rb +780 -817
  60. data/lib/depager/ruby/plugins/srp.rb +56 -51
  61. data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
  62. data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
  63. data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
  64. data/lib/depager/utils.rb +148 -318
  65. data/lib/depager/version.rb +4 -3
  66. metadata +52 -60
  67. data/ChangeLog +0 -16
  68. data/data/depager/pre-setup.rb +0 -3
  69. data/examples/c89/c89.tab.rb +0 -7127
  70. data/examples/pl0d/pl0ds.tab.rb +0 -2698
  71. data/examples/sample_calc/calc.action.tab.rb +0 -457
  72. data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
  73. data/examples/sample_calc/calc.ast.tab.rb +0 -665
  74. data/examples/sample_calc/calc.astdf.dr +0 -54
  75. data/examples/sample_calc/calc.astdf.tab.rb +0 -672
  76. data/examples/sample_calc/calc.atree.tab.rb +0 -451
  77. data/examples/sample_calc/calc.cst.tab.rb +0 -644
  78. data/examples/sample_calc/calc.lex.tab.rb +0 -374
  79. data/examples/sample_calc/calc.nvaction.dr +0 -33
  80. data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
  81. data/examples/sample_calc/calc.tab.rb +0 -365
  82. data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
  83. data/examples/slex_test/divreg.slex.tab.rb +0 -303
  84. data/examples/slex_test/ljoin.slex.tab.rb +0 -370
  85. data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
  86. data/lib/depager/ruby/plugins/astdf.rb +0 -6
  87. data/lib/depager/ruby/plugins/atree.dr +0 -55
  88. data/lib/depager/ruby/plugins/atree.rb +0 -347
  89. data/lib/depager/ruby/plugins/nvaction.rb +0 -19
  90. data/lib/depager/ruby/templates/simple.erb +0 -23
  91. data/setup.rb +0 -1585
@@ -1,180 +1,172 @@
1
- %defext CSTBuilderExtension
2
- %extend Lexer ('plugins/lex.rb')
3
- %extend NVAction ('plugins/nvaction.rb')
4
- %decorate @NVAction
5
- #%decorate ShiftReducePrinter ('plugins/srp.rb')
6
- %inner{
7
- attr_accessor :optouter, :nodes_code
8
- def init_parser
9
- super
10
- @n = 0
11
- @visitor_code = []
12
- @nodes_code = []
13
- @optouter = []
14
- @on_reduce = []
15
- end
16
- def modify_action_code code
17
- code.gsub(/~([a-z_])/, 'node.\1')
18
- end
19
- def post_rhs
20
- code, lineno = '', g_parser.lineno
21
- if g_parser.line =~ /\s*\{/
22
- @line0, @line = g_parser.line0, g_parser.line
23
- code = parse_action
24
-
25
- g_parser.update_context @line
26
- end
27
-
28
- node_name = "#{lhs_name}_#{nrhs}"
29
- accept = ""
30
- nodes = g_parser.rhs.map do |i|
31
- x = g_parser.int_to_sym(i)
32
- if x.class == String
33
- "tx#{x.unpack("H*")[0]}"
34
- else
35
- x = x.to_s
36
- accept << "#{x}.accept(v); " if x =~ /\A[a-z_]+\Z/
37
- x.downcase
38
- end
39
- end
40
- attrc = nodes.map{|i| ":#{i}" }.join(', ')
41
- inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
42
- @nodes_code << %{
43
- class Node_#{node_name} < Node_#{lhs_name}
44
- attr_accessor #{attrc}
45
- def initialize #{nodes.join(', ')}
46
- super()
47
- #{inic}
48
- end
49
- def accept v
50
- #{accept}
51
- v.visit_Node_#{node_name}(self)
52
- end
53
- end
54
- }; #code
55
-
56
- @visitor_code <<
57
- gen_defm_code("visit_Node_#{node_name} node",
58
- modify_action_code(code), lineno)
59
-
60
- args = nodes.inject([]){|r, i| r << "val[#{r.size}]"}
61
- code = "Node_#{node_name}.new(#{args.join(', ')})"
62
- @optouter <<
63
- gen_defm_code("_cst_#{nrules} val", code, lineno)
64
-
65
- @on_reduce[nrules] = ":_cst_#{nrules}"
66
- end
67
- def post_rule_list
68
- code = unindent %{
69
- class Node
70
- def accept
71
- end
72
- end
73
- }; #code
74
- g_parser.optouter << code
75
-
76
- code = unindent %{
77
- class Visitor
78
- $$!!@ CST @!!$$
79
- end
80
- }; #code
81
- g_parser.optouter <<
82
- code.sub!('$$!!@ CST @!!$$', @visitor_code.join) <<
83
- unindent(@nodes_code) <<
84
- gen_action_decorator_code(target_name, paramkey,
85
- @on_reduce, @optouter)
86
- end
87
- %}
88
- %hook pre_rule_list /%CST\{\s*\Z/ skip
89
- %banner '%CST{ ... }'
90
- %%
91
-
92
- %LEX{
93
- /\s+/, /#.*/ { }
94
- /%\}\s*\Z/ { yield nil,nil }
95
- 'Node' { yield token(:NODE, $&) }
96
- '{' ! { ln = lineno; yield token(:ACTION, parse_action, ln) }
97
- %}
98
-
99
- #begin-rule
100
- start:
101
- opt_node opt_visitor
102
- {
103
- code = %{
104
- class Node
105
- $$!!@ NODE @!!$$
106
- end
107
- class Visitor
108
- $$!!@ VISITOR @!!$$
109
- end
110
- }; #code
111
- master.nodes_code <<
112
- code.sub!('$$!!@ NODE @!!$$', _opt_node) \
113
- .sub!('$$!!@ VISITOR @!!$$', _opt_visitor)
114
- }
115
- ;
116
- opt_node:
117
- { '' }
118
- | NODE ACTION { _ACTION.value }
119
- ;
120
- opt_visitor:
121
- { '' }
122
- | VISITOR ACTION { _ACTION.value }
123
- ;
124
- #end-rule
125
- %%
126
- %hook post_lhs /\[/ skip
127
- %banner '[ ... ]'
128
- %inner{
129
- def do_default
130
- master.nodes_code << %{
131
- class Node_#{master.lhs_name} < Node
132
- def initialize
133
- super()
134
- end
135
- end
136
- }; #code
137
- end
138
- %}
139
- %%
140
-
141
- %LEX{
142
- /\A\s+/ { } #skip blank
143
- /""/,/''/,/[0-9]+/,
144
- /\{\s*\}/,/\[\s*\]/,
145
- /nil/ { yield token(:LIT, $&) }
146
- /\A[a-z][a-z_]*/ { yield token(:ID, $&) }
147
- /\A(.)/ { yield token($&, $&) }
148
- %}
149
-
150
- #begin-rule
151
- start:
152
- '[' pair ']'
153
- {
154
- args = []; code = ''
155
- _pair.each do |id, lit|
156
- args << id
157
- code << "#{id} = #{lit}; " if lit
158
- end
159
- attrc = args.map{|i| ":#{i}"}.join(', ')
160
- master.nodes_code << %{
161
- class Node_#{master.lhs_name} < Node
162
- attr_accessor #{attrc}
163
- def initialize
164
- super()
165
- #{code}
166
- end
167
- end
168
- }; #code
169
- }
170
- ;
171
- pair:
172
- expr { [ _expr ] }
173
- | pair ',' expr { _pair << _expr }
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 ('plugins/lex.rb')
3
+ %extend Depager::Action ('plugins/action.rb')
4
+ %decorate @Action
5
+ #%decorate Depager::LALR::ShiftReducePrinter ('plugins/srp.rb')
6
+ %expanded_code_delimiter DEPAGER_EXPANDED_CODE
7
+ %inner{
8
+ attr_accessor :action_code, :nodes_code, :visitor_code
9
+ def init_extension
10
+ @n = 0
11
+ @visitor_code = ''
12
+ @nodes_code = ''
13
+ @action_code = ''
14
+ @on_reduce = []
15
+ end
16
+
17
+ def modify_action_code code
18
+ code.gsub(/\$\.([a-z_])/, 'node.\1')
19
+ end
20
+
21
+ def post_rhs
22
+ code, lineno = '', g_parser.file.lineno
23
+ if g_parser.line =~ /\s*\{/
24
+ @original_line, @line = g_parser.original_line, g_parser.line
25
+ code = parse_block
26
+
27
+ g_parser.update_context @line
28
+ end
29
+
30
+ node_name = "#{g_parser.lhs_name}_#{g_parser.nrhs}"
31
+ accept = ""
32
+ nodes = g_parser.rhs.map do |i|
33
+ x = g_parser.int_to_sym(i)
34
+ if x.class == String
35
+ "tx#{x.unpack("H*")[0]}"
36
+ else
37
+ x = x.to_s
38
+ accept << "#{x}.accept(v); " if x =~ /\A[a-z_]+\Z/
39
+ x.downcase
40
+ end
41
+ end
42
+ attrc = nodes.map{|i| ":#{i}" }.join(', ')
43
+ inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
44
+ @nodes_code << %{
45
+ class Node_#{node_name} < Node_#{g_parser.lhs_name}
46
+ attr_accessor #{attrc}
47
+ def initialize #{nodes.join(', ')}
48
+ super()
49
+ #{inic}
50
+ end
51
+ def accept v
52
+ #{accept}
53
+ v.visit_Node_#{node_name}(self)
54
+ end
55
+ end
56
+ } #code
57
+
58
+ @visitor_code <<
59
+ expand_inline_code(modify_action_code(code), lineno, :wrap => "def visit_Node_#{node_name} node")
60
+
61
+ args = nodes.inject([]){|r, i| r << "val[#{r.size}]"}
62
+ code = "#{target_namespace}::Node_#{node_name}.new(#{args.join(', ')})"
63
+ n = g_parser.rules.size-1
64
+ @action_code <<
65
+ expand_inline_code(code, lineno, :wrap => "def _cst_#{n} val")
66
+
67
+ @on_reduce[n] = ":_cst_#{n}"
68
+ end
69
+
70
+ def term_extension
71
+ g_parser.outer_code << "module #{target_namespace}\n"
72
+ g_parser.outer_code << @nodes_code
73
+ g_parser.outer_code << %{
74
+ class Visitor
75
+ %s
76
+ end
77
+ } % @visitor_code #code
78
+ g_parser.outer_code << "end\n"
79
+ g_parser.outer_code << generate_action_decorator_code(@on_reduce, @action_code)
80
+ end
81
+ %}
82
+ %hook pre_rule_list /%CST\{\s*\Z/ skip
83
+ %banner '%CST{ ... }'
84
+ %%
85
+
86
+ %LEX{
87
+ /\s+/, /#.*/ { }
88
+ /%\}\s*\Z/ { yield nil,nil }
89
+ 'Node' { yield token(:NODE, $&) }
90
+ 'Visitor' { yield token(:VISITOR, $&) }
91
+ '{' ! { lineno = file.lineno; yield token(:ACTION, parse_block, lineno) }
92
+ %}
93
+
94
+ #begin-rule
95
+ start:
96
+ opt_node opt_visitor
97
+ {
98
+ master.nodes_code << %{
99
+ class Node
100
+ def accept
101
+ end
102
+ %s
103
+ end
104
+ } % _opt_node #code
105
+ master.visitor_code << _opt_visitor
106
+ }
107
+ ;
108
+ opt_node:
109
+ { '' }
110
+ | NODE ACTION { _ACTION.value }
111
+ ;
112
+ opt_visitor:
113
+ { '' }
114
+ | VISITOR ACTION { _ACTION.value }
115
+ ;
116
+ #end-rule
117
+ %%
118
+ %hook post_lhs /\[/ skip
119
+ %banner '[ ... ]'
120
+ %inner{
121
+ def do_default
122
+ master.nodes_code << %{
123
+ class Node_#{g_parser.lhs_name} < Node
124
+ def initialize
125
+ super()
126
+ end
127
+ end
128
+ } #code
129
+ end
130
+ %}
131
+ %%
132
+
133
+ %LEX{
134
+ /\A\s+/ { } #skip blank
135
+ /""/,/''/,/[0-9]+/,
136
+ /\{\s*\}/,/\[\s*\]/,
137
+ /nil/ { yield token(:LIT, $&) }
138
+ /\A[a-z][a-z_]*/ { yield token(:ID, $&) }
139
+ /\A(.)/ { yield token($&, $&) }
140
+ %}
141
+
142
+ #begin-rule
143
+ start:
144
+ '[' pair ']'
145
+ {
146
+ args = []; code = ''
147
+ _pair.each do |id, lit|
148
+ args << id
149
+ code << "#{id} = #{lit}; " if lit
150
+ end
151
+ attrc = args.map{|i| ":#{i}"}.join(', ')
152
+ master.nodes_code << %{
153
+ class Node_#{g_parser.lhs_name} < Node
154
+ attr_accessor #{attrc}
155
+ def initialize
156
+ super
157
+ #{code}
158
+ end
159
+ end
160
+ } #code
161
+ }
162
+ ;
163
+ pair:
164
+ expr { [ _expr ] }
165
+ | pair ',' expr { _pair << _expr }
166
+ ;
167
+ expr:
168
+ ID { [ _ID.value, nil] }
169
+ | ID '=' LIT { [ _ID.value, _LIT.value ] }
170
+ ;
171
+ #end-rule
172
+ %%
@@ -1,626 +1,587 @@
1
-
2
- ###
3
- ### CSTBuilderExtension - Depager Extension (master)
4
- ###
5
- require 'pp.rb'
6
- require 'depager/parser.rb'
7
-
8
-
9
- module D4CSTBuilderExtension #:nodoc:all
10
- end
11
-
12
- class CSTBuilderExtension #:nodoc:all
13
- include Depager::ExtensionUtils
14
-
15
- attr_accessor :h2p
16
-
17
- def initialize
18
- @master = self
19
- @hook = []
20
- @h2p = {}
21
- init_parser
22
- end
23
-
24
- def __regext__ p
25
- super p, :default, nil
26
-
27
- @hook[0] = CSTBuilderExtension_post_lhs.new(p, @nparam, self)
28
- @h2p['post_lhs'] = @hook[0]
29
- p.hooks[:post_lhs].push [@hook[0], :do_parse]
30
-
31
- @hook[1] = CSTBuilderExtension_pre_rule_list.new(p, @nparam, self)
32
- @h2p['pre_rule_list'] = @hook[1]
33
- p.hooks[:pre_rule_list].push [@hook[1], :do_parse]
34
-
35
- regext p
36
- end
37
-
38
- ### Inner Code
39
- attr_accessor :optouter, :nodes_code
40
- def init_parser
41
- super
42
- @n = 0
43
- @visitor_code = []
44
- @nodes_code = []
45
- @optouter = []
46
- @on_reduce = []
47
- end
48
- def modify_action_code code
49
- code.gsub(/~([a-z_])/, 'node.\1')
50
- end
51
- def post_rhs
52
- code, lineno = '', g_parser.lineno
53
- if g_parser.line =~ /\s*\{/
54
- @line0, @line = g_parser.line0, g_parser.line
55
- code = parse_action
56
-
57
- g_parser.update_context @line
58
- end
59
-
60
- node_name = "#{lhs_name}_#{nrhs}"
61
- accept = ""
62
- nodes = g_parser.rhs.map do |i|
63
- x = g_parser.int_to_sym(i)
64
- if x.class == String
65
- "tx#{x.unpack("H*")[0]}"
66
- else
67
- x = x.to_s
68
- accept << "#{x}.accept(v); " if x =~ /\A[a-z_]+\Z/
69
- x.downcase
70
- end
71
- end
72
- attrc = nodes.map{|i| ":#{i}" }.join(', ')
73
- inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
74
- @nodes_code << %{
75
- class Node_#{node_name} < Node_#{lhs_name}
76
- attr_accessor #{attrc}
77
- def initialize #{nodes.join(', ')}
78
- super()
79
- #{inic}
80
- end
81
- def accept v
82
- #{accept}
83
- v.visit_Node_#{node_name}(self)
84
- end
85
- end
86
- }; #code
87
-
88
- @visitor_code <<
89
- gen_defm_code("visit_Node_#{node_name} node",
90
- modify_action_code(code), lineno)
91
-
92
- args = nodes.inject([]){|r, i| r << "val[#{r.size}]"}
93
- code = "Node_#{node_name}.new(#{args.join(', ')})"
94
- @optouter <<
95
- gen_defm_code("_cst_#{nrules} val", code, lineno)
96
-
97
- @on_reduce[nrules] = ":_cst_#{nrules}"
98
- end
99
- def post_rule_list
100
- code = unindent %{
101
- class Node
102
- def accept
103
- end
104
- end
105
- }; #code
106
- g_parser.optouter << code
107
-
108
- code = unindent %{
109
- class Visitor
110
- $$!!@ CST @!!$$
111
- end
112
- }; #code
113
- g_parser.optouter <<
114
- code.sub!('$$!!@ CST @!!$$', @visitor_code.join) <<
115
- unindent(@nodes_code) <<
116
- gen_action_decorator_code(target_name, paramkey,
117
- @on_reduce, @optouter)
118
- end
119
-
120
- end
121
-
122
- ### Outer Code
123
-
124
- ###
125
- ### CSTBuilderExtension_pre_rule_list - Part of Depager Extension (slave)
126
- ###
127
- module D4CSTBuilderExtension_pre_rule_list #:nodoc:all
128
- end
129
-
130
- class CSTBuilderExtension_pre_rule_list < Depager::LALR::Basis #:nodoc:all
131
- include Depager::ExtensionUtils
132
-
133
-
134
- ### Reduce Table
135
- reduce_table = [
136
- [ -1, 1 ],
137
- [ 0, 2 ],
138
- [ 1, 0 ],
139
- [ 1, 2 ],
140
- [ 2, 0 ],
141
- [ 2, 2 ],
142
- ]
143
- ### Extension Params
144
- nparams = {
145
- 'NVAction' => 2,
146
- }
147
- ### Term to Int
148
- t2i = {
149
- nil => 0,
150
- false => 1,
151
- :NODE => 2,
152
- :ACTION => 3,
153
- :VISITOR => 4,
154
- }
155
- ### Int to Term
156
- i2t = [
157
- nil,
158
- false,
159
- :NODE,
160
- :ACTION,
161
- :VISITOR,
162
- ]
163
- ### Action Table
164
- action_table = [
165
- [ nil, nil, 1, nil, nil, ],
166
- [ nil, nil, nil, 4, nil, ],
167
- [ ACC, nil, nil, nil, nil, ],
168
- [ nil, nil, nil, nil, 5, ],
169
- [ nil, nil, nil, nil, nil, ],
170
- [ nil, nil, nil, 7, nil, ],
171
- [ nil, nil, nil, nil, nil, ],
172
- [ nil, nil, nil, nil, nil, ],
173
- ]
174
- ### Default Reduce Table
175
- defred_table = [
176
- -2,
177
- nil,
178
- nil,
179
- -4,
180
- -3,
181
- nil,
182
- -1,
183
- -5,
184
- ]
185
- defred_after_shift_table = [
186
- nil,
187
- nil,
188
- nil,
189
- nil,
190
- -3,
191
- nil,
192
- -1,
193
- -5,
194
- ]
195
- ### Nonterm to Int
196
- nt2i = {
197
- :start => 0,
198
- :opt_node => 1,
199
- :opt_visitor => 2,
200
- }
201
- ### Int to Nonterm
202
- i2nt = [
203
- :start,
204
- :opt_node,
205
- :opt_visitor,
206
- ]
207
- ### Goto Table
208
- goto_table = [
209
- [ 2, 3, nil, ],
210
- [ nil, nil, nil, ],
211
- [ nil, nil, nil, ],
212
- [ nil, nil, 6, ],
213
- [ nil, nil, nil, ],
214
- [ nil, nil, nil, ],
215
- [ nil, nil, nil, ],
216
- [ nil, nil, nil, ],
217
- ]
218
-
219
- Tables = [ reduce_table, nparams, action_table,
220
- defred_table, defred_after_shift_table, goto_table,
221
- t2i, i2t, nt2i, i2nt ]
222
-
223
- attr_accessor :p, :m
224
- def initialize p, nparam, master = nil
225
- super()
226
- @g_parser = @p = p
227
- @master = @m = master
228
- @nparam = nparam
229
- @dect = D4CSTBuilderExtension_pre_rule_list::NVAction.new(self)
230
- init_parser
231
- end
232
-
233
-
234
- def do_parse?
235
- if @line =~ /^\s*%CST\{\s*\Z/
236
- @line = $'
237
- true
238
- else
239
- false
240
- end
241
- end
242
-
243
-
244
- def banner
245
- "%CST{ ... } / #{@master.class.name}"
246
- end
247
-
248
- ### Inner Code
249
-
250
- def lex
251
- begin
252
- until @line.empty?
253
- case @line
254
-
255
- when /\A\s+/, /\A#.*/
256
- @oldline = @line; @line = $'
257
-
258
-
259
-
260
- when /\A%\}\s*\Z/
261
- @oldline = @line; @line = $'
262
- yield nil,nil
263
-
264
-
265
- when /\ANode/
266
- @oldline = @line; @line = $'
267
- yield token(:NODE, $&)
268
-
269
-
270
- when /\A\{/
271
- #
272
- ln = lineno; yield token(:ACTION, parse_action, ln)
273
-
274
-
275
- else
276
- raise RuntimeError, "must not happen #{@line}"
277
- end
278
- end
279
- end while @line0 = @line = getline
280
- yield nil, nil
281
- end
282
-
283
- end
284
-
285
- ### Outer Code
286
-
287
- class D4CSTBuilderExtension_pre_rule_list::NVAction < Depager::LALR::Action #:nodoc:all
288
- include Depager::DecoratorUtils
289
-
290
- on_reduce = [
291
- nil,
292
- :_act_0,
293
- :_act_1,
294
- :_act_2,
295
- :_act_3,
296
- :_act_4,
297
-
298
- ]
299
- Tables = [on_reduce]
300
- def initialize inside
301
- super inside, 'NVAction'
302
- @on_reduce, = self.class::Tables
303
- init_parser
304
- end
305
-
306
-
307
- module_eval <<-'.,.,122745803312555.,.,', 'cst.dr', 100
308
- def _act_0 val
309
- _opt_node, _opt_visitor, = *val
310
-
311
- code = %{
312
- class Node
313
- $$!!@ NODE @!!$$
314
- end
315
- class Visitor
316
- $$!!@ VISITOR @!!$$
317
- end
318
- }; #code
319
- master.nodes_code <<
320
- code.sub!('$$!!@ NODE @!!$$', _opt_node) \
321
- .sub!('$$!!@ VISITOR @!!$$', _opt_visitor)
322
-
323
- end
324
- .,.,122745803312555.,.,
325
-
326
- module_eval <<-'.,.,12274580333994.,.,', 'cst.dr', 115
327
- def _act_1 val
328
- ''
329
-
330
- end
331
- .,.,12274580333994.,.,
332
-
333
- module_eval <<-'.,.,122745803355803.,.,', 'cst.dr', 116
334
- def _act_2 val
335
- _NODE, _ACTION, = *val
336
- _ACTION.value
337
-
338
- end
339
- .,.,122745803355803.,.,
340
-
341
- module_eval <<-'.,.,122745803313768.,.,', 'cst.dr', 119
342
- def _act_3 val
343
- ''
344
-
345
- end
346
- .,.,122745803313768.,.,
347
-
348
- module_eval <<-'.,.,122745803342911.,.,', 'cst.dr', 120
349
- def _act_4 val
350
- _VISITOR, _ACTION, = *val
351
- _ACTION.value
352
-
353
- end
354
- .,.,122745803342911.,.,
355
-
356
- end
357
-
358
-
359
- ###
360
- ### CSTBuilderExtension_post_lhs - Part of Depager Extension (slave)
361
- ###
362
- module D4CSTBuilderExtension_post_lhs #:nodoc:all
363
- end
364
-
365
- class CSTBuilderExtension_post_lhs < Depager::LALR::Basis #:nodoc:all
366
- include Depager::ExtensionUtils
367
-
368
-
369
- ### Reduce Table
370
- reduce_table = [
371
- [ -1, 1 ],
372
- [ 0, 3 ],
373
- [ 1, 1 ],
374
- [ 1, 3 ],
375
- [ 2, 1 ],
376
- [ 2, 3 ],
377
- ]
378
- ### Extension Params
379
- nparams = {
380
- 'NVAction' => 2,
381
- }
382
- ### Term to Int
383
- t2i = {
384
- nil => 0,
385
- false => 1,
386
- "[" => 2,
387
- "]" => 3,
388
- "," => 4,
389
- :ID => 5,
390
- "=" => 6,
391
- :LIT => 7,
392
- }
393
- ### Int to Term
394
- i2t = [
395
- nil,
396
- false,
397
- "[",
398
- "]",
399
- ",",
400
- :ID,
401
- "=",
402
- :LIT,
403
- ]
404
- ### Action Table
405
- action_table = [
406
- [ nil, nil, 1, nil, nil, nil, nil, nil, ],
407
- [ nil, nil, nil, nil, nil, 5, nil, nil, ],
408
- [ ACC, nil, nil, nil, nil, nil, nil, nil, ],
409
- [ nil, nil, nil, 6, 7, nil, nil, nil, ],
410
- [ nil, nil, nil, nil, nil, nil, nil, nil, ],
411
- [ nil, nil, nil, nil, nil, nil, 8, nil, ],
412
- [ nil, nil, nil, nil, nil, nil, nil, nil, ],
413
- [ nil, nil, nil, nil, nil, 5, nil, nil, ],
414
- [ nil, nil, nil, nil, nil, nil, nil, 10, ],
415
- [ nil, nil, nil, nil, nil, nil, nil, nil, ],
416
- [ nil, nil, nil, nil, nil, nil, nil, nil, ],
417
- ]
418
- ### Default Reduce Table
419
- defred_table = [
420
- nil,
421
- nil,
422
- nil,
423
- nil,
424
- -2,
425
- -4,
426
- -1,
427
- nil,
428
- nil,
429
- -3,
430
- -5,
431
- ]
432
- defred_after_shift_table = [
433
- nil,
434
- nil,
435
- nil,
436
- nil,
437
- -2,
438
- nil,
439
- -1,
440
- nil,
441
- nil,
442
- -3,
443
- -5,
444
- ]
445
- ### Nonterm to Int
446
- nt2i = {
447
- :start => 0,
448
- :pair => 1,
449
- :expr => 2,
450
- }
451
- ### Int to Nonterm
452
- i2nt = [
453
- :start,
454
- :pair,
455
- :expr,
456
- ]
457
- ### Goto Table
458
- goto_table = [
459
- [ 2, nil, nil, ],
460
- [ nil, 3, 4, ],
461
- [ nil, nil, nil, ],
462
- [ nil, nil, nil, ],
463
- [ nil, nil, nil, ],
464
- [ nil, nil, nil, ],
465
- [ nil, nil, nil, ],
466
- [ nil, nil, 9, ],
467
- [ nil, nil, nil, ],
468
- [ nil, nil, nil, ],
469
- [ nil, nil, nil, ],
470
- ]
471
-
472
- Tables = [ reduce_table, nparams, action_table,
473
- defred_table, defred_after_shift_table, goto_table,
474
- t2i, i2t, nt2i, i2nt ]
475
-
476
- attr_accessor :p, :m
477
- def initialize p, nparam, master = nil
478
- super()
479
- @g_parser = @p = p
480
- @master = @m = master
481
- @nparam = nparam
482
- @dect = D4CSTBuilderExtension_post_lhs::NVAction.new(self)
483
- init_parser
484
- end
485
-
486
-
487
- def do_parse?
488
- if @line =~ /^\s*\[/
489
- @line = $'
490
- true
491
- else
492
- false
493
- end
494
- end
495
-
496
-
497
- def banner
498
- "[ ... ] / #{@master.class.name}"
499
- end
500
-
501
- ### Inner Code
502
-
503
- def lex
504
- begin
505
- until @line.empty?
506
- case @line
507
-
508
- when /\A\A\s+/
509
- @oldline = @line; @line = $'
510
-
511
-
512
-
513
- when /\A""/, /\A''/, /\A[0-9]+/, /\A\{\s*\}/, /\A\[\s*\]/, /\Anil/
514
- @oldline = @line; @line = $'
515
- yield token(:LIT, $&)
516
-
517
-
518
- when /\A\A[a-z][a-z_]*/
519
- @oldline = @line; @line = $'
520
- yield token(:ID, $&)
521
-
522
-
523
- when /\A\A(.)/
524
- @oldline = @line; @line = $'
525
- yield token($&, $&)
526
-
527
-
528
- else
529
- raise RuntimeError, "must not happen #{@line}"
530
- end
531
- end
532
- end while @line0 = @line = getline
533
- yield nil, nil
534
- end
535
- def do_default
536
- master.nodes_code << %{
537
- class Node_#{master.lhs_name} < Node
538
- def initialize
539
- super()
540
- end
541
- end
542
- }; #code
543
- end
544
-
545
- end
546
-
547
- ### Outer Code
548
-
549
- class D4CSTBuilderExtension_post_lhs::NVAction < Depager::LALR::Action #:nodoc:all
550
- include Depager::DecoratorUtils
551
-
552
- on_reduce = [
553
- nil,
554
- :_act_0,
555
- :_act_1,
556
- :_act_2,
557
- :_act_3,
558
- :_act_4,
559
-
560
- ]
561
- Tables = [on_reduce]
562
- def initialize inside
563
- super inside, 'NVAction'
564
- @on_reduce, = self.class::Tables
565
- init_parser
566
- end
567
-
568
-
569
- module_eval <<-'.,.,122745803313978.,.,', 'cst.dr', 151
570
- def _act_0 val
571
- _, _pair, _, = *val
572
-
573
- args = []; code = ''
574
- _pair.each do |id, lit|
575
- args << id
576
- code << "#{id} = #{lit}; " if lit
577
- end
578
- attrc = args.map{|i| ":#{i}"}.join(', ')
579
- master.nodes_code << %{
580
- class Node_#{master.lhs_name} < Node
581
- attr_accessor #{attrc}
582
- def initialize
583
- super()
584
- #{code}
585
- end
586
- end
587
- }; #code
588
-
589
- end
590
- .,.,122745803313978.,.,
591
-
592
- module_eval <<-'.,.,122745803351295.,.,', 'cst.dr', 170
593
- def _act_1 val
594
- _expr, = *val
595
- [ _expr ]
596
-
597
- end
598
- .,.,122745803351295.,.,
599
-
600
- module_eval <<-'.,.,122745803357565.,.,', 'cst.dr', 171
601
- def _act_2 val
602
- _pair, _, _expr, = *val
603
- _pair << _expr
604
-
605
- end
606
- .,.,122745803357565.,.,
607
-
608
- module_eval <<-'.,.,122745803313793.,.,', 'cst.dr', 174
609
- def _act_3 val
610
- _ID, = *val
611
- [ _ID.value, nil]
612
-
613
- end
614
- .,.,122745803313793.,.,
615
-
616
- module_eval <<-'.,.,12274580337259.,.,', 'cst.dr', 175
617
- def _act_4 val
618
- _ID, _, _LIT, = *val
619
- [ _ID.value, _LIT.value ]
620
-
621
- end
622
- .,.,12274580337259.,.,
623
-
624
- end
625
-
626
-
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ###
4
+ ### Depager::CSTBuilderExtension - Depager Extension (master)
5
+ ###
6
+ require 'depager/parser.rb'
7
+
8
+
9
+ module Depager ; end
10
+
11
+ class Depager::CSTBuilderExtension < Depager::Extension
12
+
13
+ def initialize
14
+ @master = self
15
+ @slaves = []
16
+ end
17
+
18
+ def extension_registered g_parser
19
+ super g_parser
20
+
21
+ @slaves[0] = Depager::CSTBuilderExtension::Slave_pre_rule_list::Parser.new(g_parser, self)
22
+ g_parser.hooks[:pre_rule_list].push [@slaves[0], :do_parse]
23
+ @slaves[1] = Depager::CSTBuilderExtension::Slave_post_lhs::Parser.new(g_parser, self)
24
+ g_parser.hooks[:post_lhs].push [@slaves[1], :do_parse]
25
+ end
26
+
27
+ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 8
28
+ attr_accessor :action_code, :nodes_code, :visitor_code
29
+ def init_extension
30
+ @n = 0
31
+ @visitor_code = ''
32
+ @nodes_code = ''
33
+ @action_code = ''
34
+ @on_reduce = []
35
+ end
36
+
37
+ def modify_action_code code
38
+ code.gsub(/\$\.([a-z_])/, 'node.\1')
39
+ end
40
+
41
+ def post_rhs
42
+ code, lineno = '', g_parser.file.lineno
43
+ if g_parser.line =~ /\s*\{/
44
+ @original_line, @line = g_parser.original_line, g_parser.line
45
+ code = parse_block
46
+
47
+ g_parser.update_context @line
48
+ end
49
+
50
+ node_name = "#{g_parser.lhs_name}_#{g_parser.nrhs}"
51
+ accept = ""
52
+ nodes = g_parser.rhs.map do |i|
53
+ x = g_parser.int_to_sym(i)
54
+ if x.class == String
55
+ "tx#{x.unpack("H*")[0]}"
56
+ else
57
+ x = x.to_s
58
+ accept << "#{x}.accept(v); " if x =~ /\A[a-z_]+\Z/
59
+ x.downcase
60
+ end
61
+ end
62
+ attrc = nodes.map{|i| ":#{i}" }.join(', ')
63
+ inic = nodes.map{|i| "@#{i} = #{i}"}.join('; ')
64
+ @nodes_code << %{
65
+ class Node_#{node_name} < Node_#{g_parser.lhs_name}
66
+ attr_accessor #{attrc}
67
+ def initialize #{nodes.join(', ')}
68
+ super()
69
+ #{inic}
70
+ end
71
+ def accept v
72
+ #{accept}
73
+ v.visit_Node_#{node_name}(self)
74
+ end
75
+ end
76
+ } #code
77
+
78
+ @visitor_code <<
79
+ expand_inline_code(modify_action_code(code), lineno, :wrap => "def visit_Node_#{node_name} node")
80
+
81
+ args = nodes.inject([]){|r, i| r << "val[#{r.size}]"}
82
+ code = "#{target_namespace}::Node_#{node_name}.new(#{args.join(', ')})"
83
+ n = g_parser.rules.size-1
84
+ @action_code <<
85
+ expand_inline_code(code, lineno, :wrap => "def _cst_#{n} val")
86
+
87
+ @on_reduce[n] = ":_cst_#{n}"
88
+ end
89
+
90
+ def term_extension
91
+ g_parser.outer_code << "module #{target_namespace}\n"
92
+ g_parser.outer_code << @nodes_code
93
+ g_parser.outer_code << %{
94
+ class Visitor
95
+ %s
96
+ end
97
+ } % @visitor_code #code
98
+ g_parser.outer_code << "end\n"
99
+ g_parser.outer_code << generate_action_decorator_code(@on_reduce, @action_code)
100
+ end
101
+
102
+ DEPAGER_EXPANDED_CODE
103
+
104
+ end
105
+
106
+ ###
107
+ ### Depager::CSTBuilderExtension::Slave_pre_rule_list - Part of Depager Extension (slave)
108
+ ###
109
+
110
+ module Depager::CSTBuilderExtension::Slave_pre_rule_list #:nodoc:all
111
+ class Parser < Depager::LALR::Basis #:nodoc:all
112
+ include Depager::Utils::ExtensionSlaveMethods
113
+
114
+
115
+ ### Reduce Table
116
+ reduce_table = [
117
+ [ -1, 1 ],
118
+ [ 0, 2 ],
119
+ [ 1, 0 ],
120
+ [ 1, 2 ],
121
+ [ 2, 0 ],
122
+ [ 2, 2 ],
123
+ ]
124
+ ### Term to Int
125
+ term_to_int = {
126
+ nil => 0,
127
+ false => 1,
128
+ :NODE => 2,
129
+ :ACTION => 3,
130
+ :VISITOR => 4,
131
+ }
132
+ ### Int to Term
133
+ int_to_term = [
134
+ nil,
135
+ false,
136
+ :NODE,
137
+ :ACTION,
138
+ :VISITOR,
139
+ ]
140
+ ### Action Table
141
+ action_table = [
142
+ [ nil, nil, 3, nil, nil, ],
143
+ [ ACC, nil, nil, nil, nil, ],
144
+ [ nil, nil, nil, nil, 5, ],
145
+ [ nil, nil, nil, 6, nil, ],
146
+ [ nil, nil, nil, nil, nil, ],
147
+ [ nil, nil, nil, 7, nil, ],
148
+ [ nil, nil, nil, nil, nil, ],
149
+ [ nil, nil, nil, nil, nil, ],
150
+ ]
151
+ ### Default Reduce Table
152
+ defred_table = [
153
+ -2,
154
+ nil,
155
+ -4,
156
+ nil,
157
+ -1,
158
+ nil,
159
+ -3,
160
+ -5,
161
+ ]
162
+ defred_after_shift_table = [
163
+ nil,
164
+ nil,
165
+ nil,
166
+ nil,
167
+ -1,
168
+ nil,
169
+ -3,
170
+ -5,
171
+ ]
172
+ ### Nonterm to Int
173
+ nonterm_to_int = {
174
+ :start => 0,
175
+ :opt_node => 1,
176
+ :opt_visitor => 2,
177
+ }
178
+ ### Int to Nonterm
179
+ int_to_nonterm = [
180
+ :start,
181
+ :opt_node,
182
+ :opt_visitor,
183
+ ]
184
+ ### Goto Table
185
+ goto_table = [
186
+ [ 1, 2, nil, ],
187
+ [ nil, nil, nil, ],
188
+ [ nil, nil, 4, ],
189
+ [ nil, nil, nil, ],
190
+ [ nil, nil, nil, ],
191
+ [ nil, nil, nil, ],
192
+ [ nil, nil, nil, ],
193
+ [ nil, nil, nil, ],
194
+ ]
195
+
196
+ Tables = [ reduce_table, action_table,
197
+ defred_table, defred_after_shift_table, goto_table,
198
+ term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
199
+
200
+ def initialize g_parser, master
201
+ super()
202
+ @g_parser = g_parser
203
+ @d_parser = g_parser.d_parser
204
+ @master = master
205
+ @decorated = Action.new(self)
206
+ end
207
+
208
+
209
+ def do_parse?
210
+ if @line.match(/^\s*%CST\{\s*\Z/)
211
+ @line = $'
212
+ true
213
+ else
214
+ false
215
+ end
216
+ end
217
+
218
+
219
+ def banner
220
+ "%CST{ ... } / Depager::CSTBuilderExtension"
221
+ end
222
+
223
+
224
+ def lex
225
+ begin
226
+ until @line.empty?
227
+ case @line
228
+
229
+ when /\A\s+/, /\A#.*/
230
+ @line = $'
231
+
232
+
233
+
234
+ when /\A%\}\s*\Z/
235
+ @line = $'
236
+ yield nil,nil
237
+
238
+
239
+ when /\ANode/
240
+ @line = $'
241
+ yield token(:NODE, $&)
242
+
243
+
244
+ when /\AVisitor/
245
+ @line = $'
246
+ yield token(:VISITOR, $&)
247
+
248
+
249
+ when /\A\{/
250
+ #
251
+ lineno = file.lineno; yield token(:ACTION, parse_block, lineno)
252
+
253
+
254
+ else
255
+ raise RuntimeError, "must not happen #{@line}"
256
+ end
257
+ end
258
+ end while @original_line = @line = file.gets
259
+ yield nil, nil
260
+ end
261
+
262
+ end
263
+ end
264
+
265
+
266
+ class Depager::CSTBuilderExtension::Slave_pre_rule_list::Action < Depager::LALR::Action #:nodoc:all
267
+ include Depager::Utils::ExtensionSlaveDecoratorMethods
268
+
269
+ on_reduce = [
270
+ nil,
271
+ :_act_1,
272
+ :_act_2,
273
+ :_act_3,
274
+ :_act_4,
275
+ :_act_5,
276
+
277
+ ]
278
+ Tables = [ on_reduce ]
279
+
280
+
281
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 95
282
+ def _act_1 val
283
+ _opt_node, _opt_visitor, = *val
284
+
285
+ master.nodes_code << %{
286
+ class Node
287
+ def accept
288
+ end
289
+ %s
290
+ end
291
+ } % _opt_node #code
292
+ master.visitor_code << _opt_visitor
293
+
294
+ end
295
+ DEPAGER_EXPANDED_CODE
296
+
297
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 107
298
+ def _act_2 val
299
+ ''
300
+
301
+ end
302
+ DEPAGER_EXPANDED_CODE
303
+
304
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 108
305
+ def _act_3 val
306
+ _NODE, _ACTION, = *val
307
+ _ACTION.value
308
+
309
+ end
310
+ DEPAGER_EXPANDED_CODE
311
+
312
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 111
313
+ def _act_4 val
314
+ ''
315
+
316
+ end
317
+ DEPAGER_EXPANDED_CODE
318
+
319
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 112
320
+ def _act_5 val
321
+ _VISITOR, _ACTION, = *val
322
+ _ACTION.value
323
+
324
+ end
325
+ DEPAGER_EXPANDED_CODE
326
+
327
+
328
+ end
329
+
330
+ ###
331
+ ### Depager::CSTBuilderExtension::Slave_post_lhs - Part of Depager Extension (slave)
332
+ ###
333
+
334
+ module Depager::CSTBuilderExtension::Slave_post_lhs #:nodoc:all
335
+ class Parser < Depager::LALR::Basis #:nodoc:all
336
+ include Depager::Utils::ExtensionSlaveMethods
337
+
338
+
339
+ ### Reduce Table
340
+ reduce_table = [
341
+ [ -1, 1 ],
342
+ [ 0, 3 ],
343
+ [ 1, 1 ],
344
+ [ 1, 3 ],
345
+ [ 2, 1 ],
346
+ [ 2, 3 ],
347
+ ]
348
+ ### Term to Int
349
+ term_to_int = {
350
+ nil => 0,
351
+ false => 1,
352
+ "[" => 2,
353
+ "]" => 3,
354
+ "," => 4,
355
+ :ID => 5,
356
+ "=" => 6,
357
+ :LIT => 7,
358
+ }
359
+ ### Int to Term
360
+ int_to_term = [
361
+ nil,
362
+ false,
363
+ "[",
364
+ "]",
365
+ ",",
366
+ :ID,
367
+ "=",
368
+ :LIT,
369
+ ]
370
+ ### Action Table
371
+ action_table = [
372
+ [ nil, nil, 2, nil, nil, nil, nil, nil, ],
373
+ [ ACC, nil, nil, nil, nil, nil, nil, nil, ],
374
+ [ nil, nil, nil, nil, nil, 5, nil, nil, ],
375
+ [ nil, nil, nil, 6, 7, nil, nil, nil, ],
376
+ [ nil, nil, nil, nil, nil, nil, nil, nil, ],
377
+ [ nil, nil, nil, nil, nil, nil, 8, nil, ],
378
+ [ nil, nil, nil, nil, nil, nil, nil, nil, ],
379
+ [ nil, nil, nil, nil, nil, 5, nil, nil, ],
380
+ [ nil, nil, nil, nil, nil, nil, nil, 10, ],
381
+ [ nil, nil, nil, nil, nil, nil, nil, nil, ],
382
+ [ nil, nil, nil, nil, nil, nil, nil, nil, ],
383
+ ]
384
+ ### Default Reduce Table
385
+ defred_table = [
386
+ nil,
387
+ nil,
388
+ nil,
389
+ nil,
390
+ -2,
391
+ -4,
392
+ -1,
393
+ nil,
394
+ nil,
395
+ -3,
396
+ -5,
397
+ ]
398
+ defred_after_shift_table = [
399
+ nil,
400
+ nil,
401
+ nil,
402
+ nil,
403
+ -2,
404
+ nil,
405
+ -1,
406
+ nil,
407
+ nil,
408
+ -3,
409
+ -5,
410
+ ]
411
+ ### Nonterm to Int
412
+ nonterm_to_int = {
413
+ :start => 0,
414
+ :pair => 1,
415
+ :expr => 2,
416
+ }
417
+ ### Int to Nonterm
418
+ int_to_nonterm = [
419
+ :start,
420
+ :pair,
421
+ :expr,
422
+ ]
423
+ ### Goto Table
424
+ goto_table = [
425
+ [ 1, nil, nil, ],
426
+ [ nil, nil, nil, ],
427
+ [ nil, 3, 4, ],
428
+ [ nil, nil, nil, ],
429
+ [ nil, nil, nil, ],
430
+ [ nil, nil, nil, ],
431
+ [ nil, nil, nil, ],
432
+ [ nil, nil, 9, ],
433
+ [ nil, nil, nil, ],
434
+ [ nil, nil, nil, ],
435
+ [ nil, nil, nil, ],
436
+ ]
437
+
438
+ Tables = [ reduce_table, action_table,
439
+ defred_table, defred_after_shift_table, goto_table,
440
+ term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
441
+
442
+ def initialize g_parser, master
443
+ super()
444
+ @g_parser = g_parser
445
+ @d_parser = g_parser.d_parser
446
+ @master = master
447
+ @decorated = Action.new(self)
448
+ end
449
+
450
+
451
+ def do_parse?
452
+ if @line.match(/^\s*\[/)
453
+ @line = $'
454
+ true
455
+ else
456
+ false
457
+ end
458
+ end
459
+
460
+
461
+ def banner
462
+ "[ ... ] / Depager::CSTBuilderExtension"
463
+ end
464
+
465
+
466
+ def lex
467
+ begin
468
+ until @line.empty?
469
+ case @line
470
+
471
+ when /\A\A\s+/
472
+ @line = $'
473
+
474
+
475
+
476
+ when /\A""/, /\A''/, /\A[0-9]+/, /\A\{\s*\}/, /\A\[\s*\]/, /\Anil/
477
+ @line = $'
478
+ yield token(:LIT, $&)
479
+
480
+
481
+ when /\A\A[a-z][a-z_]*/
482
+ @line = $'
483
+ yield token(:ID, $&)
484
+
485
+
486
+ when /\A\A(.)/
487
+ @line = $'
488
+ yield token($&, $&)
489
+
490
+
491
+ else
492
+ raise RuntimeError, "must not happen #{@line}"
493
+ end
494
+ end
495
+ end while @original_line = @line = file.gets
496
+ yield nil, nil
497
+ end
498
+ module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 121
499
+ def do_default
500
+ master.nodes_code << %{
501
+ class Node_#{g_parser.lhs_name} < Node
502
+ def initialize
503
+ super()
504
+ end
505
+ end
506
+ } #code
507
+ end
508
+
509
+ DEPAGER_EXPANDED_CODE
510
+
511
+ end
512
+ end
513
+
514
+
515
+ class Depager::CSTBuilderExtension::Slave_post_lhs::Action < Depager::LALR::Action #:nodoc:all
516
+ include Depager::Utils::ExtensionSlaveDecoratorMethods
517
+
518
+ on_reduce = [
519
+ nil,
520
+ :_act_1,
521
+ :_act_2,
522
+ :_act_3,
523
+ :_act_4,
524
+ :_act_5,
525
+
526
+ ]
527
+ Tables = [ on_reduce ]
528
+
529
+
530
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 143
531
+ def _act_1 val
532
+ _, _pair, _, = *val
533
+
534
+ args = []; code = ''
535
+ _pair.each do |id, lit|
536
+ args << id
537
+ code << "#{id} = #{lit}; " if lit
538
+ end
539
+ attrc = args.map{|i| ":#{i}"}.join(', ')
540
+ master.nodes_code << %{
541
+ class Node_#{g_parser.lhs_name} < Node
542
+ attr_accessor #{attrc}
543
+ def initialize
544
+ super
545
+ #{code}
546
+ end
547
+ end
548
+ } #code
549
+
550
+ end
551
+ DEPAGER_EXPANDED_CODE
552
+
553
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 162
554
+ def _act_2 val
555
+ _expr, = *val
556
+ [ _expr ]
557
+
558
+ end
559
+ DEPAGER_EXPANDED_CODE
560
+
561
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 163
562
+ def _act_3 val
563
+ _pair, _, _expr, = *val
564
+ _pair << _expr
565
+
566
+ end
567
+ DEPAGER_EXPANDED_CODE
568
+
569
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 166
570
+ def _act_4 val
571
+ _ID, = *val
572
+ [ _ID.value, nil]
573
+
574
+ end
575
+ DEPAGER_EXPANDED_CODE
576
+
577
+ module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/cst.dr', 167
578
+ def _act_5 val
579
+ _ID, _, _LIT, = *val
580
+ [ _ID.value, _LIT.value ]
581
+
582
+ end
583
+ DEPAGER_EXPANDED_CODE
584
+
585
+
586
+ end
587
+