Class: Depager::CSTBuilderExtension::PostLhs1::Parser

Inherits:
LALR::Basis show all
Includes:
Utils::ExtensionSlaveMethods
Defined in:
lib/depager/plugins/cst.rb

Overview

:nodoc:all

Constant Summary collapse

REDUCE_TABLE =

Reduce Table

[
  [ -1, 1 ],
  [ 0, 3 ],
  [ 1, 1 ],
  [ 1, 3 ],
  [ 2, 1 ],
  [ 2, 3 ],
]
TERM_TO_INT =

Term to Int

{
  nil => 0,
  false => 1,
  "[" => 2,
  "]" => 3,
  "," => 4,
  :ID => 5,
  "=" => 6,
  :LIT => 7,
}
INT_TO_TERM =

Int to Term

[
  nil,
  false,
  "[",
  "]",
  ",",
  :ID,
  "=",
  :LIT,
]
ACTION_TABLE =

Action Table

[
  [ nil, nil, 2, nil, nil, nil, nil, nil, ],
  [ ACC, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, 5, nil, nil, ],
  [ nil, nil, nil, 6, 7, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, 8, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, 5, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, 10, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, ],
]
DEFRED_TABLE =

Default Reduce Table

[
  nil,
  nil,
  nil,
  nil,
  -2,
  -4,
  -1,
  nil,
  nil,
  -3,
  -5,
]
DEFRED_AFTER_SHIFT_TABLE =
[
  nil,
  nil,
  nil,
  nil,
  -2,
  nil,
  -1,
  nil,
  nil,
  -3,
  -5,
]
NONTERM_TO_INT =

Nonterm to Int

{
  :start => 0,
  :pair => 1,
  :expr => 2,
}
INT_TO_NONTERM =

Int to Nonterm

[
  :start,
  :pair,
  :expr,
]
GOTO_TABLE =

Goto Table

[
  [ 1, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, 3, 4, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, 9, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
]

Constants inherited from LALR::Parser

LALR::Parser::ACC

Instance Attribute Summary

Attributes included from Utils::ExtensionSlaveMethods

#d_parser, #g_parser, #master

Attributes inherited from LALR::Basis

#action_value, #basis, #file, #line, #lookahead, #parser_size, #stack

Instance Method Summary collapse

Methods included from Utils::ExtensionSlaveMethods

#abort_driver, #do_default, #do_parse

Methods included from Utils::CodeGeneratorMethods

#expand_inline_code, #generate_action_decorator_code, #generate_decorator_code, #parse_block

Methods included from Utils::CommonMethods

#error_exit, #error_message, #expanded_code_delimiter, #file, #full_target_name, #input_path, #inspect, #target_name, #target_namespace, #warning

Methods inherited from LALR::Basis

#abort_driver, #accept, #do_abort_driver, #error, #next_decorator_index, #reduce, #shift

Methods inherited from LALR::Parser

#accept, #error, #parse, #reduce, #shift

Constructor Details

#initialize(g_parser, master) ⇒ Parser

Returns a new instance of Parser.



457
458
459
460
461
462
463
# File 'lib/depager/plugins/cst.rb', line 457

def initialize g_parser, master
  super()
  @g_parser  = g_parser
  @d_parser  = g_parser.d_parser
  @master    = master
  @decorated = Action.new(self)
end

Instance Method Details

#action_tableObject



392
# File 'lib/depager/plugins/cst.rb', line 392

def action_table; ACTION_TABLE; end


476
477
478
# File 'lib/depager/plugins/cst.rb', line 476

def banner
  "[ ... ] / Depager::CSTBuilderExtension"
end

#defred_after_shift_tableObject



423
# File 'lib/depager/plugins/cst.rb', line 423

def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end

#defred_tableObject



408
# File 'lib/depager/plugins/cst.rb', line 408

def defred_table; DEFRED_TABLE; end

#do_parse?Boolean

Returns:

  • (Boolean)


466
467
468
469
470
471
472
473
# File 'lib/depager/plugins/cst.rb', line 466

def do_parse?
  if @line.match(/^\s*\[/)
     @line = $' 
    true
  else
    false
  end
end

#goto_tableObject



455
# File 'lib/depager/plugins/cst.rb', line 455

def goto_table; GOTO_TABLE; end

#int_to_nontermObject



439
# File 'lib/depager/plugins/cst.rb', line 439

def int_to_nonterm; INT_TO_NONTERM; end

#int_to_termObject



376
# File 'lib/depager/plugins/cst.rb', line 376

def int_to_term; INT_TO_TERM; end

#lex {|nil, nil| ... } ⇒ Object

Yields:

  • (nil, nil)


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
# File 'lib/depager/plugins/cst.rb', line 480

def lex
  begin
    until @line.empty?
      case @line
          when /\A\A\s+/
            @line = $'
                 

          when /\A""/, /\A''/, /\A[0-9]+/, /\A\{\s*\}/, /\A\[\s*\]/, /\Anil/
            @line = $'
                 yield token(:LIT, $&) 

          when /\A\A[a-z][a-z_]*/
            @line = $'
                 yield token(:ID, $&)  

          when /\A\A(.)/
            @line = $'
                 yield token($&, $&)   


      else
        raise RuntimeError, "must not happen #{@line}"
      end
    end
  end while @original_line = @line = file.gets
  yield nil, nil
end

#nonterm_to_intObject



431
# File 'lib/depager/plugins/cst.rb', line 431

def nonterm_to_int; NONTERM_TO_INT; end

#reduce_tableObject



350
# File 'lib/depager/plugins/cst.rb', line 350

def reduce_table; REDUCE_TABLE; end

#term_to_intObject



363
# File 'lib/depager/plugins/cst.rb', line 363

def term_to_int; TERM_TO_INT; end