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.



219
220
221
# File 'lib/rouge/lexer.rb', line 219

def initialize(rules)
  @rules = rules
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



218
219
220
# File 'lib/rouge/lexer.rb', line 218

def rules
  @rules
end

Instance Method Details

#mixin(lexer_name) ⇒ Object



243
244
245
# File 'lib/rouge/lexer.rb', line 243

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

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



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/rouge/lexer.rb', line 223

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

    callback = proc do
      token tok
      case next_state
      when :pop!
        pop!
      when Symbol
        push next_state
      end # else pass
    end
  end

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