Class: RubyLexer::NestedContexts::ForSMContext

Inherits:
ImplicitLhsContext show all
Defined in:
lib/rubylexer/context.rb

Constant Summary collapse

EVENTS =

normal progression: for => in

[:for,:in]
{nil=> [:for], :for => [:in],:in => []}

Instance Attribute Summary collapse

Attributes inherited from NestedContext

#ender, #linenum, #starter

Instance Method Summary collapse

Methods inherited from ImplicitLhsContext

#ender, #lhs, #starter

Methods inherited from NestedContext

#lhs, #lhs=, #matches?, #wantarrow

Constructor Details

#initialize(linenum) ⇒ ForSMContext

Returns a new instance of ForSMContext.



297
298
299
300
# File 'lib/rubylexer/context.rb', line 297

def initialize linenum
  dflt_initialize("for","in",linenum)
  @state=:for
end

Instance Attribute Details

#stateObject (readonly)

note on :semi and :colon events: in :in state (and only then),

(unescaped) newline, semicolon, and (unaccompanied) colon 
also trigger the :then event. otherwise, they are ignored.


295
296
297
# File 'lib/rubylexer/context.rb', line 295

def state
  @state
end

Instance Method Details

#see(lxr, msg) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/rubylexer/context.rb', line 302

def see(lxr,msg)
  stack=lxr.parsestack
  assert msg!=:for
  case msg
  when :for; WantsEndContext===stack.last or raise 'syntax error: for not expected at this time'
             #local var defined in this state
             #never actually used?
  when :in;  self.equal? stack.pop or raise 'syntax error: in not expected at this time'
             stack.push ExpectDoOrNlContext.new("for",/(do|;|:|\n)/,@linenum) 
             #pop self off owning context stack and push ExpectDoOrNlContext
  when :comma, :splat; return
  else super
  end
  LEGAL_SUCCESSORS[@state].include? msg or raise "for syntax error: #{msg} unexpected in #@state"
  @state=msg
end