script = <<-eos if the '$1-$2 No Limit' list is more than a then notify the floor to open if the '$1-$2 No Limit' list is more than 1 then notify the floor to opeeen if the '$1-$2 No Limit' list is more than z then ntify the floor to open if the '$1-$2 No Limit' list is more than 1 then notify the floor to open eos class SyntaxCheckingContext def self.execute(text) rules = polish_text(text) rules.each_with_index do |rule, index| result = self.new.instance_eval(rule) yield result, index if block_given? && result.any? end end def self.polish_text(text) rules = text.split("\n") rules.collect do |rule| rule.gsub!(/'.+'/,extract_stakes(rule)) rule << " end" end end def self.extract_stakes(rule) stakes = rule.scan(/'.+'/).first stakes.delete!("'").gsub!('$','dollar').gsub!('-','dash').gsub!(' ','space') end def self.sym_to_stakes(sym) sym.to_s.gsub!('dollar','$').gsub!('dash','-').gsub!('space',' ') end %w(open is list the to announce floor).each do |method| define_method(method.to_sym) { |*args| true } end def than(arg) arg end def initialize @errors = [] end def more(number) @errors << "more than should be followed by a number" unless number.kind_of?(Numeric) number end def notify(arg) @errors.join(', ') end def method_missing(sym, *args) if sym.to_s =~ /^dollar\d+dashdollar\d+space(Nospace)*Limit/ return true end @errors << "#{sym.to_s} is an invalid keyword" @errors.join(', ') end end module Kernel def silence_warnings old_verbose, $VERBOSE = $VERBOSE, nil yield ensure $VERBOSE = old_verbose end end silence_warnings do puts "\nSyntax Check:" SyntaxCheckingContext.execute(script) do |error, line| puts "errors on line #{line}, (#{error})" end end