lib/sexpr.rb in sexpr-0.2.0 vs lib/sexpr.rb in sexpr-0.3.0

- old
+ new

@@ -1,31 +1,38 @@ require_relative "sexpr/version" require_relative "sexpr/loader" +require_relative "sexpr/errors" # # A helper to manipulate sexp grammars # module Sexpr - def self.load(input, options = {}) - case input - when lambda{|x| x.respond_to?(:to_path)} - require 'yaml' - load(YAML.load_file(input.to_path), options) - when String - require 'yaml' - load(YAML.load(input), options) - when Hash - Grammar.new(input, options) - else - raise ArgumentError, "Invalid argument for Sexpr::Grammar: #{input}" - end + PathLike = lambda{|x| + x.respond_to?(:to_path) or (x.is_a?(String) and File.exists?(x)) + } + + def self.load(input) + defn = case input + when PathLike + require 'yaml' + path = input.respond_to?(:to_path) ? input.to_path : input.to_s + YAML.load_file(path).merge(:path => input) + when String + require 'yaml' + YAML.load(input) + when Hash + input + else + raise ArgumentError, "Invalid argument for Sexpr::Grammar: #{input}" + end + Grammar.new defn end + def self.sexpr(arg) + Object.new.extend(Sexpr::Grammar::Tagging).sexpr(arg) + end + end # module Sexpr +require_relative "sexpr/node" require_relative "sexpr/grammar" -require_relative "sexpr/element" -require_relative "sexpr/alternative" -require_relative "sexpr/many" -require_relative "sexpr/reference" -require_relative "sexpr/rule" -require_relative "sexpr/sequence" -require_relative "sexpr/terminal" +require_relative "sexpr/matcher" +require_relative "sexpr/parser" \ No newline at end of file