Module: Sexpr
- Extended by:
- Grammar::Tagging
- Includes:
- Node
- Defined in:
- lib/sexpr.rb,
lib/sexpr/node.rb,
lib/sexpr/errors.rb,
lib/sexpr/parser.rb,
lib/sexpr/grammar.rb,
lib/sexpr/matcher.rb,
lib/sexpr/version.rb,
lib/sexpr/rewriter.rb,
lib/sexpr/processor.rb,
lib/sexpr/matcher/many.rb,
lib/sexpr/matcher/rule.rb,
lib/sexpr/parser/citrus.rb,
lib/sexpr/grammar/options.rb,
lib/sexpr/grammar/parsing.rb,
lib/sexpr/grammar/tagging.rb,
lib/sexpr/grammar/matching.rb,
lib/sexpr/matcher/sequence.rb,
lib/sexpr/matcher/terminal.rb,
lib/sexpr/processor/helper.rb,
lib/sexpr/matcher/reference.rb,
lib/sexpr/matcher/alternative.rb,
lib/sexpr/matcher/non_terminal.rb,
lib/sexpr/processor/null_helper.rb,
lib/sexpr/processor/sexpr_coercions.rb
Overview
A helper to manipulate sexp grammars
Defined Under Namespace
Modules: Grammar, Matcher, Node, Parser, Version
Classes: Error, InvalidParseSourceError, NoParserError, Processor, Rewriter, UnexpectedSexprError, UnrecognizedParserError
Constant Summary
collapse
- YAML_OPTIONS =
{ :permitted_classes => %w[Regexp], :aliases => true }
- PathLike =
lambda{|x|
x.respond_to?(:to_path) or (x.is_a?(String) and File.exist?(x))
}
- VERSION =
Version.to_s
Constants included
from Node
Node::EMPTY_TRACKING_MARKERS
Class Method Summary
collapse
default_tagging_module, looks_a_sexpr?, mod2rulename, rule2modname, sexpr, tagging_module_for, tagging_reference
Methods included from Node
#sexpr_body, #sexpr_copy, #sexpr_type, #tracking_markers, #tracking_markers=
Class Method Details
.load(input, options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/sexpr.rb', line 22
def self.load(input, options = {})
case input
when PathLike then load_file input, options
when String then load_string input, options
when Hash then load_hash input, options
else
raise ArgumentError, "Invalid argument for Sexpr::Grammar: #{input}"
end
end
|
.load_file(input, options = {}) ⇒ Object
32
33
34
35
|
# File 'lib/sexpr.rb', line 32
def self.load_file(input, options = {})
path = input.to_path rescue input.to_s
load_hash load_yaml(File.read(path)), options.merge(:path => input)
end
|
.load_hash(input, options = {}) ⇒ Object
41
42
43
44
|
# File 'lib/sexpr.rb', line 41
def self.load_hash(input, options = {})
raise ArgumentError, "Invalid grammar definition: #{input}" unless Hash===input
Grammar.new input, options
end
|
.load_string(input, options = {}) ⇒ Object
37
38
39
|
# File 'lib/sexpr.rb', line 37
def self.load_string(input, options = {})
load_hash load_yaml(input), options
end
|
.load_yaml(source) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/sexpr.rb', line 46
def self.load_yaml(source)
if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
YAML.safe_load(source, **YAML_OPTIONS)
else
YAML.load(source)
end
end
|