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

Constructor Details

#initialize(linenum) ⇒ RescueSMContext

Returns a new instance of RescueSMContext.



253
254
255
256
257
# File 'lib/rubylexer/context.rb', line 253

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.


251
252
253
# File 'lib/rubylexer/context.rb', line 251

def state
  @state
end

Instance Method Details

#see(lxr, msg) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/rubylexer/context.rb', line 259

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