Class: Lexr::Dsl

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

Instance Method Summary collapse

Constructor Details

#initializeDsl

Returns a new instance of Dsl.



111
112
113
# File 'lib/lexr.rb', line 111

def initialize
  @rules = []
end

Instance Method Details

#ignores(rule_hash) ⇒ Object



122
123
124
# File 'lib/lexr.rb', line 122

def ignores(rule_hash)
  matches rule_hash.merge(:ignore => true)
end

#matches(rule_hash) ⇒ Object



115
116
117
118
119
120
# File 'lib/lexr.rb', line 115

def matches(rule_hash)
  pattern = rule_hash.keys.reject { |k| k.class == Symbol }.first
  symbol = rule_hash[pattern]
  opts = rule_hash.delete_if { |k, v| k.class != Symbol }
  @rules << Rule.new(pattern, symbol, opts)
end

#new(str) ⇒ Object



126
127
128
# File 'lib/lexr.rb', line 126

def new(str)
  Lexr.new(str, @rules)
end