-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,26 +382,25 @@ def self.extend_object(obj) | |
super | ||
end | ||
|
||
# Parses the given +string+ using this grammar's root rule. Accepts the same | ||
# Parses the given +source+ using this grammar's root rule. Accepts the same | ||
# +options+ as Rule#parse, plus the following: | ||
# | ||
# root:: The name of the root rule to start parsing at. Defaults to this | ||
# grammar's #root. | ||
def parse(string, options={}) | ||
def parse(source, options={}) | ||
rule_name = options.delete(:root) || root | ||
raise Error, "No root rule specified" unless rule_name | ||
rule = rule(rule_name) | ||
raise Error, "No rule named \"#{rule_name}\"" unless rule | ||
rule.parse(string, options) | ||
rule.parse(source, options) | ||
end | ||
|
||
# Parse the given file at +path+ using this grammar's root role. Accept the same | ||
# +options+ as #parser. | ||
def parse_file(path, options = {}) | ||
unless path.respond_to?(:to_path) | ||
require 'pathname' | ||
path = Pathname.new(path) | ||
end | ||
# Parses the contents of the file at the given +path+ using this grammar's | ||
# #root rule. Accepts the same +options+ as #parse. | ||
def parse_file(path, options={}) | ||
path = Pathname.new(path.to_str) unless Pathname === path | ||
raise Error, "Cannot find file #{path}" unless path.exist? | ||
raise Error, "Cannot read file #{path}" unless path.readable? | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mjackson
Author
Owner
|
||
parse(path, options) | ||
end | ||
|
||
|
Well, I know at least one gem (epath) that provide a Path implementation, far better than Pathname, and which will not be usable here. Checking for respond_to?(:to_path) is standard in the ruby 1.9.x branch.
Also, I'm not sure that raising a Citrus::Error is actually a good idea if something goes wrong with the file. I would say that the path must exit and be readable as a precondition and that a IOError may occur otherwise.
What do you think?