Class: Depager::StatefulLexerExtension::PreRhsPostSymbol1::Parser

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

Overview

:nodoc:all

Constant Summary collapse

REDUCE_TABLE =

Reduce Table

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

Term to Int

{
  nil => 0,
  false => 1,
  "[" => 2,
  "]" => 3,
  "?" => 4,
  ">" => 5,
  :SYMBOL => 6,
  "+" => 7,
  "-" => 8,
}
INT_TO_TERM =

Int to Term

[
  nil,
  false,
  "[",
  "]",
  "?",
  ">",
  :SYMBOL,
  "+",
  "-",
]
ACTION_TABLE =

Action Table

[
  [ nil, nil, 2, nil, nil, nil, nil, nil, nil, ],
  [ ACC, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, 5, nil, 6, 7, ],
  [ nil, nil, nil, 8, 9, 5, nil, 6, 7, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, 11, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, 12, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, 13, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, 14, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
  [ nil, nil, 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,
  -3,
  nil,
  nil,
  nil,
  -1,
  nil,
  -4,
  -5,
  -6,
  -7,
  -2,
]
DEFRED_AFTER_SHIFT_TABLE =
[
  nil,
  nil,
  nil,
  nil,
  -3,
  nil,
  nil,
  nil,
  -1,
  nil,
  -4,
  -5,
  -6,
  -7,
  -2,
]
NONTERM_TO_INT =

Nonterm to Int

{
  :start => 0,
  :option_list => 1,
  :option => 2,
}
INT_TO_NONTERM =

Int to Nonterm

[
  :start,
  :option_list,
  :option,
]
GOTO_TABLE =

Goto Table

[
  [ 1, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, 3, 4, ],
  [ nil, nil, 10, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ nil, nil, nil, ],
  [ 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.



644
645
646
647
648
649
650
# File 'lib/depager/plugins/slex.rb', line 644

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



567
# File 'lib/depager/plugins/slex.rb', line 567

def action_table; ACTION_TABLE; end


663
664
665
# File 'lib/depager/plugins/slex.rb', line 663

def banner
  "[> ...] / Depager::StatefulLexerExtension"
end

#defred_after_shift_tableObject



606
# File 'lib/depager/plugins/slex.rb', line 606

def defred_after_shift_table; DEFRED_AFTER_SHIFT_TABLE; end

#defred_tableObject



587
# File 'lib/depager/plugins/slex.rb', line 587

def defred_table; DEFRED_TABLE; end

#do_parse?Boolean

Returns:

  • (Boolean)


653
654
655
656
657
658
659
660
# File 'lib/depager/plugins/slex.rb', line 653

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

#goto_tableObject



642
# File 'lib/depager/plugins/slex.rb', line 642

def goto_table; GOTO_TABLE; end

#int_to_nontermObject



622
# File 'lib/depager/plugins/slex.rb', line 622

def int_to_nonterm; INT_TO_NONTERM; end

#int_to_termObject



547
# File 'lib/depager/plugins/slex.rb', line 547

def int_to_term; INT_TO_TERM; end

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

Yields:

  • (nil, nil)


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

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

          when /\A:[a-zA-Z_]+\??/
            @line = $'
                 yield token(:SYMBOL, $&) 

          when /\A\]/
            @line = $'
                 yield token($&, $&); @line = $'; yield nil, nil 

          when /\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



614
# File 'lib/depager/plugins/slex.rb', line 614

def nonterm_to_int; NONTERM_TO_INT; end

#reduce_tableObject



519
# File 'lib/depager/plugins/slex.rb', line 519

def reduce_table; REDUCE_TABLE; end

#term_to_intObject



533
# File 'lib/depager/plugins/slex.rb', line 533

def term_to_int; TERM_TO_INT; end