Class: ManaMana::RDSL::Lexer

Inherits:
Object
  • Object
show all
Defined in:
lib/manamana/rdsl/lexer.rb

Instance Method Summary collapse

Constructor Details

#initializeLexer

Returns a new instance of Lexer.



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
# File 'lib/manamana/rdsl/lexer.rb', line 17

def initialize
  
# line 20 "lib/manamana/rdsl/lexer.rb"
class << self
	attr_accessor :_lexer_actions
	private :_lexer_actions, :_lexer_actions=
end
self._lexer_actions = [
	0, 1, 2, 1, 3, 1, 5, 1, 
	6, 1, 7, 1, 8, 1, 9, 1, 
	10, 1, 11, 1, 12, 2, 0, 1, 
	2, 3, 4
]

class << self
	attr_accessor :_lexer_key_offsets
	private :_lexer_key_offsets, :_lexer_key_offsets=
end
self._lexer_key_offsets = [
	0, 0, 15, 28, 42, 54, 56, 57, 
	58, 59, 60, 61, 62, 63, 70, 81, 
	90, 91, 93, 94, 95, 98, 112, 117, 
	121, 125, 127, 128, 133, 137, 141, 143
]

class << self
	attr_accessor :_lexer_trans_keys
	private :_lexer_trans_keys, :_lexer_trans_keys=
end
self._lexer_trans_keys = [
	9, 10, 13, 32, 61, 93, 125, 40, 
	41, 48, 57, 65, 91, 97, 123, 9, 
	32, 61, 93, 125, 40, 41, 48, 57, 
	65, 91, 97, 123, 9, 10, 13, 32, 
	93, 125, 40, 41, 48, 57, 65, 91, 
	97, 123, 9, 32, 93, 125, 40, 41, 
	48, 57, 65, 91, 97, 123, 10, 13, 
	10, 10, 10, 61, 61, 10, 32, 60, 
	48, 57, 65, 90, 97, 122, 9, 10, 
	13, 32, 60, 48, 57, 65, 90, 97, 
	122, 9, 32, 60, 48, 57, 65, 90, 
	97, 122, 10, 10, 13, 10, 10, 124, 
	32, 126, 32, 42, 93, 124, 9, 13, 
	40, 41, 48, 57, 65, 91, 97, 125, 
	9, 10, 13, 32, 126, 9, 10, 13, 
	32, 10, 13, 32, 126, 10, 13, 61, 
	9, 10, 13, 32, 126, 9, 10, 13, 
	32, 10, 13, 32, 126, 10, 13, 124, 
	32, 126, 0
]

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

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

class << self
	attr_accessor :_lexer_index_offsets
	private :_lexer_index_offsets, :_lexer_index_offsets=
end
self._lexer_index_offsets = [
	0, 0, 12, 22, 33, 42, 45, 47, 
	49, 51, 53, 55, 57, 59, 64, 73, 
	80, 82, 85, 87, 89, 92, 102, 107, 
	112, 116, 119, 121, 126, 131, 135, 138
]

class << self
	attr_accessor :_lexer_indicies
	private :_lexer_indicies, :_lexer_indicies=
end
self._lexer_indicies = [
	1, 2, 3, 1, 5, 4, 4, 4, 
	4, 4, 4, 0, 1, 1, 5, 4, 
	4, 4, 4, 4, 4, 0, 6, 2, 
	3, 6, 4, 4, 4, 4, 4, 4, 
	0, 6, 6, 4, 4, 4, 4, 4, 
	4, 0, 2, 3, 0, 2, 0, 7, 
	0, 8, 0, 9, 0, 10, 0, 11, 
	0, 12, 13, 14, 14, 14, 14, 13, 
	16, 17, 18, 16, 19, 19, 19, 19, 
	15, 16, 16, 19, 19, 19, 19, 15, 
	20, 15, 17, 18, 15, 17, 15, 21, 
	15, 24, 23, 22, 25, 27, 26, 23, 
	25, 26, 26, 26, 26, 13, 29, 11, 
	30, 26, 28, 29, 11, 30, 29, 28, 
	8, 31, 4, 28, 7, 32, 28, 10, 
	33, 35, 20, 36, 14, 34, 35, 20, 
	36, 35, 34, 20, 36, 19, 34, 21, 
	37, 34, 24, 23, 38, 0
]

class << self
	attr_accessor :_lexer_trans_targs
	private :_lexer_trans_targs, :_lexer_trans_targs=
