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 = nil, &block) ⇒ Object
Define a parser with the given block and compile it into match methods in the given module.
-
#compile_parser(*args, &block) ⇒ Class
Define a parser with the given block and compile it into a parser class using the given options.
-
#define_rules(&block) ⇒ Rattler::Parsers::Rules
Define parse rules with the given block.
Instance Method Details
#compile(mod, grammar = nil, &block) ⇒ Object
Define a parser with the given block and compile it into match methods in the given module
66 67 68 69 |
# File 'lib/rattler.rb', line 66 def compile(mod, grammar=nil, &block) grammar_or_rules = grammar || Rattler::Parsers.define(&block) Rattler::BackEnd::Compiler.compile(mod, grammar_or_rules) end |
#compile_parser(*args, &block) ⇒ Class
Define a parser with the given block and compile it into a parser class using the given options
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rattler.rb', line 48 def compile_parser(*args, &block) = @@defaults grammar = nil for arg in args case arg when Hash then = .merge(arg) when String then grammar = arg end end base_class = .fetch(:class) do Rattler::Runtime::const_get @@parser_types[[:type]] end Rattler::BackEnd::Compiler.compile_parser(base_class, grammar || Rattler::Parsers.define(&block)) end |