Class: Jade::Frontend::FixityFixer::Fixity

Inherits:
Data
  • Object
show all
Defined in:
lib/jade/frontend/fixity_fixer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assocObject (readonly)

Returns the value of attribute assoc

Returns:

  • (Object)

    the current value of assoc



17
18
19
# File 'lib/jade/frontend/fixity_fixer.rb', line 17

def assoc
  @assoc
end

#precedenceObject (readonly)

Returns the value of attribute precedence

Returns:

  • (Object)

    the current value of 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