Class: RParsec::OperatorTable

Inherits:
Object
  • Object
show all
Defined in:
lib/rparsec/operator_table.rb

Overview

This class holds information about operator precedences and associativities. prefix, postfix, infixl, infixr, infixn can be called to register operators.

prefix

Defines a prefix operator that returns a unary Proc object with a precedence associated. Returns self.

postfix

Defines a postfix operator that returns a unary Proc object with a precedence associated. Returns self.

infixl

Defines a left associative infix operator that returns a binary Proc object with a precedence associated. Returns self.

infixr

Defines a right associative infix operator that returns a binary Proc object with a precedence associated. Returns self.

infixn

Defines a non-associative infix operator that returns a binary Proc object with a precedence associated. Returns self.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOperatorTable

To create an OperatorTable instance. If a block is given, it is invoked to do post-instantiation. For example:

OperatorTable.new do |tbl|
  tbl.infixl(char(?+) >> Plus, 10)
  tbl.infixl(char(?-) >> Minus, 10)
  tbl.infixl(char(?*) >> Mul, 20)
  tbl.infixl(char(?/) >> Div, 20)
  tbl.prefix(char(?-) >> Neg, 50)
end


43
44
45
46
# File 'lib/rparsec/operator_table.rb', line 43

def initialize
  @operators = []
  block_given? and yield self
end

Instance Attribute Details

#operatorsObject (readonly)

Operator attributes.



29
30
31
# File 'lib/rparsec/operator_table.rb', line 29

def operators
  @operators
end