Class: Rouge::RegexLexer::StateDSL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &defn) ⇒ StateDSL

Returns a new instance of StateDSL.


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

def initialize(name, &defn)
  @name = name
  @defn = defn
  @rules = []
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules


42
43
44
# File 'lib/rouge/regex_lexer.rb', line 42

def rules
  @rules
end

Instance Method Details

#appended(&defn) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/rouge/regex_lexer.rb', line 65

def appended(&defn)
  parent_defn = @defn
  StateDSL.new(@name) do
    instance_eval(&parent_defn)
    instance_eval(&defn)
  end
end

#prepended(&defn) ⇒ Object


57
58
59
60
61
62
63
# File 'lib/rouge/regex_lexer.rb', line 57

def prepended(&defn)
  parent_defn = @defn
  StateDSL.new(@name) do
    instance_eval(&defn)
    instance_eval(&parent_defn)
  end
end

#to_state(lexer_class) ⇒ Object


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

def to_state(lexer_class)
  load!
  rules = @rules.map do |rule|
    rule.is_a?(String) ? lexer_class.get_state(rule) : rule
  end
  State.new(@name, rules)
end