Module: RDF::LL1::Parser::ClassMethods

Defined in:
lib/ebnf/ll1/parser.rb

Overview

DSL for creating terminals and productions

Instance Method Summary collapse

Instance Method Details

#patternsObject



26
# File 'lib/ebnf/ll1/parser.rb', line 26

def patterns; @@patterns || []; end

#production(term) {|reader, phase, input, current| ... } ⇒ Object

Defines a production called during different phases of parsing with data from previous production along with data defined for the current production

Yield to generate a triple

Parameters:

  • term (Symbol)

    Term which is a key in the branch table

Yields:

  • (reader, phase, input, current)

Yield Parameters:

  • reader (RDF::Reader)

    Reader instance

  • phase (Symbol)

    Phase of parsing, one of :start, or :finish

  • input (Hash)

    A Hash containing input from the parent production

  • current (Hash)

    A Hash defined for the current production, during :start may be initialized with data to pass to further productions, during :finish, it contains data placed by earlier productions

  • block (Prod)

    Block passed to initialization for yielding to calling reader. Should conform to the yield specs for #initialize



51
52
53
54
# File 'lib/ebnf/ll1/parser.rb', line 51

def production(term, &block)
  @@production_handlers ||= {}
  @@production_handlers[term] = block
end

#production_handlersObject



24
# File 'lib/ebnf/ll1/parser.rb', line 24

def production_handlers; @@production_handlers || {}; end

#terminal(term, regexp, options = {}) {|reader, term, token, input| ... } ⇒ Object

Defines the pattern for a terminal node and a block to be invoked when ther terminal is encountered. If the block is missing, the value of the terminal will be placed on the input hash to be returned to a previous production.

Parameters:

  • term (Symbol, String)

    Defines a terminal production, which appears as within a sequence in the branch table

  • regexp (Regexp)

    Pattern used to scan for this terminal

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

Options Hash (options):

  • :unescape (Boolean)

    Cause strings and codepoints to be unescaped.

Yields:

  • (reader, term, token, input)

Yield Parameters:

  • reader (RDF::Reader)

    Reader instance

  • term (Symbol)

    A symbol indicating the production which referenced this terminal

  • token (String)

    The scanned token

  • input (Hash)

    A Hash containing input from the parent production

  • block (Prod)

    Block passed to initialization for yielding to calling reader. Should conform to the yield specs for #initialize



81
82
83
84
85
86
87
88
# File 'lib/ebnf/ll1/parser.rb', line 81

def terminal(term, regexp, options = {}, &block)
  @@patterns ||= []
  @@patterns << [term, regexp]  # Passed in order to define evaulation sequence
  @@terminal_handlers ||= {}
  @@terminal_handlers[term] = block if block_given?
  @@unescape_terms ||= []
  @@unescape_terms << term if options[:unescape]
end

#terminal_handlersObject



25
# File 'lib/ebnf/ll1/parser.rb', line 25

def terminal_handlers; @@terminal_handlers || {}; end

#unescape_termsObject



27
# File 'lib/ebnf/ll1/parser.rb', line 27

def unescape_terms; @@unescape_terms || []; end