Class: Gorgyrella::Parser

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

._gorgyrella_parser_actionsObject

Returns the value of attribute _gorgyrella_parser_actions.



12
13
14
# File 'lib/gorgyrella/parser.rb', line 12

def _gorgyrella_parser_actions
  @_gorgyrella_parser_actions
end

._gorgyrella_parser_eof_actionsObject

Returns the value of attribute _gorgyrella_parser_eof_actions.



289
290
291
# File 'lib/gorgyrella/parser.rb', line 289

def _gorgyrella_parser_eof_actions
  @_gorgyrella_parser_eof_actions
end

._gorgyrella_parser_index_offsetsObject

Returns the value of attribute _gorgyrella_parser_index_offsets.



145
146
147
# File 'lib/gorgyrella/parser.rb', line 145

def _gorgyrella_parser_index_offsets
  @_gorgyrella_parser_index_offsets
end

._gorgyrella_parser_key_offsetsObject

Returns the value of attribute _gorgyrella_parser_key_offsets.



28
29
30
# File 'lib/gorgyrella/parser.rb', line 28

def _gorgyrella_parser_key_offsets
  @_gorgyrella_parser_key_offsets
end

._gorgyrella_parser_range_lengthsObject

Returns the value of attribute _gorgyrella_parser_range_lengths.



125
126
127
# File 'lib/gorgyrella/parser.rb', line 125

def _gorgyrella_parser_range_lengths
  @_gorgyrella_parser_range_lengths
end

._gorgyrella_parser_single_lengthsObject

Returns the value of attribute _gorgyrella_parser_single_lengths.



105
106
107
# File 'lib/gorgyrella/parser.rb', line 105

def _gorgyrella_parser_single_lengths
  @_gorgyrella_parser_single_lengths
end

._gorgyrella_parser_trans_actionsObject

Returns the value of attribute _gorgyrella_parser_trans_actions.



227
228
229
# File 'lib/gorgyrella/parser.rb', line 227

def _gorgyrella_parser_trans_actions
  @_gorgyrella_parser_trans_actions
end

._gorgyrella_parser_trans_keysObject

Returns the value of attribute _gorgyrella_parser_trans_keys.



48
49
50
# File 'lib/gorgyrella/parser.rb', line 48

def _gorgyrella_parser_trans_keys
  @_gorgyrella_parser_trans_keys
end

._gorgyrella_parser_trans_targsObject

Returns the value of attribute _gorgyrella_parser_trans_targs.



165
166
167
# File 'lib/gorgyrella/parser.rb', line 165

def _gorgyrella_parser_trans_targs
  @_gorgyrella_parser_trans_targs
end

.gorgyrella_parser_en_documentObject

Returns the value of attribute gorgyrella_parser_en_document.



322
323
324
# File 'lib/gorgyrella/parser.rb', line 322

def gorgyrella_parser_en_document
  @gorgyrella_parser_en_document
end

.gorgyrella_parser_errorObject

Returns the value of attribute gorgyrella_parser_error.



317
318
319
# File 'lib/gorgyrella/parser.rb', line 317

def gorgyrella_parser_error
  @gorgyrella_parser_error
end

.gorgyrella_parser_first_finalObject

Returns the value of attribute gorgyrella_parser_first_final.



313
314
315
# File 'lib/gorgyrella/parser.rb', line 313

def gorgyrella_parser_first_final
  @gorgyrella_parser_first_final
end

.gorgyrella_parser_startObject

Returns the value of attribute gorgyrella_parser_start.



309
310
311
# File 'lib/gorgyrella/parser.rb', line 309

def gorgyrella_parser_start
  @gorgyrella_parser_start
end

Class Method Details

.run_machine(data, test_mode = false) ⇒ Object



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
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
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
# File 'lib/gorgyrella/parser.rb', line 330

def self.run_machine(data, test_mode = false)
   # puts "Running the state machine with input #{data}..."
   data += "\n\n"
   data = data.unpack("c*") if data.is_a?(String)
   
   line_counter = 0
   line_data = []
 
   builder = Builder.new
 
   eof = -1
  
   
# line 344 "lib/gorgyrella/parser.rb"
begin
	p ||= 0
	pe ||= data.length
	cs = gorgyrella_parser_start
end

# line 123 "lib/gorgyrella/parser.rl"
   
# line 353 "lib/gorgyrella/parser.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
	_keys = _gorgyrella_parser_key_offsets[cs]
	_trans = _gorgyrella_parser_index_offsets[cs]
	_klen = _gorgyrella_parser_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] < _gorgyrella_parser_trans_keys[_mid]
        _upper = _mid - 1
     elsif data[p] > _gorgyrella_parser_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 = _gorgyrella_parser_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] < _gorgyrella_parser_trans_keys[_mid]
       _upper = _mid - 2
     elsif data[p] > _gorgyrella_parser_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
	cs = _gorgyrella_parser_trans_targs[_trans]
	if _gorgyrella_parser_trans_actions[_trans] != 0
		_acts = _gorgyrella_parser_trans_actions[_trans]
		_nacts = _gorgyrella_parser_actions[_acts]
		_acts += 1
		while _nacts > 0
			_nacts -= 1
			_acts += 1
			case _gorgyrella_parser_actions[_acts - 1]
