Module: Rattler::HelperMethods
Overview
Convenience methods for defining parsers
Constant Summary collapse
- @@defaults =
{ :type => :extended_packrat }
- @@parser_types =
{ :recursive_descent => :RecursiveDescentParser, :packrat => :PackratParser, :extended_packrat => :ExtendedPackratParser }
Instance Method Summary collapse
-
#compile(mod, grammar_or_parser, opts = {}) ⇒ Object
Compile grammar source or a parser model into match methods in a module.
-
#compile_parser(*args) ⇒ Class
Define a parser with the given grammar and compile it into a parser class using the given options.
Instance Method Details
#compile(mod, grammar, opts) ⇒ Module #compile(mod, parser, opts) ⇒ Module
Compile grammar source or a parser model into match methods in a module.
44 45 46 |
# File 'lib/rattler.rb', line 44 def compile(mod, grammar_or_parser, opts={}) Rattler::Compiler.compile(mod, grammar_or_parser, opts) end |
#compile_parser(*args) ⇒ Class
Define a parser with the given grammar and compile it into a parser class using the given options
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rattler.rb', line 29 def compile_parser(*args) = @@defaults.dup grammar = nil for arg in args case arg when Hash then .merge!(arg) when String then grammar = arg end end base_class = .delete(:class) || (Rattler::Runtime::const_get @@parser_types[[:type]]) Rattler::Compiler.compile_parser(base_class, grammar, ) end |