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
50
# File 'lib/rouge/regex_lexer.rb', line 45

def initialize(name, &defn)
  @name = name
  @defn = defn
  @rules = []
  @loaded = false
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


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

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

#prepended(&defn) ⇒ Object


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

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

#to_state(lexer_class) ⇒ Object


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

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