liquid2 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +5 -1
- data/lib/liquid2/environment.rb +6 -1
- data/lib/liquid2/expressions/arithmetic.rb +123 -0
- data/lib/liquid2/expressions/lambda.rb +2 -0
- data/lib/liquid2/expressions/relational.rb +1 -1
- data/lib/liquid2/nodes/tags/raw.rb +2 -1
- data/lib/liquid2/parser.rb +86 -15
- data/lib/liquid2/scanner.rb +9 -2
- data/lib/liquid2/undefined.rb +11 -1
- data/lib/liquid2/version.rb +1 -1
- data/sig/liquid2.rbs +97 -12
- data.tar.gz.sig +0 -0
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42973b8aae08cf4321586ac4cdaf39ecab29e0a2a4b7f26aed278291e41b7645
|
4
|
+
data.tar.gz: 9c2bca82b7f589cfdccd4a2a5c091ac3cd32613e0c40354b6313d23a6c35bbec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbb3917b6b68ba37aaffbf158aac61d85a577ddf244b12fdad9eaa99e5ea54a0f94b255b3d21381514bb42bbb7c3543c247b7bba38255e95dacc195aedf2f10a
|
7
|
+
data.tar.gz: a61fd0b11ff0d4ed92bdcd1b8eca60b5997f6881caad131132256f561a0c039cdc33e758601b7dd9da0e02534f53c21a38da6c09e38bc947a4a93834a0413210
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.3.0] - 25-05-29
|
2
|
+
|
3
|
+
- Fixed static analysis of lambda expressions (arrow functions). Previously we were not including lambda parameters in the scope of the expression. See [#12](https://github.com/jg-rp/ruby-liquid2/issues/12).
|
4
|
+
- Fixed parsing of variable paths that start with `true`, `false`, `nil` or `null`. For example, `{{ true.foo }}`. See [#13](https://github.com/jg-rp/ruby-liquid2/issues/13).
|
5
|
+
- Added support for arithmetic infix operators `+`, `-`, `*`, `/`, `%` and `**`, and prefix operators `+` and `-`. These operators are disabled by default. Enable them by passing `arithmetic_operators: true` to a new `Liquid2::Environment`.
|
6
|
+
|
1
7
|
## [0.2.0] - 25-05-12
|
2
8
|
|
3
9
|
- Fixed error context info when raising `UndefinedError` from `StrictUndefined`.
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Liquid templates for Ruby, with some extra features.
|
|
36
36
|
Add `'liquid2'` to your Gemfile:
|
37
37
|
|
38
38
|
```
|
39
|
-
gem 'liquid2', '~> 0.
|
39
|
+
gem 'liquid2', '~> 0.3.0'
|
40
40
|
```
|
41
41
|
|
42
42
|
Or
|
@@ -219,6 +219,10 @@ Here we use `~` to remove the newline after the opening `for` tag, but preserve
|
|
219
219
|
</ul>
|
220
220
|
```
|
221
221
|
|
222
|
+
#### Arithmetic operators
|
223
|
+
|
224
|
+
Arithmetic infix operators `+`, `-`, `*`, `/`, `%` and `**`, and prefix operators `+` and `-`, are an experimental feature and are disabled by default. Enable them by passing `arithmetic_operators: true` to a new [`Liquid2::Environment`](https://github.com/jg-rp/ruby-liquid2/blob/main/lib/liquid2/environment.rb).
|
225
|
+
|
222
226
|
#### Scientific notation
|
223
227
|
|
224
228
|
Integer and float literals can use scientific notation, like `1.2e3` or `1e-2`.
|
data/lib/liquid2/environment.rb
CHANGED
@@ -45,7 +45,7 @@ module Liquid2
|
|
45
45
|
class Environment
|
46
46
|
attr_reader :tags, :local_namespace_limit, :context_depth_limit, :loop_iteration_limit,
|
47
47
|
:output_stream_limit, :filters, :suppress_blank_control_flow_blocks,
|
48
|
-
:shorthand_indexes, :falsy_undefined
|
48
|
+
:shorthand_indexes, :falsy_undefined, :arithmetic_operators
|
49
49
|
|
50
50
|
# @param context_depth_limit [Integer] The maximum number of times a render context can
|
51
51
|
# be extended or copied before a `Liquid2::LiquidResourceLimitError`` is raised.
|
@@ -68,6 +68,7 @@ module Liquid2
|
|
68
68
|
# @param undefined [singleton(Liquid2::Undefined)] A singleton returning an instance of
|
69
69
|
# `Liquid2::Undefined`, which is used to represent template variables that don't exist.
|
70
70
|
def initialize(
|
71
|
+
arithmetic_operators: false,
|
71
72
|
context_depth_limit: 30,
|
72
73
|
globals: nil,
|
73
74
|
loader: nil,
|
@@ -87,6 +88,10 @@ module Liquid2
|
|
87
88
|
# keyword argument.
|
88
89
|
@filters = {}
|
89
90
|
|
91
|
+
# When `true`, arithmetic operators `+`, `-`, `*`, `/`, `%` and `**` are enabled.
|
92
|
+
# Defaults to `false`.
|
93
|
+
@arithmetic_operators = arithmetic_operators
|
94
|
+
|
90
95
|
# The maximum number of times a render context can be extended or copied before
|
91
96
|
# a Liquid2::LiquidResourceLimitError is raised.
|
92
97
|
@context_depth_limit = context_depth_limit
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "blank"
|
4
|
+
require_relative "../expression"
|
5
|
+
|
6
|
+
module Liquid2 # :nodoc:
|
7
|
+
# Base class for all arithmetic expressions.
|
8
|
+
class ArithmeticExpression < Expression
|
9
|
+
# @param left [Expression]
|
10
|
+
# @param right [Expression]
|
11
|
+
def initialize(token, left, right)
|
12
|
+
super(token)
|
13
|
+
@left = left
|
14
|
+
@right = right
|
15
|
+
end
|
16
|
+
|
17
|
+
def children = [@left, @right]
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def inner_evaluate(context)
|
22
|
+
left = context.evaluate(@left)
|
23
|
+
right = context.evaluate(@right)
|
24
|
+
left = left.to_liquid(context) if left.respond_to?(:to_liquid)
|
25
|
+
right = right.to_liquid(context) if right.respond_to?(:to_liquid)
|
26
|
+
[Liquid2::Filters.to_decimal(left), Liquid2::Filters.to_decimal(right)]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Infix addition
|
31
|
+
class Plus < ArithmeticExpression
|
32
|
+
def evaluate(context)
|
33
|
+
left, right = inner_evaluate(context)
|
34
|
+
left + right
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Infix subtraction
|
39
|
+
class Minus < ArithmeticExpression
|
40
|
+
def evaluate(context)
|
41
|
+
left, right = inner_evaluate(context)
|
42
|
+
left - right
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Infix multiplication
|
47
|
+
class Times < ArithmeticExpression
|
48
|
+
def evaluate(context)
|
49
|
+
left, right = inner_evaluate(context)
|
50
|
+
left * right
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Infix division
|
55
|
+
class Divide < ArithmeticExpression
|
56
|
+
def evaluate(context)
|
57
|
+
left, right = inner_evaluate(context)
|
58
|
+
left / right
|
59
|
+
rescue ZeroDivisionError => e
|
60
|
+
raise LiquidTypeError.new(e.message, nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Infix modulo
|
65
|
+
class Modulo < ArithmeticExpression
|
66
|
+
def evaluate(context)
|
67
|
+
left, right = inner_evaluate(context)
|
68
|
+
left % right
|
69
|
+
rescue ZeroDivisionError => e
|
70
|
+
raise LiquidTypeError.new(e.message, nil)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Infix exponentiation
|
75
|
+
class Pow < ArithmeticExpression
|
76
|
+
def evaluate(context)
|
77
|
+
left, right = inner_evaluate(context)
|
78
|
+
left**right
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Prefix negation
|
83
|
+
class Negative < Expression
|
84
|
+
# @param right [Expression]
|
85
|
+
def initialize(token, right)
|
86
|
+
super(token)
|
87
|
+
@right = right
|
88
|
+
end
|
89
|
+
|
90
|
+
def evaluate(context)
|
91
|
+
right = context.evaluate(@right)
|
92
|
+
value = Liquid2::Filters.to_decimal(right,
|
93
|
+
default: nil) || context.env.undefined(
|
94
|
+
"-(#{Liquid2.to_output_string(right)})",
|
95
|
+
node: self
|
96
|
+
)
|
97
|
+
value.send(:-@)
|
98
|
+
end
|
99
|
+
|
100
|
+
def children = [@right]
|
101
|
+
end
|
102
|
+
|
103
|
+
# Prefix positive
|
104
|
+
class Positive < Expression
|
105
|
+
# @param right [Expression]
|
106
|
+
def initialize(token, right)
|
107
|
+
super(token)
|
108
|
+
@right = right
|
109
|
+
end
|
110
|
+
|
111
|
+
def evaluate(context)
|
112
|
+
right = context.evaluate(@right)
|
113
|
+
value = Liquid2::Filters.to_decimal(right,
|
114
|
+
default: nil) || context.env.undefined(
|
115
|
+
"+(#{Liquid2.to_output_string(right)})",
|
116
|
+
node: self
|
117
|
+
)
|
118
|
+
value.send(:+@)
|
119
|
+
end
|
120
|
+
|
121
|
+
def children = [@right]
|
122
|
+
end
|
123
|
+
end
|
@@ -4,7 +4,7 @@ require_relative "blank"
|
|
4
4
|
require_relative "../expression"
|
5
5
|
|
6
6
|
module Liquid2 # :nodoc:
|
7
|
-
# Base for comparison expressions.
|
7
|
+
# Base class for all comparison expressions.
|
8
8
|
class ComparisonExpression < Expression
|
9
9
|
# @param left [Expression]
|
10
10
|
# @param right [Expression]
|
@@ -10,7 +10,8 @@ module Liquid2
|
|
10
10
|
def self.parse(token, parser)
|
11
11
|
parser.carry_whitespace_control
|
12
12
|
parser.eat(:token_tag_end)
|
13
|
-
# TODO: apply whitespace control to raw text
|
13
|
+
# TODO: apply whitespace control to raw text?
|
14
|
+
# Shopify/liquid does not apply whitespace control to raw content.
|
14
15
|
raw = parser.eat(:token_raw)
|
15
16
|
parser.eat_empty_tag("endraw")
|
16
17
|
new(token, raw[1] || raise)
|
data/lib/liquid2/parser.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative "node"
|
|
7
7
|
require_relative "nodes/comment"
|
8
8
|
require_relative "nodes/output"
|
9
9
|
require_relative "expressions/arguments"
|
10
|
+
require_relative "expressions/arithmetic"
|
10
11
|
require_relative "expressions/array"
|
11
12
|
require_relative "expressions/blank"
|
12
13
|
require_relative "expressions/boolean"
|
@@ -336,14 +337,26 @@ module Liquid2
|
|
336
337
|
|
337
338
|
left = case kind
|
338
339
|
when :token_true
|
339
|
-
|
340
|
-
|
340
|
+
if looks_like_a_path
|
341
|
+
parse_path
|
342
|
+
else
|
343
|
+
self.next
|
344
|
+
true
|
345
|
+
end
|
341
346
|
when :token_false
|
342
|
-
|
343
|
-
|
347
|
+
if looks_like_a_path
|
348
|
+
parse_path
|
349
|
+
else
|
350
|
+
self.next
|
351
|
+
false
|
352
|
+
end
|
344
353
|
when :token_nil
|
345
|
-
|
346
|
-
|
354
|
+
if looks_like_a_path
|
355
|
+
parse_path
|
356
|
+
else
|
357
|
+
self.next
|
358
|
+
nil
|
359
|
+
end
|
347
360
|
when :token_int
|
348
361
|
Liquid2.to_liquid_int(self.next[1])
|
349
362
|
when :token_float
|
@@ -358,7 +371,7 @@ module Liquid2
|
|
358
371
|
parse_path
|
359
372
|
when :token_lparen
|
360
373
|
parse_range_lambda_or_grouped_expression
|
361
|
-
when :token_not
|
374
|
+
when :token_not, :token_plus, :token_minus
|
362
375
|
parse_prefix_expression
|
363
376
|
else
|
364
377
|
unless looks_like_a_path && RESERVED_WORDS.include?(kind)
|
@@ -535,7 +548,10 @@ module Liquid2
|
|
535
548
|
LOGICAL_AND = 4
|
536
549
|
RELATIONAL = 5
|
537
550
|
MEMBERSHIP = 6
|
538
|
-
|
551
|
+
ADD_SUB = 8
|
552
|
+
MUL_DIV = 9
|
553
|
+
POW = 10
|
554
|
+
PREFIX = 11
|
539
555
|
end
|
540
556
|
|
541
557
|
PRECEDENCES = {
|
@@ -551,7 +567,14 @@ module Liquid2
|
|
551
567
|
token_ne: Precedence::RELATIONAL,
|
552
568
|
token_lg: Precedence::RELATIONAL,
|
553
569
|
token_le: Precedence::RELATIONAL,
|
554
|
-
token_ge: Precedence::RELATIONAL
|
570
|
+
token_ge: Precedence::RELATIONAL,
|
571
|
+
token_plus: Precedence::ADD_SUB,
|
572
|
+
token_minus: Precedence::ADD_SUB,
|
573
|
+
token_times: Precedence::MUL_DIV,
|
574
|
+
token_divide: Precedence::MUL_DIV,
|
575
|
+
token_floor_div: Precedence::MUL_DIV,
|
576
|
+
token_mod: Precedence::MUL_DIV,
|
577
|
+
token_pow: Precedence::POW
|
555
578
|
}.freeze
|
556
579
|
|
557
580
|
BINARY_OPERATORS = Set[
|
@@ -565,7 +588,14 @@ module Liquid2
|
|
565
588
|
:token_contains,
|
566
589
|
:token_in,
|
567
590
|
:token_and,
|
568
|
-
:token_or
|
591
|
+
:token_or,
|
592
|
+
:token_plus,
|
593
|
+
:token_minus,
|
594
|
+
:token_times,
|
595
|
+
:token_divide,
|
596
|
+
:token_floor_div,
|
597
|
+
:token_mod,
|
598
|
+
:token_pow
|
569
599
|
]
|
570
600
|
|
571
601
|
TERMINATE_EXPRESSION = Set[
|
@@ -803,14 +833,35 @@ module Liquid2
|
|
803
833
|
end
|
804
834
|
|
805
835
|
eat(:token_rparen)
|
806
|
-
|
836
|
+
expr
|
807
837
|
end
|
808
838
|
|
809
839
|
# @return [Node]
|
810
840
|
def parse_prefix_expression
|
811
|
-
|
812
|
-
|
813
|
-
|
841
|
+
case current_kind
|
842
|
+
when :token_not
|
843
|
+
token = self.next
|
844
|
+
expr = parse_primary(precedence: Precedence::PREFIX)
|
845
|
+
LogicalNot.new(token, expr)
|
846
|
+
when :token_plus
|
847
|
+
token = self.next
|
848
|
+
unless @env.arithmetic_operators
|
849
|
+
raise LiquidSyntaxError.new("unexpected prefix operator +",
|
850
|
+
token)
|
851
|
+
end
|
852
|
+
|
853
|
+
Positive.new(token, parse_primary(precedence: Precedence::PREFIX))
|
854
|
+
when :token_minus
|
855
|
+
token = self.next
|
856
|
+
unless @env.arithmetic_operators
|
857
|
+
raise LiquidSyntaxError.new("unexpected prefix operator -",
|
858
|
+
token)
|
859
|
+
end
|
860
|
+
|
861
|
+
Negative.new(token, parse_primary(precedence: Precedence::PREFIX))
|
862
|
+
else
|
863
|
+
raise LiquidSyntaxError.new("unexpected prefix operator #{current[1]}", current)
|
864
|
+
end
|
814
865
|
end
|
815
866
|
|
816
867
|
# @param left [Expression]
|
@@ -842,7 +893,27 @@ module Liquid2
|
|
842
893
|
when :token_or
|
843
894
|
LogicalOr.new(op_token, left, right)
|
844
895
|
else
|
845
|
-
|
896
|
+
unless @env.arithmetic_operators
|
897
|
+
raise LiquidSyntaxError.new("unexpected infix operator, #{op_token[1]}",
|
898
|
+
op_token)
|
899
|
+
end
|
900
|
+
|
901
|
+
case op_token.first
|
902
|
+
when :token_plus
|
903
|
+
Plus.new(op_token, left, right)
|
904
|
+
when :token_minus
|
905
|
+
Minus.new(op_token, left, right)
|
906
|
+
when :token_times
|
907
|
+
Times.new(op_token, left, right)
|
908
|
+
when :token_divide
|
909
|
+
Divide.new(op_token, left, right)
|
910
|
+
when :token_mod
|
911
|
+
Modulo.new(op_token, left, right)
|
912
|
+
when :token_pow
|
913
|
+
Pow.new(op_token, left, right)
|
914
|
+
else
|
915
|
+
raise LiquidSyntaxError.new("unexpected infix operator, #{op_token[1]}", op_token)
|
916
|
+
end
|
846
917
|
end
|
847
918
|
end
|
848
919
|
|
data/lib/liquid2/scanner.rb
CHANGED
@@ -16,7 +16,7 @@ module Liquid2
|
|
16
16
|
RE_WORD = /[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/
|
17
17
|
RE_INT = /-?\d+(?:[eE]\+?\d+)?/
|
18
18
|
RE_FLOAT = /((?:-?\d+\.\d+(?:[eE][+-]?\d+)?)|(-?\d+[eE]-\d+))/
|
19
|
-
RE_PUNCTUATION =
|
19
|
+
RE_PUNCTUATION = %r{\?|\[|\]|\|{1,2}|\.{1,2}|,|:|\(|\)|[<>=!]+|[+\-%*/]+(?![\}%])}
|
20
20
|
RE_SINGLE_QUOTE_STRING_SPECIAL = /[\\'\$]/
|
21
21
|
RE_DOUBLE_QUOTE_STRING_SPECIAL = /[\\"\$]/
|
22
22
|
|
@@ -58,7 +58,14 @@ module Liquid2
|
|
58
58
|
">=" => :token_ge,
|
59
59
|
"==" => :token_eq,
|
60
60
|
"!=" => :token_ne,
|
61
|
-
"=>" => :token_arrow
|
61
|
+
"=>" => :token_arrow,
|
62
|
+
"+" => :token_plus,
|
63
|
+
"-" => :token_minus,
|
64
|
+
"%" => :token_mod,
|
65
|
+
"*" => :token_times,
|
66
|
+
"/" => :token_divide,
|
67
|
+
"//" => :token_floor_div,
|
68
|
+
"**" => :token_pow
|
62
69
|
}.freeze
|
63
70
|
|
64
71
|
def self.tokenize(source, scanner)
|
data/lib/liquid2/undefined.rb
CHANGED
@@ -28,6 +28,8 @@ module Liquid2
|
|
28
28
|
def to_s = ""
|
29
29
|
def to_i = 0
|
30
30
|
def to_f = 0.0
|
31
|
+
def -@ = self
|
32
|
+
def +@ = self
|
31
33
|
def each(...) = Enumerator.new {} # rubocop:disable Lint/EmptyBlock
|
32
34
|
def each_with_index(...) = Enumerator.new {} # rubocop:disable Lint/EmptyBlock
|
33
35
|
def join(...) = ""
|
@@ -102,6 +104,14 @@ module Liquid2
|
|
102
104
|
raise UndefinedError.new(@message, @node.token)
|
103
105
|
end
|
104
106
|
|
107
|
+
def +@
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
def -@
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
105
115
|
def each(...)
|
106
116
|
raise UndefinedError.new(@message, @node.token)
|
107
117
|
end
|
@@ -115,7 +125,7 @@ module Liquid2
|
|
115
125
|
end
|
116
126
|
|
117
127
|
def to_liquid(_context)
|
118
|
-
|
128
|
+
self
|
119
129
|
end
|
120
130
|
|
121
131
|
def poke
|
data/lib/liquid2/version.rb
CHANGED
data/sig/liquid2.rbs
CHANGED
@@ -84,6 +84,8 @@ module Liquid2
|
|
84
84
|
|
85
85
|
@scanner: StringScanner
|
86
86
|
|
87
|
+
@arithmetic_operators: bool
|
88
|
+
|
87
89
|
attr_reader tags: Hash[String, _Tag]
|
88
90
|
|
89
91
|
attr_reader local_namespace_limit: Integer?
|
@@ -102,6 +104,8 @@ module Liquid2
|
|
102
104
|
|
103
105
|
attr_reader falsy_undefined: bool
|
104
106
|
|
107
|
+
attr_reader arithmetic_operators: bool
|
108
|
+
|
105
109
|
def initialize: (?context_depth_limit: ::Integer, ?globals: Hash[String, untyped]?, ?loader: TemplateLoader?, ?local_namespace_limit: Integer?, ?loop_iteration_limit: Integer?, ?output_stream_limit: Integer?, ?shorthand_indexes: bool, ?suppress_blank_control_flow_blocks: bool, ?undefined: singleton(Undefined), ?falsy_undefined: bool) -> void
|
106
110
|
|
107
111
|
# @param source [String] template source text.
|
@@ -375,6 +379,12 @@ module Liquid2
|
|
375
379
|
MEMBERSHIP: 6
|
376
380
|
|
377
381
|
PREFIX: 7
|
382
|
+
|
383
|
+
ADD_SUB: 8
|
384
|
+
|
385
|
+
MUL_DIV: 9
|
386
|
+
|
387
|
+
POW: 10
|
378
388
|
end
|
379
389
|
|
380
390
|
PRECEDENCES: Hash[Symbol, Integer]
|
@@ -609,29 +619,33 @@ module Liquid2
|
|
609
619
|
|
610
620
|
def []: (*untyped) ?{ (?) -> untyped } -> self
|
611
621
|
|
612
|
-
def key?: (*untyped) ?{ (?) -> untyped } ->
|
622
|
+
def key?: (*untyped) ?{ (?) -> untyped } -> untyped
|
613
623
|
|
614
|
-
def include?: (*untyped) ?{ (?) -> untyped } ->
|
624
|
+
def include?: (*untyped) ?{ (?) -> untyped } -> untyped
|
615
625
|
|
616
|
-
def member?: (*untyped) ?{ (?) -> untyped } ->
|
626
|
+
def member?: (*untyped) ?{ (?) -> untyped } -> untyped
|
617
627
|
|
618
628
|
def fetch: (*untyped) ?{ (?) -> untyped } -> self
|
619
629
|
|
620
|
-
def !: () ->
|
630
|
+
def !: () -> untyped
|
621
631
|
|
622
632
|
def ==: (untyped other) -> untyped
|
623
633
|
|
624
634
|
alias eql? ==
|
625
635
|
|
626
|
-
def size: () ->
|
636
|
+
def size: () -> untyped
|
627
637
|
|
628
|
-
def length: () ->
|
638
|
+
def length: () -> untyped
|
629
639
|
|
630
640
|
def to_s: () -> ""
|
631
641
|
|
632
|
-
def to_i: () ->
|
642
|
+
def to_i: () -> untyped
|
643
|
+
|
644
|
+
def +@: () -> untyped
|
645
|
+
|
646
|
+
def -@: () -> untyped
|
633
647
|
|
634
|
-
def to_f: () ->
|
648
|
+
def to_f: () -> untyped
|
635
649
|
|
636
650
|
def each: (*untyped) ?{ (?) -> untyped } -> untyped
|
637
651
|
|
@@ -639,9 +653,9 @@ module Liquid2
|
|
639
653
|
|
640
654
|
def join: (*untyped) -> ""
|
641
655
|
|
642
|
-
def to_liquid: (RenderContext _context) ->
|
656
|
+
def to_liquid: (RenderContext _context) -> untyped
|
643
657
|
|
644
|
-
def poke: () ->
|
658
|
+
def poke: () -> bool
|
645
659
|
end
|
646
660
|
|
647
661
|
# An undefined type that always raises an exception.
|
@@ -679,6 +693,10 @@ module Liquid2
|
|
679
693
|
def to_s: () -> untyped
|
680
694
|
|
681
695
|
def to_i: () -> untyped
|
696
|
+
|
697
|
+
def +@: () -> untyped
|
698
|
+
|
699
|
+
def -@: () -> untyped
|
682
700
|
|
683
701
|
def to_f: () -> untyped
|
684
702
|
|
@@ -1593,7 +1611,7 @@ module Liquid2
|
|
1593
1611
|
def self.to_integer: (untyped obj) -> Integer
|
1594
1612
|
|
1595
1613
|
# Cast _obj_ to a number, favouring BigDecimal over Float.
|
1596
|
-
def self.to_decimal: (untyped obj, ?default:
|
1614
|
+
def self.to_decimal: (untyped obj, ?default: untyped) -> (Integer | BigDecimal | Numeric)
|
1597
1615
|
|
1598
1616
|
# Cast _obj_ to a date and time. Return `nil` if casting fails.
|
1599
1617
|
def self.to_date: (untyped obj) -> untyped
|
@@ -2551,4 +2569,71 @@ module Liquid2
|
|
2551
2569
|
|
2552
2570
|
def block_scope: () -> Array[Identifier]
|
2553
2571
|
end
|
2554
|
-
end
|
2572
|
+
end
|
2573
|
+
|
2574
|
+
module Liquid2
|
2575
|
+
# Base class for all arithmetic expressions.
|
2576
|
+
class ArithmeticExpression < Expression
|
2577
|
+
@left: untyped
|
2578
|
+
|
2579
|
+
@right: untyped
|
2580
|
+
|
2581
|
+
# @param left [Expression]
|
2582
|
+
# @param right [Expression]
|
2583
|
+
def initialize: ([Symbol, String?, Integer] token, untyped left, untyped right) -> void
|
2584
|
+
|
2585
|
+
def children: () -> ::Array[untyped]
|
2586
|
+
|
2587
|
+
def inner_evaluate: (untyped context) -> ::Array[untyped]
|
2588
|
+
end
|
2589
|
+
|
2590
|
+
# Infix addition
|
2591
|
+
class Plus < ArithmeticExpression
|
2592
|
+
def evaluate: (RenderContext context) -> untyped
|
2593
|
+
end
|
2594
|
+
|
2595
|
+
# Infix subtraction
|
2596
|
+
class Minus < ArithmeticExpression
|
2597
|
+
def evaluate: (RenderContext context) -> untyped
|
2598
|
+
end
|
2599
|
+
|
2600
|
+
# Infix multiplication
|
2601
|
+
class Times < ArithmeticExpression
|
2602
|
+
def evaluate: (RenderContext context) -> untyped
|
2603
|
+
end
|
2604
|
+
|
2605
|
+
# Infix division
|
2606
|
+
class Divide < ArithmeticExpression
|
2607
|
+
def evaluate: (RenderContext context) -> untyped
|
2608
|
+
end
|
2609
|
+
|
2610
|
+
# Infix modulo
|
2611
|
+
class Modulo < ArithmeticExpression
|
2612
|
+
def evaluate: (RenderContext context) -> untyped
|
2613
|
+
end
|
2614
|
+
|
2615
|
+
# Infix exponentiation
|
2616
|
+
class Pow < ArithmeticExpression
|
2617
|
+
def evaluate: (RenderContext context) -> untyped
|
2618
|
+
end
|
2619
|
+
|
2620
|
+
# Prefix negation
|
2621
|
+
class Negative < Expression
|
2622
|
+
@right: untyped
|
2623
|
+
|
2624
|
+
# @param right [Expression]
|
2625
|
+
def initialize: ([Symbol, String?, Integer] token, untyped right) -> void
|
2626
|
+
|
2627
|
+
def evaluate: (RenderContext context) -> untyped
|
2628
|
+
end
|
2629
|
+
|
2630
|
+
# Prefix positive
|
2631
|
+
class Positive < Expression
|
2632
|
+
@right: untyped
|
2633
|
+
|
2634
|
+
# @param right [Expression]
|
2635
|
+
def initialize: ([Symbol, String?, Integer] token, untyped right) -> void
|
2636
|
+
|
2637
|
+
def evaluate: (RenderContext context) -> untyped
|
2638
|
+
end
|
2639
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Prior
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/liquid2/errors.rb
|
86
86
|
- lib/liquid2/expression.rb
|
87
87
|
- lib/liquid2/expressions/arguments.rb
|
88
|
+
- lib/liquid2/expressions/arithmetic.rb
|
88
89
|
- lib/liquid2/expressions/array.rb
|
89
90
|
- lib/liquid2/expressions/blank.rb
|
90
91
|
- lib/liquid2/expressions/boolean.rb
|
metadata.gz.sig
CHANGED
Binary file
|