end
self._lexer_trans_targs = [
	21, 2, 25, 6, 24, 9, 4, 5, 
	3, 10, 26, 1, 13, 0, 27, 21, 
	15, 30, 18, 29, 14, 17, 21, 20, 
	31, 21, 22, 12, 21, 23, 11, 8, 
	7, 21, 21, 28, 16, 19, 21
]

class << self
	attr_accessor :_lexer_trans_actions
	private :_lexer_trans_actions, :_lexer_trans_actions=
end
self._lexer_trans_actions = [
	17, 0, 3, 0, 3, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 3, 15, 
	0, 3, 0, 3, 0, 0, 19, 0, 
	24, 5, 3, 0, 13, 3, 0, 0, 
	0, 7, 9, 3, 0, 0, 11
]

class << self
	attr_accessor :_lexer_to_state_actions
	private :_lexer_to_state_actions, :_lexer_to_state_actions=
end
self._lexer_to_state_actions = [
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 21, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0
]

class << self
	attr_accessor :_lexer_from_state_actions
	private :_lexer_from_state_actions, :_lexer_from_state_actions=
end
self._lexer_from_state_actions = [
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0, 
	0, 0, 0, 0, 0, 1, 0, 0, 
	0, 0, 0, 0, 0, 0, 0, 0
]

class << self
	attr_accessor :_lexer_eof_trans
	private :_lexer_eof_trans, :_lexer_eof_trans=
end
self._lexer_eof_trans = [
	0, 1, 1, 1, 1, 1, 1, 1, 
	1, 1, 1, 1, 0, 0, 16, 16, 
	16, 16, 16, 16, 23, 0, 29, 29, 
	29, 29, 34, 35, 35, 35, 35, 39
]

class << self
	attr_accessor :lexer_start
end
self.lexer_start = 21;
class << self
	attr_accessor :lexer_first_final
end
self.lexer_first_final = 21;
class << self
	attr_accessor :lexer_error
end
self.lexer_error = 0;

class << self
	attr_accessor :lexer_en_main
end
self.lexer_en_main = 21;


# line 41 "src/rdsl/lexer.rl"
  # %% this just fixes syntax highlighting in TextMate et al.
end

Instance Method Details

#emit_group_name(token_array, data, ts, te) ⇒ Object



206
207
208
209
# File 'lib/manamana/rdsl/lexer.rb', line 206

def emit_group_name(token_array, data, ts, te)
  value = data[ts...te].pack("c*").split(/=+/)[0].strip
  token_array << [:GROUP, { value: value, offset: ts }]
end

#emit_requirement(token_array, data, ts, te) ⇒ Object



223
224
225
226
# File 'lib/manamana/rdsl/lexer.rb', line 223

def emit_requirement(token_array, data, ts, te)
  value = data[ts...te].pack("c*").gsub(/^\* /, '').split.join(' ')
  token_array << [:REQUIREMENT, { value: value, offset: ts }]
end

#emit_row(data, target_array, ts, te) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
# File 'lib/manamana/rdsl/lexer.rb', line 211

def emit_row(data, target_array, ts, te)
  cells = data[(ts + 1)...( te - 1)].pack("c*")

  # ignore borders
  return if /^\-+/ =~ cells

  target_array << [:ROW, { offset: ts }]
  cells.split('|').each do |cell|
    target_array << [:CELL, { value: cell.strip }]
  end
end

#emit_text(token_array, data, ts, te) ⇒ Object



228
229
230
231
# File 'lib/manamana/rdsl/lexer.rb', line 228

def emit_text(token_array, data, ts, te)
    value = data[ts...te].pack("c*").strip.split.join(' ')
  token_array << [:TEXT, { value: value, offset: ts }]
end

#tokenize(data) ⇒ Object



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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/manamana/rdsl/lexer.rb', line 233

def tokenize(data)
  data = data.unpack("c*") if(data.is_a?(String))
  eof = data.length
  token_array = []

  
# line 240 "lib/manamana/rdsl/lexer.rb"
begin
	p ||= 0
	pe ||= data.length
	cs = lexer_start
	ts = nil
	te = nil
	act = 0
end

# line 77 "src/rdsl/lexer.rl"
  
# line 252 "lib/manamana/rdsl/lexer.rb"
begin
	_klen, _trans, _keys, _acts, _nacts = nil
	_goto_level = 0
	_resume = 10
	_eof_trans = 15
	_again = 20
	_test_eof = 30
	_out = 40
	while true
	_trigger_goto = false
	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
	_acts = _lexer_from_state_actions[cs]
	_nacts = _lexer_actions[_acts]
	_acts += 1
	while _nacts > 0
		_nacts -= 1
		_acts += 1
		case _lexer_actions[_acts - 1]
			when 2 then
