Skip to content

Commit 9018db9

Browse files
Christopher Wallismarijnh
authored andcommitted
[soy mode] tokenize operators in expressions
- tokenize arithmetic and equality operators as "operator" - added tests to validate this
1 parent cafe582 commit 9018db9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mode/soy/soy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@
271271
stream.match(/-?([0-9]*[.])?[0-9]+/)) {
272272
return "atom";
273273
}
274+
if (stream.match(/(\||[+\-*\/%]|[=!][=]|[<>][=]?)/)) {
275+
// Tokenize filter, binary, and equality operators.
276+
return "operator";
277+
}
274278
if (match = stream.match(/^\$([\w]+)/)) {
275279
return ref(state.variables, match[1]);
276280
}

mode/soy/test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Test of small keywords and words containing them.
99
MT('keywords-test',
1010
'[keyword {] [keyword as] worrying [keyword and] notorious [keyword as]',
11-
' the Fandor-alias assassin, [keyword or]',
11+
' the Fandor[operator -]alias assassin, [keyword or]',
1212
' Corcand cannot fit [keyword in] [keyword }]');
1313

1414
MT('let-test',
@@ -33,6 +33,20 @@
3333
'[keyword {namespace] [variable my.namespace.templates] ' +
3434
'[attribute requirecss]=[string "my.namespace"][keyword }]');
3535

36+
MT('operators-test',
37+
'[keyword {] [atom 1] [operator ==] [atom 1] [keyword }]',
38+
'[keyword {] [atom 1] [operator !=] [atom 2] [keyword }]',
39+
'[keyword {] [atom 2] [operator +] [atom 2] [keyword }]',
40+
'[keyword {] [atom 2] [operator -] [atom 2] [keyword }]',
41+
'[keyword {] [atom 2] [operator *] [atom 2] [keyword }]',
42+
'[keyword {] [atom 2] [operator /] [atom 2] [keyword }]',
43+
'[keyword {] [atom 2] [operator %] [atom 2] [keyword }]',
44+
'[keyword {] [atom 2] [operator <=] [atom 2] [keyword }]',
45+
'[keyword {] [atom 2] [operator >=] [atom 2] [keyword }]',
46+
'[keyword {] [atom 3] [operator >] [atom 2] [keyword }]',
47+
'[keyword {] [atom 2] [operator >] [atom 3] [keyword }]',
48+
'[keyword {] [variable-2&error $variable] [operator |] safeHtml [keyword }]')
49+
3650
MT('primitive-test',
3751
'[keyword {] [atom true] [keyword }]',
3852
'[keyword {] [atom false] [keyword }]',

0 commit comments

Comments
 (0)