depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,200 +1,202 @@
|
|
1
|
-
%defext StatefulLexerExtension
|
2
|
-
%extend Lexer ('plugins/lex.rb')
|
3
|
-
%extend
|
4
|
-
%decorate @
|
5
|
-
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
6
|
-
%
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@ins = []
|
11
|
-
@
|
12
|
-
@on_reduce = []
|
13
|
-
@addition = []
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
g_parser.
|
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
|
-
%LEX{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
1
|
+
%defext Depager::StatefulLexerExtension
|
2
|
+
%extend Depager::Depager::Lexer ('plugins/lex.rb')
|
3
|
+
%extend Depager::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 :ins, :code, :optval
|
9
|
+
def init_extension
|
10
|
+
@ins = []
|
11
|
+
@action_code = ''
|
12
|
+
@on_reduce = []
|
13
|
+
@addition = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def term_extension
|
17
|
+
@action_code << %{
|
18
|
+
def after_error
|
19
|
+
warn "StatefulLex: lex_state==\#{@basis.lex_state}" if Depager.debug_mode?
|
20
|
+
end
|
21
|
+
}
|
22
|
+
g_parser.outer_code <<
|
23
|
+
generate_action_decorator_code(@on_reduce, @action_code)
|
24
|
+
end
|
25
|
+
|
26
|
+
def post_rhs
|
27
|
+
j = 0
|
28
|
+
rhs = g_parser.rhs
|
29
|
+
@ins.each do |i, option_list, debug|
|
30
|
+
state_name = "#{g_parser.lhs_name}_#{g_parser.nrhs}_#{i}"
|
31
|
+
m_name = "_lex_#{state_name}"
|
32
|
+
if i != rhs.size
|
33
|
+
nt_name = "__#{state_name}__"
|
34
|
+
isym = g_parser.add_nonterm(nt_name)
|
35
|
+
g_parser.insert_sym_to_rhs(i + j, isym, nt_name)
|
36
|
+
@addition << [ isym, m_name ]
|
37
|
+
j += 1
|
38
|
+
else
|
39
|
+
@on_reduce[g_parser.rules.size-1] = ':'+m_name
|
40
|
+
end
|
41
|
+
|
42
|
+
codes = option_list.map do |k, m|
|
43
|
+
case k
|
44
|
+
when :GOTO
|
45
|
+
"@basis.lex_state = #{m}" <<
|
46
|
+
(debug ? ";warn 'MODE:->#{m}'" : '')
|
47
|
+
when :ADD
|
48
|
+
"@basis.lex_context[#{m}] = true" <<
|
49
|
+
(debug ? ";warn 'CONTEXT:+#{m}/\#{@context.inspect}'" : '')
|
50
|
+
when :SUB
|
51
|
+
"@basis.lex_context.delete #{m}" <<
|
52
|
+
(debug ? ";warn 'CONTEXT:-#{m}'/\#{@context.inspect}" : '')
|
53
|
+
else
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@action_code << %{
|
57
|
+
def #{m_name} val
|
58
|
+
#{codes.join("\n ")}
|
59
|
+
end
|
60
|
+
}
|
61
|
+
end
|
62
|
+
@ins.clear
|
63
|
+
end
|
64
|
+
|
65
|
+
def post_rhs_list
|
66
|
+
@addition.each do |isym, m_name|
|
67
|
+
g_parser.add_rule isym, []
|
68
|
+
@on_reduce[g_parser.rules.size-1] = ':'+m_name
|
69
|
+
end
|
70
|
+
@addition.clear
|
71
|
+
end
|
72
|
+
%}
|
73
|
+
######################################################################
|
74
|
+
# Define Tokens
|
75
|
+
######################################################################
|
76
|
+
%hook pre_rule_list /%LEX\{\s*\Z/ skip
|
77
|
+
%banner '%LEX{ ... }'
|
78
|
+
%%
|
79
|
+
%LEX{
|
80
|
+
/\s+/, /#.*\Z/ { }
|
81
|
+
/[A-Z]+/ { yield token(:ID, $&) }
|
82
|
+
/\%\}\s*\Z/ { yield nil,nil }
|
83
|
+
/\/(([^\/\\]+|\\.)*)\// { yield token(:LEX, "/\\A#{$1}/") }
|
84
|
+
/'([^'\\]+|\\.)*'/,
|
85
|
+
/"([^"\\]+|\\.)*"/
|
86
|
+
{
|
87
|
+
yield token(:LEX, "/\\A#{Regexp.escape($1).gsub('/', '\/')}/")
|
88
|
+
}
|
89
|
+
'{' !
|
90
|
+
{
|
91
|
+
lineno = file.lineno
|
92
|
+
yield token(:ACTION, parse_block, lineno)
|
93
|
+
}
|
94
|
+
/./ { yield token($&, $&) }
|
95
|
+
%}
|
96
|
+
#begin-rule
|
97
|
+
start:
|
98
|
+
mode_list
|
99
|
+
{
|
100
|
+
ll = ''
|
101
|
+
_mode_list.each do |m, s, l|
|
102
|
+
else_code = if s
|
103
|
+
"lex_#{s}(&block)"
|
104
|
+
else
|
105
|
+
'raise RuntimeError, "must not happen #{@line}"'
|
106
|
+
end
|
107
|
+
ll << %{
|
108
|
+
def lex_#{m}(&block)
|
109
|
+
case @line
|
110
|
+
#{l}
|
111
|
+
else
|
112
|
+
#{else_code}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
}; #code
|
116
|
+
end
|
117
|
+
g_parser.inner_code << ll << %{
|
118
|
+
attr_accessor :lex_state, :lex_context
|
119
|
+
def lex(&block)
|
120
|
+
@lex_state ||= :START
|
121
|
+
@lex_context ||= {}
|
122
|
+
begin
|
123
|
+
until @line.empty?
|
124
|
+
self.send "lex_\#{@lex_state}", &block
|
125
|
+
end
|
126
|
+
end while @original_line = @line = file.gets
|
127
|
+
yield nil, nil
|
128
|
+
end
|
129
|
+
}; #code
|
130
|
+
}
|
131
|
+
;
|
132
|
+
mode_list:
|
133
|
+
{ [ ] }
|
134
|
+
| mode_list mode lexactlist { _mode_list << [_mode[0], _mode[1], _lexactlist] }
|
135
|
+
;
|
136
|
+
mode:
|
137
|
+
'<' ID opt_super '>' { [ _ID.value, _opt_super ] }
|
138
|
+
;
|
139
|
+
opt_super:
|
140
|
+
{ nil }
|
141
|
+
| ':' ID { _ID.value }
|
142
|
+
;
|
143
|
+
lexactlist:
|
144
|
+
lexact { _lexact }
|
145
|
+
| lexactlist lexact { _lexactlist << _lexact }
|
146
|
+
;
|
147
|
+
lexact:
|
148
|
+
lexlist opt_noskip ACTION
|
149
|
+
{
|
150
|
+
%{
|
151
|
+
when #{_lexlist.join(', ')}
|
152
|
+
#{ _opt_noskip ? '#' : "@line = $'" }
|
153
|
+
#{ _ACTION.value }
|
154
|
+
}; #code
|
155
|
+
}
|
156
|
+
;
|
157
|
+
opt_noskip:
|
158
|
+
{ false }
|
159
|
+
| '!' { true }
|
160
|
+
;
|
161
|
+
lexlist:
|
162
|
+
LEX { [ _LEX.value ] }
|
163
|
+
| lexlist ',' LEX { _lexlist.push _LEX.value }
|
164
|
+
;
|
165
|
+
#end-rule
|
166
|
+
%%
|
167
|
+
######################################################################
|
168
|
+
# Change State
|
169
|
+
######################################################################
|
170
|
+
%hook pre_rhs post_symbol /\[/
|
171
|
+
%banner '[> ...]'
|
172
|
+
%%
|
173
|
+
%LEX{
|
174
|
+
/\s+/ { }
|
175
|
+
/:[a-zA-Z_]+\??/ { yield token(:SYMBOL, $&) }
|
176
|
+
/\]/ { yield token($&, $&); @line = $'; yield nil, nil }
|
177
|
+
/./ { yield token($&, $&) }
|
178
|
+
%}
|
179
|
+
|
180
|
+
#begin-rule
|
181
|
+
start:
|
182
|
+
'[' option_list ']'
|
183
|
+
{
|
184
|
+
master.ins.push [g_parser.rhs.size, _option_list, false]
|
185
|
+
}
|
186
|
+
| '[' option_list '?' ']'
|
187
|
+
{
|
188
|
+
master.ins.push [g_parser.rhs.size, _option_list, true]
|
189
|
+
}
|
190
|
+
|
191
|
+
;
|
192
|
+
option_list:
|
193
|
+
option { [_option] }
|
194
|
+
| option_list option { _option_list << _option }
|
195
|
+
;
|
196
|
+
option:
|
197
|
+
'>' SYMBOL { [:GOTO, _SYMBOL.value] }
|
198
|
+
| '+' SYMBOL { [:ADD, _SYMBOL.value] }
|
199
|
+
| '-' SYMBOL { [:SUB, _SYMBOL.value] }
|
200
|
+
;
|
201
|
+
#end-rule
|
202
|
+
%%
|
@@ -1,817 +1,780 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
###
|
4
|
-
###
|
5
|
-
|
6
|
-
require 'depager/parser.rb'
|
7
|
-
|
8
|
-
|
9
|
-
module
|
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
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
end
|
461
|
-
|
462
|
-
|
463
|
-
module_eval <<-'
|
464
|
-
def
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
end
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
.,.,122745803335394.,.,
|
782
|
-
|
783
|
-
module_eval <<-'.,.,122745803345722.,.,', 'slex.dr', 190
|
784
|
-
def _act_3 val
|
785
|
-
_option_list, _option, = *val
|
786
|
-
_option_list << _option
|
787
|
-
|
788
|
-
end
|
789
|
-
.,.,122745803345722.,.,
|
790
|
-
|
791
|
-
module_eval <<-'.,.,122745803311899.,.,', 'slex.dr', 193
|
792
|
-
def _act_4 val
|
793
|
-
_, _SYMBOL, = *val
|
794
|
-
[:GOTO, _SYMBOL.value]
|
795
|
-
|
796
|
-
end
|
797
|
-
.,.,122745803311899.,.,
|
798
|
-
|
799
|
-
module_eval <<-'.,.,122745803346690.,.,', 'slex.dr', 194
|
800
|
-
def _act_5 val
|
801
|
-
_, _SYMBOL, = *val
|
802
|
-
[:ADD, _SYMBOL.value]
|
803
|
-
|
804
|
-
end
|
805
|
-
.,.,122745803346690.,.,
|
806
|
-
|
807
|
-
module_eval <<-'.,.,122745803330412.,.,', 'slex.dr', 195
|
808
|
-
def _act_6 val
|
809
|
-
_, _SYMBOL, = *val
|
810
|
-
[:SUB, _SYMBOL.value]
|
811
|
-
|
812
|
-
end
|
813
|
-
.,.,122745803330412.,.,
|
814
|
-
|
815
|
-
end
|
816
|
-
|
817
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### Depager::StatefulLexerExtension - Depager Extension (master)
|
5
|
+
###
|
6
|
+
require 'depager/parser.rb'
|
7
|
+
|
8
|
+
|
9
|
+
module Depager ; end
|
10
|
+
|
11
|
+
class Depager::StatefulLexerExtension < 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::StatefulLexerExtension::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::StatefulLexerExtension::Slave_pre_rhs__post_symbol::Parser.new(g_parser, self)
|
24
|
+
g_parser.hooks[:pre_rhs].push [@slaves[1], :do_parse]
|
25
|
+
# use @slaves[1](Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol::Parser)
|
26
|
+
g_parser.hooks[:post_symbol].push [@slaves[1], :do_parse]
|
27
|
+
end
|
28
|
+
|
29
|
+
module_eval <<'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 8
|
30
|
+
attr_accessor :ins, :code, :optval
|
31
|
+
def init_extension
|
32
|
+
@ins = []
|
33
|
+
@action_code = ''
|
34
|
+
@on_reduce = []
|
35
|
+
@addition = []
|
36
|
+
end
|
37
|
+
|
38
|
+
def term_extension
|
39
|
+
@action_code << %{
|
40
|
+
def after_error
|
41
|
+
warn "StatefulLex: lex_state==\#{@basis.lex_state}" if Depager.debug_mode?
|
42
|
+
end
|
43
|
+
}
|
44
|
+
g_parser.outer_code <<
|
45
|
+
generate_action_decorator_code(@on_reduce, @action_code)
|
46
|
+
end
|
47
|
+
|
48
|
+
def post_rhs
|
49
|
+
j = 0
|
50
|
+
rhs = g_parser.rhs
|
51
|
+
@ins.each do |i, option_list, debug|
|
52
|
+
state_name = "#{g_parser.lhs_name}_#{g_parser.nrhs}_#{i}"
|
53
|
+
m_name = "_lex_#{state_name}"
|
54
|
+
if i != rhs.size
|
55
|
+
nt_name = "__#{state_name}__"
|
56
|
+
isym = g_parser.add_nonterm(nt_name)
|
57
|
+
g_parser.insert_sym_to_rhs(i + j, isym, nt_name)
|
58
|
+
@addition << [ isym, m_name ]
|
59
|
+
j += 1
|
60
|
+
else
|
61
|
+
@on_reduce[g_parser.rules.size-1] = ':'+m_name
|
62
|
+
end
|
63
|
+
|
64
|
+
codes = option_list.map do |k, m|
|
65
|
+
case k
|
66
|
+
when :GOTO
|
67
|
+
"@basis.lex_state = #{m}" <<
|
68
|
+
(debug ? ";warn 'MODE:->#{m}'" : '')
|
69
|
+
when :ADD
|
70
|
+
"@basis.lex_context[#{m}] = true" <<
|
71
|
+
(debug ? ";warn 'CONTEXT:+#{m}/\#{@context.inspect}'" : '')
|
72
|
+
when :SUB
|
73
|
+
"@basis.lex_context.delete #{m}" <<
|
74
|
+
(debug ? ";warn 'CONTEXT:-#{m}'/\#{@context.inspect}" : '')
|
75
|
+
else
|
76
|
+
end
|
77
|
+
end
|
78
|
+
@action_code << %{
|
79
|
+
def #{m_name} val
|
80
|
+
#{codes.join("\n ")}
|
81
|
+
end
|
82
|
+
}
|
83
|
+
end
|
84
|
+
@ins.clear
|
85
|
+
end
|
86
|
+
|
87
|
+
def post_rhs_list
|
88
|
+
@addition.each do |isym, m_name|
|
89
|
+
g_parser.add_rule isym, []
|
90
|
+
@on_reduce[g_parser.rules.size-1] = ':'+m_name
|
91
|
+
end
|
92
|
+
@addition.clear
|
93
|
+
end
|
94
|
+
|
95
|
+
DEPAGER_EXPANDED_CODE
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
###
|
100
|
+
### Depager::StatefulLexerExtension::Slave_pre_rule_list - Part of Depager Extension (slave)
|
101
|
+
###
|
102
|
+
|
103
|
+
module Depager::StatefulLexerExtension::Slave_pre_rule_list #:nodoc:all
|
104
|
+
class Parser < Depager::LALR::Basis #:nodoc:all
|
105
|
+
include Depager::Utils::ExtensionSlaveMethods
|
106
|
+
|
107
|
+
|
108
|
+
### Reduce Table
|
109
|
+
reduce_table = [
|
110
|
+
[ -1, 1 ],
|
111
|
+
[ 0, 1 ],
|
112
|
+
[ 1, 0 ],
|
113
|
+
[ 1, 3 ],
|
114
|
+
[ 2, 4 ],
|
115
|
+
[ 4, 0 ],
|
116
|
+
[ 4, 2 ],
|
117
|
+
[ 3, 1 ],
|
118
|
+
[ 3, 2 ],
|
119
|
+
[ 5, 3 ],
|
120
|
+
[ 7, 0 ],
|
121
|
+
[ 7, 1 ],
|
122
|
+
[ 6, 1 ],
|
123
|
+
[ 6, 3 ],
|
124
|
+
]
|
125
|
+
### Term to Int
|
126
|
+
term_to_int = {
|
127
|
+
nil => 0,
|
128
|
+
false => 1,
|
129
|
+
"<" => 2,
|
130
|
+
:ID => 3,
|
131
|
+
">" => 4,
|
132
|
+
":" => 5,
|
133
|
+
:ACTION => 6,
|
134
|
+
"!" => 7,
|
135
|
+
:LEX => 8,
|
136
|
+
"," => 9,
|
137
|
+
}
|
138
|
+
### Int to Term
|
139
|
+
int_to_term = [
|
140
|
+
nil,
|
141
|
+
false,
|
142
|
+
"<",
|
143
|
+
:ID,
|
144
|
+
">",
|
145
|
+
":",
|
146
|
+
:ACTION,
|
147
|
+
"!",
|
148
|
+
:LEX,
|
149
|
+
",",
|
150
|
+
]
|
151
|
+
### Action Table
|
152
|
+
action_table = [
|
153
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
154
|
+
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
155
|
+
[ nil, nil, 4, nil, nil, nil, nil, nil, nil, nil, ],
|
156
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 8, nil, ],
|
157
|
+
[ nil, nil, nil, 9, nil, nil, nil, nil, nil, nil, ],
|
158
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 8, nil, ],
|
159
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
160
|
+
[ nil, nil, nil, nil, nil, nil, nil, 12, nil, 13, ],
|
161
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
162
|
+
[ nil, nil, nil, nil, nil, 15, nil, nil, nil, nil, ],
|
163
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
164
|
+
[ nil, nil, nil, nil, nil, nil, 16, nil, nil, nil, ],
|
165
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
166
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, 17, nil, ],
|
167
|
+
[ nil, nil, nil, nil, 18, nil, nil, nil, nil, nil, ],
|
168
|
+
[ nil, nil, nil, 19, nil, nil, nil, nil, nil, nil, ],
|
169
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
170
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
171
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
172
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
173
|
+
]
|
174
|
+
### Default Reduce Table
|
175
|
+
defred_table = [
|
176
|
+
-2,
|
177
|
+
nil,
|
178
|
+
-1,
|
179
|
+
nil,
|
180
|
+
nil,
|
181
|
+
-3,
|
182
|
+
-7,
|
183
|
+
-10,
|
184
|
+
-12,
|
185
|
+
-5,
|
186
|
+
-8,
|
187
|
+
nil,
|
188
|
+
-11,
|
189
|
+
nil,
|
190
|
+
nil,
|
191
|
+
nil,
|
192
|
+
-9,
|
193
|
+
-13,
|
194
|
+
-4,
|
195
|
+
-6,
|
196
|
+
]
|
197
|
+
defred_after_shift_table = [
|
198
|
+
-2,
|
199
|
+
nil,
|
200
|
+
nil,
|
201
|
+
nil,
|
202
|
+
nil,
|
203
|
+
nil,
|
204
|
+
-7,
|
205
|
+
nil,
|
206
|
+
-12,
|
207
|
+
nil,
|
208
|
+
-8,
|
209
|
+
nil,
|
210
|
+
-11,
|
211
|
+
nil,
|
212
|
+
nil,
|
213
|
+
nil,
|
214
|
+
-9,
|
215
|
+
-13,
|
216
|
+
-4,
|
217
|
+
-6,
|
218
|
+
]
|
219
|
+
### Nonterm to Int
|
220
|
+
nonterm_to_int = {
|
221
|
+
:start => 0,
|
222
|
+
:mode_list => 1,
|
223
|
+
:mode => 2,
|
224
|
+
:lexactlist => 3,
|
225
|
+
:opt_super => 4,
|
226
|
+
:lexact => 5,
|
227
|
+
:lexlist => 6,
|
228
|
+
:opt_noskip => 7,
|
229
|
+
}
|
230
|
+
### Int to Nonterm
|
231
|
+
int_to_nonterm = [
|
232
|
+
:start,
|
233
|
+
:mode_list,
|
234
|
+
:mode,
|
235
|
+
:lexactlist,
|
236
|
+
:opt_super,
|
237
|
+
:lexact,
|
238
|
+
:lexlist,
|
239
|
+
:opt_noskip,
|
240
|
+
]
|
241
|
+
### Goto Table
|
242
|
+
goto_table = [
|
243
|
+
[ 1, 2, nil, nil, nil, nil, nil, nil, ],
|
244
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
245
|
+
[ nil, nil, 3, nil, nil, nil, nil, nil, ],
|
246
|
+
[ nil, nil, nil, 5, nil, 6, 7, nil, ],
|
247
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
248
|
+
[ nil, nil, nil, nil, nil, 10, 7, nil, ],
|
249
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
250
|
+
[ nil, nil, nil, nil, nil, nil, nil, 11, ],
|
251
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
252
|
+
[ nil, nil, nil, nil, 14, nil, nil, nil, ],
|
253
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
254
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
255
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
256
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
257
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
258
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
259
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
260
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
261
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
262
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, ],
|
263
|
+
]
|
264
|
+
|
265
|
+
Tables = [ reduce_table, action_table,
|
266
|
+
defred_table, defred_after_shift_table, goto_table,
|
267
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
268
|
+
|
269
|
+
def initialize g_parser, master
|
270
|
+
super()
|
271
|
+
@g_parser = g_parser
|
272
|
+
@d_parser = g_parser.d_parser
|
273
|
+
@master = master
|
274
|
+
@decorated = Action.new(self)
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
def do_parse?
|
279
|
+
if @line.match(/^\s*%LEX\{\s*\Z/)
|
280
|
+
@line = $'
|
281
|
+
true
|
282
|
+
else
|
283
|
+
false
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
def banner
|
289
|
+
"%LEX{ ... } / Depager::StatefulLexerExtension"
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
def lex
|
294
|
+
begin
|
295
|
+
until @line.empty?
|
296
|
+
case @line
|
297
|
+
|
298
|
+
when /\A\s+/, /\A#.*\Z/
|
299
|
+
@line = $'
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
when /\A[A-Z]+/
|
304
|
+
@line = $'
|
305
|
+
yield token(:ID, $&)
|
306
|
+
|
307
|
+
|
308
|
+
when /\A\%\}\s*\Z/
|
309
|
+
@line = $'
|
310
|
+
yield nil,nil
|
311
|
+
|
312
|
+
|
313
|
+
when /\A\/(([^\/\\]+|\\.)*)\//
|
314
|
+
@line = $'
|
315
|
+
yield token(:LEX, "/\\A#{$1}/")
|
316
|
+
|
317
|
+
|
318
|
+
when /\A'([^'\\]+|\\.)*'/, /\A"([^"\\]+|\\.)*"/
|
319
|
+
@line = $'
|
320
|
+
|
321
|
+
yield token(:LEX, "/\\A#{Regexp.escape($1).gsub('/', '\/')}/")
|
322
|
+
|
323
|
+
|
324
|
+
when /\A\{/
|
325
|
+
#
|
326
|
+
|
327
|
+
lineno = file.lineno
|
328
|
+
yield token(:ACTION, parse_block, lineno)
|
329
|
+
|
330
|
+
|
331
|
+
when /\A./
|
332
|
+
@line = $'
|
333
|
+
yield token($&, $&)
|
334
|
+
|
335
|
+
|
336
|
+
else
|
337
|
+
raise RuntimeError, "must not happen #{@line}"
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end while @original_line = @line = file.gets
|
341
|
+
yield nil, nil
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
class Depager::StatefulLexerExtension::Slave_pre_rule_list::Action < Depager::LALR::Action #:nodoc:all
|
349
|
+
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
350
|
+
|
351
|
+
on_reduce = [
|
352
|
+
nil,
|
353
|
+
:_act_1,
|
354
|
+
:_act_2,
|
355
|
+
:_act_3,
|
356
|
+
:_act_4,
|
357
|
+
:_act_5,
|
358
|
+
:_act_6,
|
359
|
+
:_act_7,
|
360
|
+
:_act_8,
|
361
|
+
:_act_9,
|
362
|
+
:_act_10,
|
363
|
+
:_act_11,
|
364
|
+
:_act_12,
|
365
|
+
:_act_13,
|
366
|
+
|
367
|
+
]
|
368
|
+
Tables = [ on_reduce ]
|
369
|
+
|
370
|
+
|
371
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 97
|
372
|
+
def _act_1 val
|
373
|
+
_mode_list, = *val
|
374
|
+
|
375
|
+
ll = ''
|
376
|
+
_mode_list.each do |m, s, l|
|
377
|
+
else_code = if s
|
378
|
+
"lex_#{s}(&block)"
|
379
|
+
else
|
380
|
+
'raise RuntimeError, "must not happen #{@line}"'
|
381
|
+
end
|
382
|
+
ll << %{
|
383
|
+
def lex_#{m}(&block)
|
384
|
+
case @line
|
385
|
+
#{l}
|
386
|
+
else
|
387
|
+
#{else_code}
|
388
|
+
end
|
389
|
+
end
|
390
|
+
}; #code
|
391
|
+
end
|
392
|
+
g_parser.inner_code << ll << %{
|
393
|
+
attr_accessor :lex_state, :lex_context
|
394
|
+
def lex(&block)
|
395
|
+
@lex_state ||= :START
|
396
|
+
@lex_context ||= {}
|
397
|
+
begin
|
398
|
+
until @line.empty?
|
399
|
+
self.send "lex_\#{@lex_state}", &block
|
400
|
+
end
|
401
|
+
end while @original_line = @line = file.gets
|
402
|
+
yield nil, nil
|
403
|
+
end
|
404
|
+
}; #code
|
405
|
+
|
406
|
+
end
|
407
|
+
DEPAGER_EXPANDED_CODE
|
408
|
+
|
409
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 131
|
410
|
+
def _act_2 val
|
411
|
+
[ ]
|
412
|
+
|
413
|
+
end
|
414
|
+
DEPAGER_EXPANDED_CODE
|
415
|
+
|
416
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 132
|
417
|
+
def _act_3 val
|
418
|
+
_mode_list, _mode, _lexactlist, = *val
|
419
|
+
_mode_list << [_mode[0], _mode[1], _lexactlist]
|
420
|
+
|
421
|
+
end
|
422
|
+
DEPAGER_EXPANDED_CODE
|
423
|
+
|
424
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 135
|
425
|
+
def _act_4 val
|
426
|
+
_, _ID, _opt_super, _, = *val
|
427
|
+
[ _ID.value, _opt_super ]
|
428
|
+
|
429
|
+
end
|
430
|
+
DEPAGER_EXPANDED_CODE
|
431
|
+
|
432
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 138
|
433
|
+
def _act_5 val
|
434
|
+
nil
|
435
|
+
|
436
|
+
end
|
437
|
+
DEPAGER_EXPANDED_CODE
|
438
|
+
|
439
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 139
|
440
|
+
def _act_6 val
|
441
|
+
_, _ID, = *val
|
442
|
+
_ID.value
|
443
|
+
|
444
|
+
end
|
445
|
+
DEPAGER_EXPANDED_CODE
|
446
|
+
|
447
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 142
|
448
|
+
def _act_7 val
|
449
|
+
_lexact, = *val
|
450
|
+
_lexact
|
451
|
+
|
452
|
+
end
|
453
|
+
DEPAGER_EXPANDED_CODE
|
454
|
+
|
455
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 143
|
456
|
+
def _act_8 val
|
457
|
+
_lexactlist, _lexact, = *val
|
458
|
+
_lexactlist << _lexact
|
459
|
+
|
460
|
+
end
|
461
|
+
DEPAGER_EXPANDED_CODE
|
462
|
+
|
463
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 147
|
464
|
+
def _act_9 val
|
465
|
+
_lexlist, _opt_noskip, _ACTION, = *val
|
466
|
+
|
467
|
+
%{
|
468
|
+
when #{_lexlist.join(', ')}
|
469
|
+
#{ _opt_noskip ? '#' : "@line = $'" }
|
470
|
+
#{ _ACTION.value }
|
471
|
+
}; #code
|
472
|
+
|
473
|
+
end
|
474
|
+
DEPAGER_EXPANDED_CODE
|
475
|
+
|
476
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 156
|
477
|
+
def _act_10 val
|
478
|
+
false
|
479
|
+
|
480
|
+
end
|
481
|
+
DEPAGER_EXPANDED_CODE
|
482
|
+
|
483
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 157
|
484
|
+
def _act_11 val
|
485
|
+
_, = *val
|
486
|
+
true
|
487
|
+
|
488
|
+
end
|
489
|
+
DEPAGER_EXPANDED_CODE
|
490
|
+
|
491
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 160
|
492
|
+
def _act_12 val
|
493
|
+
_LEX, = *val
|
494
|
+
[ _LEX.value ]
|
495
|
+
|
496
|
+
end
|
497
|
+
DEPAGER_EXPANDED_CODE
|
498
|
+
|
499
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 161
|
500
|
+
def _act_13 val
|
501
|
+
_lexlist, _, _LEX, = *val
|
502
|
+
_lexlist.push _LEX.value
|
503
|
+
|
504
|
+
end
|
505
|
+
DEPAGER_EXPANDED_CODE
|
506
|
+
|
507
|
+
|
508
|
+
end
|
509
|
+
|
510
|
+
###
|
511
|
+
### Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol - Part of Depager Extension (slave)
|
512
|
+
###
|
513
|
+
|
514
|
+
module Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol #:nodoc:all
|
515
|
+
class Parser < Depager::LALR::Basis #:nodoc:all
|
516
|
+
include Depager::Utils::ExtensionSlaveMethods
|
517
|
+
|
518
|
+
|
519
|
+
### Reduce Table
|
520
|
+
reduce_table = [
|
521
|
+
[ -1, 1 ],
|
522
|
+
[ 0, 3 ],
|
523
|
+
[ 0, 4 ],
|
524
|
+
[ 1, 1 ],
|
525
|
+
[ 1, 2 ],
|
526
|
+
[ 2, 2 ],
|
527
|
+
[ 2, 2 ],
|
528
|
+
[ 2, 2 ],
|
529
|
+
]
|
530
|
+
### Term to Int
|
531
|
+
term_to_int = {
|
532
|
+
nil => 0,
|
533
|
+
false => 1,
|
534
|
+
"[" => 2,
|
535
|
+
"]" => 3,
|
536
|
+
"?" => 4,
|
537
|
+
">" => 5,
|
538
|
+
:SYMBOL => 6,
|
539
|
+
"+" => 7,
|
540
|
+
"-" => 8,
|
541
|
+
}
|
542
|
+
### Int to Term
|
543
|
+
int_to_term = [
|
544
|
+
nil,
|
545
|
+
false,
|
546
|
+
"[",
|
547
|
+
"]",
|
548
|
+
"?",
|
549
|
+
">",
|
550
|
+
:SYMBOL,
|
551
|
+
"+",
|
552
|
+
"-",
|
553
|
+
]
|
554
|
+
### Action Table
|
555
|
+
action_table = [
|
556
|
+
[ nil, nil, 2, nil, nil, nil, nil, nil, nil, ],
|
557
|
+
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
558
|
+
[ nil, nil, nil, nil, nil, 5, nil, 6, 7, ],
|
559
|
+
[ nil, nil, nil, 8, 10, 5, nil, 6, 7, ],
|
560
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
561
|
+
[ nil, nil, nil, nil, nil, nil, 11, nil, nil, ],
|
562
|
+
[ nil, nil, nil, nil, nil, nil, 12, nil, nil, ],
|
563
|
+
[ nil, nil, nil, nil, nil, nil, 13, nil, nil, ],
|
564
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
565
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
566
|
+
[ nil, nil, nil, 14, nil, nil, nil, nil, nil, ],
|
567
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
568
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
569
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
570
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
571
|
+
]
|
572
|
+
### Default Reduce Table
|
573
|
+
defred_table = [
|
574
|
+
nil,
|
575
|
+
nil,
|
576
|
+
nil,
|
577
|
+
nil,
|
578
|
+
-3,
|
579
|
+
nil,
|
580
|
+
nil,
|
581
|
+
nil,
|
582
|
+
-1,
|
583
|
+
-4,
|
584
|
+
nil,
|
585
|
+
-5,
|
586
|
+
-6,
|
587
|
+
-7,
|
588
|
+
-2,
|
589
|
+
]
|
590
|
+
defred_after_shift_table = [
|
591
|
+
nil,
|
592
|
+
nil,
|
593
|
+
nil,
|
594
|
+
nil,
|
595
|
+
-3,
|
596
|
+
nil,
|
597
|
+
nil,
|
598
|
+
nil,
|
599
|
+
-1,
|
600
|
+
-4,
|
601
|
+
nil,
|
602
|
+
-5,
|
603
|
+
-6,
|
604
|
+
-7,
|
605
|
+
-2,
|
606
|
+
]
|
607
|
+
### Nonterm to Int
|
608
|
+
nonterm_to_int = {
|
609
|
+
:start => 0,
|
610
|
+
:option_list => 1,
|
611
|
+
:option => 2,
|
612
|
+
}
|
613
|
+
### Int to Nonterm
|
614
|
+
int_to_nonterm = [
|
615
|
+
:start,
|
616
|
+
:option_list,
|
617
|
+
:option,
|
618
|
+
]
|
619
|
+
### Goto Table
|
620
|
+
goto_table = [
|
621
|
+
[ 1, nil, nil, ],
|
622
|
+
[ nil, nil, nil, ],
|
623
|
+
[ nil, 3, 4, ],
|
624
|
+
[ nil, nil, 9, ],
|
625
|
+
[ nil, nil, nil, ],
|
626
|
+
[ nil, nil, nil, ],
|
627
|
+
[ nil, nil, nil, ],
|
628
|
+
[ nil, nil, nil, ],
|
629
|
+
[ nil, nil, nil, ],
|
630
|
+
[ nil, nil, nil, ],
|
631
|
+
[ nil, nil, nil, ],
|
632
|
+
[ nil, nil, nil, ],
|
633
|
+
[ nil, nil, nil, ],
|
634
|
+
[ nil, nil, nil, ],
|
635
|
+
[ nil, nil, nil, ],
|
636
|
+
]
|
637
|
+
|
638
|
+
Tables = [ reduce_table, action_table,
|
639
|
+
defred_table, defred_after_shift_table, goto_table,
|
640
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
641
|
+
|
642
|
+
def initialize g_parser, master
|
643
|
+
super()
|
644
|
+
@g_parser = g_parser
|
645
|
+
@d_parser = g_parser.d_parser
|
646
|
+
@master = master
|
647
|
+
@decorated = Action.new(self)
|
648
|
+
end
|
649
|
+
|
650
|
+
|
651
|
+
def do_parse?
|
652
|
+
if @line.match(/^\s*\[/)
|
653
|
+
|
654
|
+
true
|
655
|
+
else
|
656
|
+
false
|
657
|
+
end
|
658
|
+
end
|
659
|
+
|
660
|
+
|
661
|
+
def banner
|
662
|
+
"[> ...] / Depager::StatefulLexerExtension"
|
663
|
+
end
|
664
|
+
|
665
|
+
|
666
|
+
def lex
|
667
|
+
begin
|
668
|
+
until @line.empty?
|
669
|
+
case @line
|
670
|
+
|
671
|
+
when /\A\s+/
|
672
|
+
@line = $'
|
673
|
+
|
674
|
+
|
675
|
+
|
676
|
+
when /\A:[a-zA-Z_]+\??/
|
677
|
+
@line = $'
|
678
|
+
yield token(:SYMBOL, $&)
|
679
|
+
|
680
|
+
|
681
|
+
when /\A\]/
|
682
|
+
@line = $'
|
683
|
+
yield token($&, $&); @line = $'; yield nil, nil
|
684
|
+
|
685
|
+
|
686
|
+
when /\A./
|
687
|
+
@line = $'
|
688
|
+
yield token($&, $&)
|
689
|
+
|
690
|
+
|
691
|
+
else
|
692
|
+
raise RuntimeError, "must not happen #{@line}"
|
693
|
+
end
|
694
|
+
end
|
695
|
+
end while @original_line = @line = file.gets
|
696
|
+
yield nil, nil
|
697
|
+
end
|
698
|
+
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
|
703
|
+
class Depager::StatefulLexerExtension::Slave_pre_rhs__post_symbol::Action < Depager::LALR::Action #:nodoc:all
|
704
|
+
include Depager::Utils::ExtensionSlaveDecoratorMethods
|
705
|
+
|
706
|
+
on_reduce = [
|
707
|
+
nil,
|
708
|
+
:_act_1,
|
709
|
+
:_act_2,
|
710
|
+
:_act_3,
|
711
|
+
:_act_4,
|
712
|
+
:_act_5,
|
713
|
+
:_act_6,
|
714
|
+
:_act_7,
|
715
|
+
|
716
|
+
]
|
717
|
+
Tables = [ on_reduce ]
|
718
|
+
|
719
|
+
|
720
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 181
|
721
|
+
def _act_1 val
|
722
|
+
_, _option_list, _, = *val
|
723
|
+
|
724
|
+
master.ins.push [g_parser.rhs.size, _option_list, false]
|
725
|
+
|
726
|
+
end
|
727
|
+
DEPAGER_EXPANDED_CODE
|
728
|
+
|
729
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 185
|
730
|
+
def _act_2 val
|
731
|
+
_, _option_list, _, _, = *val
|
732
|
+
|
733
|
+
master.ins.push [g_parser.rhs.size, _option_list, true]
|
734
|
+
|
735
|
+
end
|
736
|
+
DEPAGER_EXPANDED_CODE
|
737
|
+
|
738
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 191
|
739
|
+
def _act_3 val
|
740
|
+
_option, = *val
|
741
|
+
[_option]
|
742
|
+
|
743
|
+
end
|
744
|
+
DEPAGER_EXPANDED_CODE
|
745
|
+
|
746
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 192
|
747
|
+
def _act_4 val
|
748
|
+
_option_list, _option, = *val
|
749
|
+
_option_list << _option
|
750
|
+
|
751
|
+
end
|
752
|
+
DEPAGER_EXPANDED_CODE
|
753
|
+
|
754
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 195
|
755
|
+
def _act_5 val
|
756
|
+
_, _SYMBOL, = *val
|
757
|
+
[:GOTO, _SYMBOL.value]
|
758
|
+
|
759
|
+
end
|
760
|
+
DEPAGER_EXPANDED_CODE
|
761
|
+
|
762
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 196
|
763
|
+
def _act_6 val
|
764
|
+
_, _SYMBOL, = *val
|
765
|
+
[:ADD, _SYMBOL.value]
|
766
|
+
|
767
|
+
end
|
768
|
+
DEPAGER_EXPANDED_CODE
|
769
|
+
|
770
|
+
module_eval <<-'DEPAGER_EXPANDED_CODE', 'lib/depager/ruby/plugins/slex.dr', 197
|
771
|
+
def _act_7 val
|
772
|
+
_, _SYMBOL, = *val
|
773
|
+
[:SUB, _SYMBOL.value]
|
774
|
+
|
775
|
+
end
|
776
|
+
DEPAGER_EXPANDED_CODE
|
777
|
+
|
778
|
+
|
779
|
+
end
|
780
|
+
|