# line 1 "NONE"
		begin
ts = p
		end
# line 286 "lib/manamana/rdsl/lexer.rb"
		end # from state action switch
	end
	if _trigger_goto
		next
	end
	_keys = _lexer_key_offsets[cs]
	_trans = _lexer_index_offsets[cs]
	_klen = _lexer_single_lengths[cs]
	_break_match = false
	
	begin
	  if _klen > 0
_lower = _keys
_upper = _keys + _klen - 1

loop do
   break if _upper < _lower
   _mid = _lower + ( (_upper - _lower) >> 1 )

   if data[p].ord < _lexer_trans_keys[_mid]
      _upper = _mid - 1
   elsif data[p].ord > _lexer_trans_keys[_mid]
      _lower = _mid + 1
   else
      _trans += (_mid - _keys)
      _break_match = true
      break
   end
end # loop
break if _break_match
_keys += _klen
_trans += _klen
	  end
	  _klen = _lexer_range_lengths[cs]
	  if _klen > 0
_lower = _keys
_upper = _keys + (_klen << 1) - 2
loop do
   break if _upper < _lower
   _mid = _lower + (((_upper-_lower) >> 1) & ~1)
   if data[p].ord < _lexer_trans_keys[_mid]
     _upper = _mid - 2
   elsif data[p].ord > _lexer_trans_keys[_mid+1]
     _lower = _mid + 2
   else
     _trans += ((_mid - _keys) >> 1)
     _break_match = true
     break
   end
end # loop
break if _break_match
_trans += _klen
	  end
	end while false
	_trans = _lexer_indicies[_trans]
	end
	if _goto_level <= _eof_trans
	cs = _lexer_trans_targs[_trans]
	if _lexer_trans_actions[_trans] != 0
		_acts = _lexer_trans_actions[_trans]
		_nacts = _lexer_actions[_acts]
		_acts += 1
		while _nacts > 0
			_nacts -= 1
			_acts += 1
			case _lexer_actions[_acts - 1]
when 3 then
# line 1 "NONE"
		begin
te = p+1
		end
when 4 then
# line 25 "src/rdsl/lexer.rl"
		begin
act = 3;		end
when 5 then
# line 28 "src/rdsl/lexer.rl"
		begin
te = p+1
		end
when 6 then
# line 23 "src/rdsl/lexer.rl"
		begin
te = p
p = p - 1; begin  emit_group_name(token_array, data, ts, te)   end
		end
when 7 then
# line 24 "src/rdsl/lexer.rl"
		begin
te = p
p = p - 1; begin  emit_requirement(token_array, data, ts, te)  end
		end
when 8 then
# line 25 "src/rdsl/lexer.rl"
		begin
te = p
p = p - 1; begin  emit_row(data, token_array, ts, te)  end
		end
when 9 then
# line 26 "src/rdsl/lexer.rl"
		begin
te = p
p = p - 1; begin  emit_text(token_array, data, ts, te)  end
		end
when 10 then
# line 24 "src/rdsl/lexer.rl"
		begin
 begin p = ((te))-1; end
 begin  emit_requirement(token_array, data, ts, te)  end
		end
when 11 then
# line 26 "src/rdsl/lexer.rl"
		begin
 begin p = ((te))-1; end
 begin  emit_text(token_array, data, ts, te)  end
		end
when 12 then
# line 1 "NONE"
		begin
	case act
	when 0 then
	begin	begin
		cs = 0
		_trigger_goto = true
		_goto_level = _again
		break
	end
end
	when 3 then
	begin begin p = ((te))-1; end
 emit_row(data, token_array, ts, te) end
end 
			end
# line 420 "lib/manamana/rdsl/lexer.rb"
			end # action switch
		end
	end
	if _trigger_goto
		next
	end
	end
	if _goto_level <= _again
	_acts = _lexer_to_state_actions[cs]
	_nacts = _lexer_actions[_acts]
	_acts += 1
	while _nacts > 0
		_nacts -= 1
		_acts += 1
		case _lexer_actions[_acts - 1]
when 0 then
# line 1 "NONE"
		begin
ts = nil;		end
when 1 then
# line 1 "NONE"
		begin
act = 0
		end
# line 445 "lib/manamana/rdsl/lexer.rb"
		end # to state action switch
	end
	if _trigger_goto
		next
	end
	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
	if _lexer_eof_trans[cs] > 0
		_trans = _lexer_eof_trans[cs] - 1;
		_goto_level = _eof_trans
		next;
	end
end
	end
	if _goto_level <= _out
		break
	end
	end
	end

# line 78 "src/rdsl/lexer.rl"

  token_array
end