Class: Rattler::Runtime::PackratParser

Inherits:
RecursiveDescentParser show all
Defined in:
lib/rattler/runtime/packrat_parser.rb

Overview

A PackratParser is a recursive descent parser that memoizes the results of applying nonterminal rules so that each rule method is invoked at most once at a given parse position.

Author:

  • Jason Arhart

Direct Known Subclasses

ExtendedPackratParser

Defined Under Namespace

Classes: MemoEntry

Instance Attribute Summary

Attributes inherited from Parser

#source

Instance Method Summary collapse

Methods inherited from RecursiveDescentParser

#match, #method_missing, #respond_to?

Methods included from Grammar::GrammarDSL

included

Methods included from ParserHelper

#select_captures

Methods inherited from Parser

#fail, #fail!, #fail_parse, #failure, #failure?, #parse, #parse!, parse!, #parse_fully, #parse_fully!, parse_fully!, #pos, #pos=

Methods inherited from Util::Node

#==, #[], [], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #inspect, #method_missing, #name, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children

Constructor Details

#initialize(source, options = {}) ⇒ PackratParser

Create a new packrat parser to parse source.

Parameters:

  • source (String)

    the source to parse

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :tab_size (Int) — default: 8

    tab size to use to calculate column numbers



25
26
27
28
# File 'lib/rattler/runtime/packrat_parser.rb', line 25

def initialize(source, options={})
  super
  @memo = Hash.new {|h, rule_name| h[rule_name] = {} }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rattler::Runtime::RecursiveDescentParser