when 0 then
# line 6 "lib/gorgyrella/parser.rl"
		begin

   context = data[p - 30, 60].pack("c*") rescue
   context ||= data[p - 10, 20].pack("c*") rescue
   context ||= data[p-10, 10].pack("c*")
   context ||= "not available"
   raise "an error occurred parsing character " + p.to_s + " code: " + data[p].to_s + " chr: ->" + data[p, 1].pack("c*") + "<- \ncontext: " + context
		end
# line 6 "lib/gorgyrella/parser.rl"
when 1 then
# line 14 "lib/gorgyrella/parser.rl"
		begin

  start = p
		end
# line 14 "lib/gorgyrella/parser.rl"
when 2 then
# line 18 "lib/gorgyrella/parser.rl"
		begin

  text = data[start, p - start].pack("c*").strip
		end
# line 18 "lib/gorgyrella/parser.rl"
when 3 then
# line 22 "lib/gorgyrella/parser.rl"
		begin

   filename = nil
   section = nil
   format = nil
   language = nil
   command = nil
		end
# line 22 "lib/gorgyrella/parser.rl"
when 4 then
# line 30 "lib/gorgyrella/parser.rl"
		begin

   case command
   when :include
    builder.append_section(
        :command => 'include', 
        :file => filename, 
        :section => section, 
        :format => format, 
        :language => language
     )
   when :export
     builder.append_section(:section => section, :language => language)
   when :end
     builder.append_section
   else
    raise command
   end
		end
# line 30 "lib/gorgyrella/parser.rl"
when 5 then
# line 49 "lib/gorgyrella/parser.rl"
		begin

   location = "start"
   line_start_pos = p
		end
# line 49 "lib/gorgyrella/parser.rl"
when 6 then
# line 54 "lib/gorgyrella/parser.rl"
		begin

   current_line_text = data[line_start_pos, p - line_start_pos].pack("c*")
   line_data << [p, cs, current_line_text]
		end
# line 54 "lib/gorgyrella/parser.rl"
when 7 then
# line 70 "lib/gorgyrella/parser.rl"
		begin
filename = text 		end
# line 70 "lib/gorgyrella/parser.rl"
when 8 then
# line 71 "lib/gorgyrella/parser.rl"
		begin
section = text		end
# line 71 "lib/gorgyrella/parser.rl"
when 9 then
# line 72 "lib/gorgyrella/parser.rl"
		begin
format = text		end
# line 72 "lib/gorgyrella/parser.rl"
when 10 then
# line 73 "lib/gorgyrella/parser.rl"
		begin
language = text		end
# line 73 "lib/gorgyrella/parser.rl"
when 11 then
# line 82 "lib/gorgyrella/parser.rl"
		begin
location = 'include command'		end
# line 82 "lib/gorgyrella/parser.rl"
when 12 then
# line 82 "lib/gorgyrella/parser.rl"
		begin
 command = :include 		end
# line 82 "lib/gorgyrella/parser.rl"
when 13 then
# line 83 "lib/gorgyrella/parser.rl"
		begin
location = 'export command'		end
# line 83 "lib/gorgyrella/parser.rl"
when 14 then
# line 83 "lib/gorgyrella/parser.rl"
		begin
 command = :export 		end
# line 83 "lib/gorgyrella/parser.rl"
when 15 then
# line 84 "lib/gorgyrella/parser.rl"
		begin
location = 'end command'		end
# line 84 "lib/gorgyrella/parser.rl"
when 16 then
# line 84 "lib/gorgyrella/parser.rl"
		begin
 command = :end 		end
# line 84 "lib/gorgyrella/parser.rl"
when 17 then
# line 102 "lib/gorgyrella/parser.rl"
		begin
 builder.append_line(current_line_text.chomp) unless location =~ /command/ 		end
# line 102 "lib/gorgyrella/parser.rl"
# line 562 "lib/gorgyrella/parser.rb"
			end # action switch
		end
	end
	if _trigger_goto
		next
	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
	__acts = _gorgyrella_parser_eof_actions[cs]
	__nacts =  _gorgyrella_parser_actions[__acts]
	__acts += 1
	while __nacts > 0
		__nacts -= 1
		__acts += 1
		case _gorgyrella_parser_actions[__acts - 1]
when 0 then
# line 6 "lib/gorgyrella/parser.rl"
		begin

   context = data[p - 30, 60].pack("c*") rescue
   context ||= data[p - 10, 20].pack("c*") rescue
   context ||= data[p-10, 10].pack("c*")
   context ||= "not available"
   raise "an error occurred parsing character " + p.to_s + " code: " + data[p].to_s + " chr: ->" + data[p, 1].pack("c*") + "<- \ncontext: " + context
		end
# line 6 "lib/gorgyrella/parser.rl"
when 6 then
# line 54 "lib/gorgyrella/parser.rl"
		begin

   current_line_text = data[line_start_pos, p - line_start_pos].pack("c*")
   line_data << [p, cs, current_line_text]
		end
# line 54 "lib/gorgyrella/parser.rl"
when 17 then
# line 102 "lib/gorgyrella/parser.rl"
		begin
 builder.append_line(current_line_text.chomp) unless location =~ /command/ 		end
# line 102 "lib/gorgyrella/parser.rl"
# line 614 "lib/gorgyrella/parser.rb"
		end # eof action switch
	end
	if _trigger_goto
		next
	end
end
	end
	if _goto_level <= _out
		break
	end
	end
	end

# line 124 "lib/gorgyrella/parser.rl"
   
   
   if test_mode
     [builder, line_data]
   else
     builder
  end
end