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.



45
46
47
48
49
# File 'lib/rouge/regex_lexer.rb', line 45

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

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



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

def rules
  @rules
end

Instance Method Details

#appended(&defn) ⇒ Object



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

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

#prepended(&defn) ⇒ Object



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

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

#to_state(lexer_class) ⇒ Object



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

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