Class: Luoma::GroupExpression
- Inherits:
-
Expression
- Object
- Expression
- Luoma::GroupExpression
- Defined in:
- lib/luoma/expression.rb,
sig/luoma/expression.rbs
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
- #children ⇒ Object
- #evaluate(context) ⇒ Object
-
#initialize(token, expr, segments) ⇒ GroupExpression
constructor
(t_token, Expression, Array) -> void.
-
#path(segments) ⇒ String
(Array) -> String.
- #to_s ⇒ Object
-
#with(token) ⇒ self
(t_token) -> self.
Methods inherited from Expression
Constructor Details
#initialize(token, expr, segments) ⇒ GroupExpression
(t_token, Expression, Array) -> void
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/luoma/expression.rb', line 38 def initialize(token, expr, segments) super(token) @expr = expr @segments = segments @span = if segments.empty? Luoma.span(token, expr.span) else Luoma.span(token, segments.last.token) end end |
Instance Method Details
#children ⇒ Object
70 71 72 |
# File 'lib/luoma/expression.rb', line 70 def children [@expr, *@segments.grep(Variable)] #: Array[_Traversable] end |
#evaluate(context) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/luoma/expression.rb', line 51 def evaluate(context) obj = @expr.evaluate(context) return obj if @segments.empty? obj, index = context.resolve_path(obj, @segments.map { |s| s.evaluate(context) }) if obj == :nothing context.env.undefined.new( path(@segments[0..index] || raise), @span, context.template.source, context.template.name ) else obj end end |
#path(segments) ⇒ String
(Array) -> String
87 88 89 90 91 92 93 |
# File 'lib/luoma/expression.rb', line 87 def path(segments) if segments.empty? "" else segments.map { |s| s.is_a?(Name) ? ".#{s}" : "[#{s}]" }.join end end |
#to_s ⇒ Object
80 81 82 |
# File 'lib/luoma/expression.rb', line 80 def to_s "(#{@expr})#{path(@segments)}" end |