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.



77
78
79
80
81
82
83
# File 'lib/rouge/regex_lexer.rb', line 77

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



76
77
78
# File 'lib/rouge/regex_lexer.rb', line 76

def name
  @name
end

#rulesObject (readonly)

Returns the value of attribute rules.



76
77
78
# File 'lib/rouge/regex_lexer.rb', line 76

def rules
  @rules
end

Instance Method Details

#appended(&defn) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/rouge/regex_lexer.rb', line 101

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

#prepended(&defn) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/rouge/regex_lexer.rb', line 93

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

#to_state(lexer_class) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/rouge/regex_lexer.rb', line 85

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