Class: Rouge::RegexLexer::State

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

Overview

a State is a named set of rules that can be tested for or mixed in.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &defn) ⇒ State

Returns a new instance of State.



39
40
41
42
# File 'lib/rouge/regex_lexer.rb', line 39

def initialize(name, &defn)
  @name = name
  @defn = defn
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/rouge/regex_lexer.rb', line 38

def name
  @name
end

Instance Method Details

#load!(lexer_class) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rouge/regex_lexer.rb', line 48

def load!(lexer_class)
  return self if @loaded
  @loaded = true
  StateDSL.new(rules).instance_eval(&@defn)

  rules.map! do |rule|
    rule.is_a?(String) ? lexer_class.get_state(rule) : rule
  end

  self
end

#rulesObject



44
45
46
# File 'lib/rouge/regex_lexer.rb', line 44

def rules
  @rules ||= []
end