Class: Dommy::Internal::CSS::CalcParser
- Inherits:
-
Object
- Object
- Dommy::Internal::CSS::CalcParser
- Defined in:
- lib/dommy/internal/css/calc.rb
Overview
Recursive-descent evaluator over calc_tokenize's output. Values are [kind, number] where kind is :length (px) or :number. Operators follow CSS Values 4 calc unit algebra: +/- need matching kinds, * needs a number operand, / needs a number divisor.
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(tokens, ctx) ⇒ CalcParser
constructor
A new instance of CalcParser.
-
#parse_value ⇒ Object
= | ( ) | [+-] | .
Constructor Details
#initialize(tokens, ctx) ⇒ CalcParser
Returns a new instance of CalcParser.
98 99 100 101 102 |
# File 'lib/dommy/internal/css/calc.rb', line 98 def initialize(tokens, ctx) @tokens = tokens @ctx = ctx @pos = 0 end |
Instance Method Details
#done? ⇒ Boolean
104 |
# File 'lib/dommy/internal/css/calc.rb', line 104 def done? = @pos >= @tokens.length |
#parse_value ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dommy/internal/css/calc.rb', line 107 def parse_value token = peek if token.is_a?(Hash) && token[:fn] parse_function elsif token == "(" advance value = parse_sum expect(")") value elsif token == "+" || token == "-" advance kind, number = parse_value [kind, token == "-" ? -number : number] elsif token.is_a?(Hash) && token[:num] advance dimension(token) else raise PropertyRegistry::CalcUnresolvable end end |