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=, #matches?, #wantarrow

Constructor Details

#initialize(linenum) ⇒ ForSMContext

Returns a new instance of ForSMContext.



290
291
292
293
# File 'lib/rubylexer/context.rb', line 290

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.


288
289
290
# File 'lib/rubylexer/context.rb', line 288

def state
  @state
end

Instance Method Details

#see(lxr, msg) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/rubylexer/context.rb', line 295

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