Class: RubyLexer::NestedContexts::ForSMContext
- Inherits:
-
ImplicitLhsContext
- Object
- NestedContext
- ImplicitLhsContext
- RubyLexer::NestedContexts::ForSMContext
- Defined in:
- lib/rubylexer/context.rb
Constant Summary collapse
- EVENTS =
normal progression: for => in
[:for,:in]
- LEGAL_SUCCESSORS =
{nil=> [:for], :for => [:in],:in => []}
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
note on :semi and :colon events: in :in state (and only then), (unescaped) newline, semicolon, and (unaccompanied) colon also trigger the :then event.
Attributes inherited from NestedContext
Instance Method Summary collapse
-
#initialize(linenum) ⇒ ForSMContext
constructor
A new instance of ForSMContext.
- #see(lxr, msg) ⇒ Object
Methods inherited from ImplicitLhsContext
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
#state ⇒ Object (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 |