Class: Antelope::Ace::Precedence
- Inherits:
-
Struct
- Object
- Struct
- Antelope::Ace::Precedence
- Includes:
- Comparable
- Defined in:
- lib/antelope/ace/precedence.rb
Overview
Defines a precedence. A precedence has a type, tokens, and a level.
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#<=>(other) ⇒ Numeric?
Compares the other object to this object.
- #to_s ⇒ Object
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level
8 9 10 |
# File 'lib/antelope/ace/precedence.rb', line 8 def level @level end |
#tokens ⇒ Object
Returns the value of attribute tokens
8 9 10 |
# File 'lib/antelope/ace/precedence.rb', line 8 def tokens @tokens end |
#type ⇒ Object
Returns the value of attribute type
8 9 10 |
# File 'lib/antelope/ace/precedence.rb', line 8 def type @type end |
Instance Method Details
#<=>(other) ⇒ Numeric?
Compares the other object to this object. If the other object isn't a Antelope::Ace::Precedence, it returns nil. If the other precedence isn't on the same level as this one, then the levels are compared and the result of that is returned. If it is, however, the type is checked; if this precedence is left associative, then it returns 1 (it is greater than the other); if this precedence is right associative, then it returns -1 (it is less than the other); if this precedence is nonassociative, it returns 0 (it is equal to the other).
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/antelope/ace/precedence.rb', line 39 def <=>(other) return nil unless other.is_a? Precedence if level != other.level level <=> other.level elsif type == :left 1 elsif type == :right -1 else 0 end end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/antelope/ace/precedence.rb', line 52 def to_s "#{type.to_s[0]}#{level}" end |