Class: Dhaka::ProductionBuilder

### Home Classes Methods

### In Files

- lib/dhaka/grammar/grammar.rb

### Parent

Object

### Methods

- ::new
- #method_missing

### Class/Module Index

Quicksearch

- Dhaka
- Dhaka::CompiledLexer
- Dhaka::CompiledParser
- Dhaka::Evaluator
- Dhaka::Grammar
- Dhaka::GrammarSymbol
- Dhaka::Lexeme
- Dhaka::Lexer
- Dhaka::LexerRun
- Dhaka::LexerSpecification
- Dhaka::LexerSupport
- Dhaka::LexerSupport::AcceptAction
- Dhaka::LexerSupport::CheckpointAction
- Dhaka::LexerSupport::DFARun
- Dhaka::LexerSupport::InvalidRegexException
- Dhaka::LexerSupport::LookaheadAcceptAction
- Dhaka::LexerSupport::RegexParser
- Dhaka::LexerSupport::RegexTokenizer
- Dhaka::LexerSupport::State
- Dhaka::LexerSupport::StateMachine
- Dhaka::NoStartProductionsError
- Dhaka::ParseErrorResult
- Dhaka::ParseSuccessResult
- Dhaka::ParseTreeCompositeNode
- Dhaka::ParseTreeLeafNode
- Dhaka::Parser
- Dhaka::ParserMethods
- Dhaka::PrecedenceBuilder
- Dhaka::Production
- Dhaka::ProductionBuilder
- Dhaka::Token
- Dhaka::Tokenizer
- Dhaka::TokenizerErrorResult
- Dhaka::TokenizerState
- Dhaka::TokenizerSuccessResult

No matching classes.

# Dhaka::ProductionBuilder

Productions for specific grammar symbols are defined in the context of this class.

### Public Class Methods

new(grammar, symbol) click to toggle source

`symbol` is the grammar symbol that productions are being defined for.

    # File lib/dhaka/grammar/grammar.rb, line 10
    def initialize(grammar, symbol)
      @grammar = grammar
      @symbol  = symbol
    end

### Public Instance Methods

method_missing(production_name, expansion, options = {}, &blk) click to toggle source

Creates a new production for `symbol` with an expansion of `expansion`. The options hash can include a directive `:prec`, the value of which is a grammar symbol name. The precedence of the production is then set to the precedence of the grammar symbol corresponding to that name.

See the arithmetic precedence grammar in the test suites for an example.

    # File lib/dhaka/grammar/grammar.rb, line 20
    def method_missing(production_name, expansion, options = {}, &blk)
      expansion_symbols = expansion.collect {|name| @grammar.symbols[name]}
      production_args   = [@symbol, expansion_symbols, production_name.to_s, blk, @grammar.production_index]
      if precedence_symbol_name = options[:prec]
        production_args << @grammar.symbol_for_name(precedence_symbol_name).precedence
      end

      production = Production.new(*production_args)
      @grammar.production_index += 1

      @symbol.nullable = true if expansion_symbols.empty?
      @grammar.productions_by_symbol[production.symbol] << production
      raise "Duplicate production named #{production.name}" if @grammar.productions_by_name[production.name]
      @grammar.productions_by_name[production.name] = production
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.