Class: Racc::Grammar::DefinitionEnv

### Home Classes Methods

### In Files

- lib/racc/grammar.rb

### Parent

Object

### Methods

- ::new
- #_
- #_add
- #_added?
- #_delayed_add
- #_intern
- #action
- #flush_delayed
- #grammar
- #many
- #many1
- #method_missing
- #null
- #option
- #precedence_table
- #separated_by
- #separated_by1
- #seq

### Files

- Manifest.txt
- README.rdoc
- pre-setup
- NEWS.en.rdoc
- grammar.en.rdoc

### Class/Module Index

Quicksearch

- Racc
- Racc::Accept
- Racc::ActionTable
- Racc::CompileError
- Racc::DebugFlags
- Racc::Error
- Racc::Goto
- Racc::Grammar
- Racc::Grammar::DefinitionEnv
- Racc::Grammar::PrecedenceDefinitionEnv
- Racc::GrammarFileParser
- Racc::GrammarFileParser::Result
- Racc::GrammarFileScanner
- Racc::ISet
- Racc::Item
- Racc::LocationPointer
- Racc::LogFileGenerator
- Racc::OrMark
- Racc::ParseError
- Racc::ParseError
- Racc::Parser
- Racc::ParserClassGenerator
- Racc::ParserFileGenerator
- Racc::ParserFileGenerator::Params
- Racc::Prec
- Racc::RRconflict
- Racc::Reduce
- Racc::Rule
- Racc::SRconflict
- Racc::Shift
- Racc::SourceText
- Racc::State
- Racc::StateTransitionTable
- Racc::StateTransitionTableGenerator
- Racc::States
- Racc::Sym
- Racc::SymbolTable
- Racc::UserAction
- Object
- Object::ParseError
- Array

No matching classes.

# Racc::Grammar::DefinitionEnv

### Public Class Methods

new() click to toggle source

    # File lib/racc/grammar.rb, line 205
    def initialize
      @grammar = Grammar.new
      @seqs = Hash.new(0)
      @delayed = []
    end

### Public Instance Methods

_(&block) click to toggle source
Alias for: action
_add(target, x) click to toggle source

    # File lib/racc/grammar.rb, line 239
    def _add(target, x)
      case x
      when Sym
        @delayed.each do |rule|
          rule.replace x, target if rule.target == x
        end
        @grammar.symboltable.delete x
      else
        x.each_rule do |r|
          r.target = target
          @grammar.add r
        end
      end
      flush_delayed
    end

_added?(sym) click to toggle source

    # File lib/racc/grammar.rb, line 259
    def _added?(sym)
      @grammar.added?(sym) or @delayed.detect {|r| r.target == sym }
    end

_delayed_add(rule) click to toggle source

    # File lib/racc/grammar.rb, line 255
    def _delayed_add(rule)
      @delayed.push rule
    end

_intern(x) click to toggle source

    # File lib/racc/grammar.rb, line 318
    def _intern(x)
      case x
      when Symbol, String
        @grammar.intern(x)
      when Racc::Sym
        x
      else
        raise TypeError, "wrong type #{x.class} (expected Symbol/String/Racc::Sym)"
      end
    end

action(&block) click to toggle source

    # File lib/racc/grammar.rb, line 279
    def action(&block)
      id = "@#{@seqs["action"] += 1}".intern
      _delayed_add Rule.new(@grammar.intern(id), [], UserAction.proc(block))
      id
    end

Also aliased as: _
flush_delayed() click to toggle source

    # File lib/racc/grammar.rb, line 263
    def flush_delayed
      return if @delayed.empty?
      @delayed.each do |rule|
        @grammar.add rule
      end
      @delayed.clear
    end

grammar() click to toggle source

    # File lib/racc/grammar.rb, line 211
    def grammar
      flush_delayed
      @grammar.each do |rule|
        if rule.specified_prec
          rule.specified_prec = @grammar.intern(rule.specified_prec)
        end
      end
      @grammar.init
      @grammar
    end

many(sym, &block) click to toggle source

    # File lib/racc/grammar.rb, line 293
    def many(sym, &block)
      _defmetasyntax("many", _intern(sym), block) {|target|
          seq() { [] }           | seq(target, sym) {|list, x| list.push x; list }
      }
    end

many1(sym, &block) click to toggle source

    # File lib/racc/grammar.rb, line 300
    def many1(sym, &block)
      _defmetasyntax("many1", _intern(sym), block) {|target|
          seq(sym) {|x| [x] }           | seq(target, sym) {|list, x| list.push x; list }
      }
    end

method_missing(mid, *args, &block) click to toggle source

    # File lib/racc/grammar.rb, line 228
    def method_missing(mid, *args, &block)
      unless mid.to_s[-1,1] == '='
        super   # raises NoMethodError
      end
      target = @grammar.intern(mid.to_s.chop.intern)
      unless args.size == 1
        raise ArgumentError, "too many arguments for #{mid} (#{args.size} for 1)"
      end
      _add target, args.first
    end

null(&block) click to toggle source

    # File lib/racc/grammar.rb, line 275
    def null(&block)
      seq(&block)
    end

option(sym, default = nil, &block) click to toggle source

    # File lib/racc/grammar.rb, line 287
    def option(sym, default = nil, &block)
      _defmetasyntax("option", _intern(sym), block) {|target|
        seq() { default } | seq(sym)
      }
    end

precedence_table(&block) click to toggle source

    # File lib/racc/grammar.rb, line 222
    def precedence_table(&block)
      env = PrecedenceDefinitionEnv.new(@grammar)
      env.instance_eval(&block)
      @grammar.end_precedence_declaration env.reverse
    end

separated_by(sep, sym, &block) click to toggle source

    # File lib/racc/grammar.rb, line 307
    def separated_by(sep, sym, &block)
      option(separated_by1(sep, sym), [], &block)
    end

separated_by1(sep, sym, &block) click to toggle source

    # File lib/racc/grammar.rb, line 311
    def separated_by1(sep, sym, &block)
      _defmetasyntax("separated_by1", _intern(sym), block) {|target|
          seq(sym) {|x| [x] }           | seq(target, sep, sym) {|list, _, x| list.push x; list }
      }
    end

seq(*list, &block) click to toggle source

    # File lib/racc/grammar.rb, line 271
    def seq(*list, &block)
      Rule.new(nil, list.map {|x| _intern(x) }, UserAction.proc(block))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.