Class: RubyLexer::NestedContexts::RescueSMContext

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

Constant Summary collapse

EVENTS =

normal progression: rescue => arrow => then

[:rescue,:arrow,:then,:semi,:colon]
{
  nil=> [:rescue], 
  :rescue => [:arrow,:then,:semi,:colon], 
  :arrow => [:then,:semi,:colon],
  :then => []
}

Instance Attribute Summary collapse

Attributes inherited from NestedContext

#ender, #linenum, #starter

Instance Method Summary collapse

Methods inherited from NestedContext

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

Constructor Details

#initialize(linenum) ⇒ RescueSMContext

Returns a new instance of RescueSMContext.



260
261
262
263
264
# File 'lib/rubylexer/context.rb', line 260

def initialize linenum
  dflt_initialize("rescue","then",linenum)
  @state=nil
  @state=:rescue 
end

Instance Attribute Details

#stateObject (readonly)

note on :semi and :colon events:

(unescaped) newline, semicolon, and (unaccompanied) colon 
also trigger the :then event. they are ignored if in :then 
state already.


258
259
260
# File 'lib/rubylexer/context.rb', line 258

def state
  @state
end

Instance Method Details

#see(lxr, msg) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/rubylexer/context.rb', line 266

def see(lxr,msg)
  stack=lxr.parsestack
  case msg
  when :rescue;
    WantsEndContext===stack.last or 
      BlockContext===stack.last or 
      ParenContext===stack.last or 
      raise 'syntax error: rescue not expected at this time'
  when :arrow; #local var defined in this state
  when :then,:semi,:colon;
    msg=:then
    self.equal? stack.pop or raise 'syntax error: then not expected at this time'
              #pop self off owning context stack
  when :comma, :splat; return
  else super
  end
  LEGAL_SUCCESSORS[@state].include? msg or raise "rescue syntax error: #{msg} unexpected in #@state"
  @state=msg
end