Class: Rouge::RegexLexer::StateDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/rouge/lexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ StateDSL

Returns a new instance of StateDSL.



338
339
340
# File 'lib/rouge/lexer.rb', line 338

def initialize(rules)
  @rules = rules
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



337
338
339
# File 'lib/rouge/lexer.rb', line 337

def rules
  @rules
end

Instance Method Details

#mixin(lexer_name) ⇒ Object



362
363
364
# File 'lib/rouge/lexer.rb', line 362

def mixin(lexer_name)
  rules << lexer_name.to_s
end

#rule(re, tok = nil, next_state = nil, &callback) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/rouge/lexer.rb', line 342

def rule(re, tok=nil, next_state=nil, &callback)
  if block_given?
    next_state = tok
  else
    tok = Token[tok]

    callback = proc do |ss|
      token tok, ss[0]
      case next_state
      when :pop!
        pop!
      when Symbol
        push next_state
      end # else pass
    end
  end

  rules << Rule.new(re, callback, next_state)
end