Class: RParsec::OperatorTable
- Inherits:
-
Object
- Object
- RParsec::OperatorTable
- 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
Procobject with a precedence associated. Returnsself. postfix-
Defines a postfix operator that returns a unary
Procobject with a precedence associated. Returnsself. infixl-
Defines a left associative infix operator that returns a binary
Procobject with a precedence associated. Returnsself. infixr-
Defines a right associative infix operator that returns a binary
Procobject with a precedence associated. Returnsself. infixn-
Defines a non-associative infix operator that returns a binary
Procobject with a precedence associated. Returnsself.
Instance Attribute Summary collapse
-
#operators ⇒ Object
readonly
Operator attributes.
Instance Method Summary collapse
-
#initialize ⇒ OperatorTable
constructor
To create an OperatorTable instance.
Constructor Details
#initialize ⇒ OperatorTable
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
#operators ⇒ Object (readonly)
Operator attributes.
29 30 31 |
# File 'lib/rparsec/operator_table.rb', line 29 def operators @operators end |