Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/Template/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,14 @@ sub tokenise_directive {
\2 # match opening quote
|
# an unquoted number matches in $4
(-?\d+(?:\.\d+)?) # numbers
# only treat leading - as unary when not after a
# word char, close-paren, or close-bracket (else
# it is a subtraction operator, e.g. x-2)
((?:(?<![)\]\w])-)? \d+(?:\.\d+)?) # numbers
|
# filename matches in $5
( \/?\w+(?:(?:\/|::?)\w*)+ | \/\w+)
# filename matches in $5 — path segments after
# the separator must start with a letter
( \/?\w+(?:(?:\/|::?)[a-zA-Z_]\w*)+ | \/[a-zA-Z_]\w+)
|
# an identifier matches in $6
(\w+) # variable identifier
Expand Down
14 changes: 13 additions & 1 deletion t/binop.t
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,19 @@ mega: 106
3 3


-- stop --
-- test --
-- name subtraction vs negative literal (GH #315) --
[% x = 10; y = x - 3 %][% y +%]
[% z = -5 %][% z +%]
[% a = x + -2 %][% a +%]
[% b = x - -2 %][% b %]
-- expect --
7
-5
8
12

-- stop --
# this is for testing the lt operator which isn't enabled by default.
-- test --
[% IF 'one' lt 'two' -%]
Expand Down
10 changes: 10 additions & 0 deletions t/macro.t
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,13 @@ two: 2[The Title] -> one: 2[The Title]
[% triple(10) %]
-- expect --
30

-- test --
-- name macro with arithmetic expressions (GH #315) --
[% MACRO show(n) BLOCK -%]
[% n %]
[%- END -%]
[% x = 5 -%]
[% show(x) %]:[% show(x+2) %]:[% show(x-2) %]:[% show(x*2) %]:[% show(x/2) %]
-- expect --
5:7:3:10:2.5
Loading