Skip to content

Commit

Permalink
Improve multi-line expressions
Browse files Browse the repository at this point in the history
Resolves #12

This commit attempts to improve support for multi-line expressions.
If certain keywords/operators are detected at beginning of a line,
treat them as expression continuation rather than custom function
call statement.
  • Loading branch information
deathaxe committed Feb 23, 2025
1 parent dc61123 commit 0020198
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Syntaxes/Liquid.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ contexts:
- include: liquid-conditionals
- include: liquid-iterations
- include: liquid-functions
- include: liquid-filters
- include: liquid-expression-continuation
- include: liquid-other

liquid-expression:
Expand Down Expand Up @@ -441,6 +443,32 @@ contexts:
- match: \bby\b
scope: keyword.operator.liquid

liquid-expression-continuation:
# hack to handle multi-line expressions
# If first token of a new line matches one of the following patterns
# it is most likely a continuation of an expression.
- match: ':'
scope: punctuation.separator.key-value.liquid
push: liquid-expression
- match: ','
scope: punctuation.separator.sequence.liquid
push: liquid-expression
- match: =
scope: keyword.operator.assignment.liquid
push: liquid-expression
- match: (?:!=|==|<=|>=|<|>)
scope: keyword.operator.comparison.liquid
push: liquid-expression
- match: \bas\b
scope: keyword.operator.assignment.liquid
push: liquid-expression
- match: \b(?:and|or|not|contains)\b
scope: keyword.operator.logical.liquid
push: liquid-expression
- match: \bby\b
scope: keyword.operator.liquid
push: liquid-expression

###[ LIQUID LITERALS ]########################################################

liquid-constants:
Expand Down
17 changes: 17 additions & 0 deletions tests/syntax_test_liquid.liquid.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@
| ^^^^^^^ meta.string.liquid string.quoted.double.liquid
| ^^ punctuation.section.embedded.end.liquid

{%- if foo != blank
and bar != ''
|^^^^^^^^^^^^^^ meta.embedded.liquid source.liquid meta.statement.liquid
| ^^^ keyword.operator.logical.liquid
| ^^^ variable.other.liquid
| ^^ keyword.operator.comparison.liquid
| ^^ meta.string.liquid string.quoted.single.liquid
or baz
|^^^^^^^^ meta.embedded.liquid source.liquid meta.statement.liquid
| ^^ keyword.operator.logical.liquid
| ^^^ variable.other.liquid
== true
|^^^^^^^^ meta.embedded.liquid source.liquid meta.statement.liquid
| ^^ keyword.operator.assignment.liquid
| ^^^^ constant.language.boolean.liquid
-%}

{% case handle %}
|^^^^^^^^^^^^^^^^ meta.embedded.liquid source.liquid meta.statement.liquid
| ^^^^ keyword.control.conditional.case.liquid
Expand Down

0 comments on commit 0020198

Please sign in to comment.