Module: Parser::Lexer::Explanation

Defined in:
lib/parser/lexer/explanation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/parser/lexer/explanation.rb', line 7

def self.included(klass)
  klass.class_exec do
    alias_method :state_before_explanation=,  :state=
    alias_method :advance_before_explanation, :advance

    remove_method :state=, :advance
  end
end

Instance Method Details

#advanceObject

Like #advance, but also pretty-print the token and its position in the stream to ‘stdout`.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/parser/lexer/explanation.rb', line 18

def advance
  type, (val, range) = advance_before_explanation

  more = "(in-kwarg)" if @context.in_kwarg

  puts decorate(range,
                Color.green("#{type} #{val.inspect}"),
                "#{state.to_s.ljust(12)} #{@cond} #{@cmdarg} #{more}")

  [ type, [val, range] ]
end

#state=(new_state) ⇒ Object



30
31
32
33
34
35
# File 'lib/parser/lexer/explanation.rb', line 30

def state=(new_state)
  puts "  #{Color.yellow(">>> STATE SET <<<", bold: true)} " +
       "#{new_state.to_s.ljust(12)} #{@cond} #{@cmdarg}".rjust(66)

  self.state_before_explanation = new_state
end