Class: RParsec::OperatorTable
- Inherits:
-
Object
- Object
- RParsec::OperatorTable
- Defined in:
- lib/rparsec/expressions.rb
Overview
to register operators.
Instance Attribute Summary collapse
-
#operators ⇒ Object
readonly
operators attribute is used internally.
Class Method Summary collapse
-
.new ⇒ Object
To create an OperatorTable instance.
Instance Method Summary collapse
-
#infixl(op, precedence) ⇒ Object
Defines a left associative infix operator that returns a binary Proc object with a precedence associated.
-
#infixn(op, precedence) ⇒ Object
Defines a non-associative infix operator that returns a binary Proc object with a precedence associated.
-
#infixr(op, precedence) ⇒ Object
Defines a right associative infix operator that returns a binary Proc object with a precedence associated.
-
#postfix(op, precedence) ⇒ Object
Defines a postfix operator that returns a unary Proc object with a precedence associated.
-
#prefix(op, precedence) ⇒ Object
Defines a prefix operator that returns a unary Proc object with a precedence associated.
-
#reinit ⇒ Object
Re-initialize the operator table.
Instance Attribute Details
#operators ⇒ Object (readonly)
operators attribute is used internally. Do not access it.
16 17 18 |
# File 'lib/rparsec/expressions.rb', line 16 def operators @operators end |
Class Method Details
.new ⇒ Object
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
38 39 40 41 42 43 44 45 |
# File 'lib/rparsec/expressions.rb', line 38 def self.new this = allocate this.reinit if block_given? yield this end this end |
Instance Method Details
#infixl(op, precedence) ⇒ Object
Defines a left associative infix operator that returns a binary Proc object with a precedence associated. Returns self.
67 68 69 |
# File 'lib/rparsec/expressions.rb', line 67 def infixl(op, precedence) add(:infixl, op, precedence) end |
#infixn(op, precedence) ⇒ Object
Defines a non-associative infix operator that returns a binary Proc object with a precedence associated. Returns self.
83 84 85 |
# File 'lib/rparsec/expressions.rb', line 83 def infixn(op, precedence) add(:infixn, op, precedence) end |
#infixr(op, precedence) ⇒ Object
Defines a right associative infix operator that returns a binary Proc object with a precedence associated. Returns self.
75 76 77 |
# File 'lib/rparsec/expressions.rb', line 75 def infixr(op, precedence) add(:infixr, op, precedence) end |
#postfix(op, precedence) ⇒ Object
Defines a postfix operator that returns a unary Proc object with a precedence associated. Returns self.
59 60 61 |
# File 'lib/rparsec/expressions.rb', line 59 def postfix(op, precedence) add(:postfix, op, precedence) end |
#prefix(op, precedence) ⇒ Object
Defines a prefix operator that returns a unary Proc object with a precedence associated. Returns self.
51 52 53 |
# File 'lib/rparsec/expressions.rb', line 51 def prefix(op, precedence) add(:prefix, op, precedence) end |
#reinit ⇒ Object
Re-initialize the operator table. Internal use only.
21 22 23 |
# File 'lib/rparsec/expressions.rb', line 21 def reinit @operators = [] end |