class Connie::Parser
Attributes
dictionary[RW]
TODO: implement negative lookahead to allow escaping : and escaping the escaping symbol itself \
Public Class Methods
new(dictionary)
click to toggle source
# File lib/connie/parser.rb, line 32 def initialize(dictionary) @dictionary = dictionary end
process(string_to_parse, dictionary = Connie[:names])
click to toggle source
# File lib/connie/parser.rb, line 26 def self.process string_to_parse, dictionary = Connie[:names] tokenized = string_to_parse.split Regexp.union(@syntax.keys) Connie::Parser.new(dictionary).apply_syntax(tokenized).join end
Public Instance Methods
apply_syntax(tokens)
click to toggle source
calls trasform on the tokens marked for interpolation and deals with escaping
# File lib/connie/parser.rb, line 37 def apply_syntax tokens tokens.map do |t| if t.match '\:[a-z]' transform t elsif t[0] && t[0].chr == '\\' # some level of escaping is present t.match %r{([\\]+)\:} raise 'I don\' speak escapeese yet!' else t end end end
transform(string)
click to toggle source
Interpolates a syntax token
# File lib/connie/parser.rb, line 51 def transform string result = nil syntax.each_pair { |k,func| result = instance_exec(string, &func) if string.match(k) } return result end
Private Instance Methods
syntax()
click to toggle source
# File lib/connie/parser.rb, line 59 def syntax @rebound_syntax ||= self.class.instance_variable_get('@syntax') end