Class: Cambridge::Parser::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/cambridge/parser/scan.rb

Instance Method Summary collapse

Constructor Details

#initializeScan

Returns a new instance of Scan.



10
11
12
13
# File 'lib/cambridge/parser/scan.rb', line 10

def initialize
  @tokens = []
  @num_stack = []
end

Instance Method Details

#atos(a) ⇒ Object



310
311
312
# File 'lib/cambridge/parser/scan.rb', line 310

def atos(a)
  a.map(&:chr).join
end

#parse(line) ⇒ Object



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
# File 'lib/cambridge/parser/scan.rb', line 15

def parse(line)
  data = line.codepoints.to_a
  stack = []
  p = 0
  ts = 0
  te = 0
  act = 0
  eof = data.length
  
# line 25 "lib/cambridge/parser/scan.rb"
class << self
	attr_accessor :_scanner_trans_keys
	private :_scanner_trans_keys, :_scanner_trans_keys=
end
self._scanner_trans_keys = [
	0, 0, 34, 122, 34, 34, 
	9, 122, 9, 122, 9, 
	34, 9, 57, 9, 122, 
	9, 57, 9, 122, 0
]

class << self
	attr_accessor :_scanner_key_spans
	private :_scanner_key_spans, :_scanner_key_spans=
end
self._scanner_key_spans = [
	0, 89, 1, 114, 114, 26, 49, 114, 
	49, 114
]

class << self
	attr_accessor :_scanner_index_offsets
	private :_scanner_index_offsets, :_scanner_index_offsets=
end
self._scanner_index_offsets = [
	0, 0, 90, 92, 207, 322, 349, 399, 
	514, 564
]

class << self
	attr_accessor :_scanner_indicies
	private :_scanner_indicies, :_scanner_indicies=
end
self._scanner_indicies = [
	0, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 2, 2, 
	2, 2, 2, 2, 2, 2, 2, 2, 
	1, 1, 1, 1, 1, 1, 1, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 1, 1, 1, 1, 1, 1, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 3, 3, 3, 3, 3, 3, 3, 
	3, 1, 5, 4, 6, 6, 6, 6, 
	6, 4, 4, 4, 4, 4, 4, 4, 
	4, 4, 4, 4, 4, 4, 4, 4, 
	4, 4, 4, 6, 4, 7, 4, 4, 
	4, 4, 4, 4, 4, 4, 4, 4, 
	4, 4, 4, 8, 8, 8, 8, 8, 
	8, 8, 8, 8, 8, 4, 4, 4, 
	4, 4, 4, 4, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 4, 4, 
	4, 4, 4, 4, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 9, 9, 
	9, 9, 9, 9, 9, 9, 4, 10, 
	10, 10, 10, 10, 1, 1, 1, 1, 
	1, 1, 1, 1, 1,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
	1, 16, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 17, 17, 17, 17, 17, 17, 17, 
	17, 17, 17, 1, 18, 18, 18, 18, 
	18, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 18, 1, 1, 1, 1, 
	1, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 19, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 1, 1, 1, 
	1, 1, 1, 1, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 1, 1, 
	1, 1, 1, 1, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 19, 19, 
	19, 19, 19, 19, 19, 19, 1, 0
]

class << self
	attr_accessor :_scanner_trans_targs
	private :_scanner_trans_targs, :_scanner_trans_targs=
end
self._scanner_trans_targs = [
	2, 0, 8, 9, 2, 5, 3, 5, 
	6, 7, 4, 3, 3, 6, 3, 7, 
	4, 8, 4, 9
]

class << self
	attr_accessor :_scanner_trans_actions
	private :_scanner_trans_actions, :_scanner_trans_actions=
end
self._scanner_trans_actions = [
	1, 0, 2, 3, 0, 0, 0, 1, 
	2, 3, 0, 4, 5, 0, 6, 0, 
	5, 0, 6, 0
]

class << self
	attr_accessor :_scanner_eof_actions
	private :_scanner_eof_actions, :_scanner_eof_actions=
end
self._scanner_eof_actions = [
	0, 0, 0, 0, 0, 4, 5, 6, 
	5, 6
]

class << self
	attr_accessor :scanner_start
end
self.scanner_start = 1;
class << self
	attr_accessor :scanner_first_final
end
self.scanner_first_final = 5;
class << self
	attr_accessor :scanner_error
end
self.scanner_error = 0;

class << self
	attr_accessor :scanner_en_main
end
self.scanner_en_main = 1;


# line 48 "lib/cambridge/parser/scan.rl"
  
# line 197 "lib/cambridge/parser/scan.rb"
begin
	p ||= 0
	pe ||= data.length
	cs = scanner_start
end

# line 49 "lib/cambridge/parser/scan.rl"
  
# line 206 "lib/cambridge/parser/scan.rb"
begin
	testEof = false
	_slen, _trans, _keys, _inds, _acts, _nacts = nil
	_goto_level = 0
	_resume = 10
	_eof_trans = 15
	_again = 20
	_test_eof = 30
	_out = 40
	while true
	if _goto_level <= 0
	if p == pe
		_goto_level = _test_eof
		next
	end
	if cs == 0
		_goto_level = _out
		next
	end
	end
	if _goto_level <= _resume
	_keys = cs << 1
	_inds = _scanner_index_offsets[cs]
	_slen = _scanner_key_spans[cs]
	_trans = if (   _slen > 0 && 
			_scanner_trans_keys[_keys] <= data[p].ord && 
			data[p].ord <= _scanner_trans_keys[_keys + 1] 
) then
			_scanner_indicies[ _inds + data[p].ord - _scanner_trans_keys[_keys] ] 
		 else 
			_scanner_indicies[ _inds + _slen ]
		 end
	cs = _scanner_trans_targs[_trans]
	if _scanner_trans_actions[_trans] != 0
	case _scanner_trans_actions[_trans]
	when 1 then
# line 4 "lib/cambridge/parser/scan.rl"
		begin
 @mark_str = p 		end
	when 4 then
# line 5 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::String.new(data[@mark_str..p-1]) 		end
	when 3 then
# line 7 "lib/cambridge/parser/scan.rl"
		begin
 @mark_cmd = p 		end
	when 6 then
# line 8 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::Command.new(data[@mark_cmd..p-1]) 		end
	when 2 then
# line 10 "lib/cambridge/parser/scan.rl"
		begin
 @mark_num = p 		end
	when 5 then
# line 11 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::Number.new(data[@mark_num..p-1]) 		end
# line 266 "lib/cambridge/parser/scan.rb"
	end
	end
	end
	if _goto_level <= _again
	if cs == 0
		_goto_level = _out
		next
	end
	p += 1
	if p != pe
		_goto_level = _resume
		next
	end
	end
	if _goto_level <= _test_eof
	if p == eof
	  case _scanner_eof_actions[cs]
	when 4 then
# line 5 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::String.new(data[@mark_str..p-1]) 		end
	when 6 then
# line 8 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::Command.new(data[@mark_cmd..p-1]) 		end
	when 5 then
# line 11 "lib/cambridge/parser/scan.rl"
		begin
 @tokens << Tokens::Number.new(data[@mark_num..p-1]) 		end
# line 296 "lib/cambridge/parser/scan.rb"
	  end
	end

	end
	if _goto_level <= _out
		break
	end
end
	end

# line 50 "lib/cambridge/parser/scan.rl"
  return @tokens
end