Class: Jade::Frontend::FixityFixer::Fixity
- Inherits:
-
Data
- Object
- Data
- Jade::Frontend::FixityFixer::Fixity
- Defined in:
- lib/jade/frontend/fixity_fixer.rb
Instance Attribute Summary collapse
-
#assoc ⇒ Object
readonly
Returns the value of attribute assoc.
-
#precedence ⇒ Object
readonly
Returns the value of attribute precedence.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare the rank of two operators for shunting-yard purposes Returns: - negative if self has lower rank - zero if self and other are equal rank - positive if self has higher rank.
Instance Attribute Details
#assoc ⇒ Object (readonly)
Returns the value of attribute assoc
17 18 19 |
# File 'lib/jade/frontend/fixity_fixer.rb', line 17 def assoc @assoc end |
#precedence ⇒ Object (readonly)
Returns the value of attribute precedence
17 18 19 |
# File 'lib/jade/frontend/fixity_fixer.rb', line 17 def precedence @precedence end |
Instance Method Details
#<=>(other) ⇒ Object
Compare the rank of two operators for shunting-yard purposes Returns:
- negative if self has lower rank
- zero if self and other are equal rank
- positive if self has higher rank
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jade/frontend/fixity_fixer.rb', line 23 def <=>(other) # rank by precedence first prec_cmp = precedence <=> other.precedence return prec_cmp unless prec_cmp.zero? # same precedence → rank by associativity case assoc when :left 0 # equal rank: left-assoc when :right 1 # higher rank: right-assoc when :none raise "Non-associative operator cannot be chained" end end |