Skip to content

Commit

Permalink
Add support for nested parenthesis and inline conditional expressions
Browse files Browse the repository at this point in the history
There's a lot of such code in Qt and KDE world.

Fixes #68
  • Loading branch information
ratijas authored and rwols committed Feb 21, 2023
1 parent c04b77b commit eb40ede
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CMake.sublime-syntax
Expand Up @@ -206,8 +206,7 @@ contexts:
- include: break
- include: main

if-args:
- meta_scope: meta.function-call.arguments.cmake
if-args-inline:
- match: \(
scope: punctuation.section.parens.begin.cmake
push: if-args
Expand Down Expand Up @@ -266,6 +265,10 @@ contexts:
- match: \n
- match: ''
pop: true

if-args:
- meta_scope: meta.function-call.arguments.cmake
- include: if-args-inline
- include: args-common

elseif:
Expand Down Expand Up @@ -520,6 +523,8 @@ contexts:
- match: \)
scope: punctuation.section.parens.end.cmake
pop: true
# This might be useful for commands which take literal condition expressions as arguments
- include: if-args-inline
- match: (?={{generic_named_parameter}})
push: unquoted-argument-or-keyword
- include: string-unquoted
Expand Down
15 changes: 15 additions & 0 deletions syntax_test.txt
Expand Up @@ -360,3 +360,18 @@ foreach(iexample RANGE ${nexample})
# ^^^^^ meta.group.foreach.cmake meta.function-call.arguments.cmake variable.parameter.foreach.RANGE.cmake
endforeach()
# <- meta.group.foreach.cmake meta.function-call.cmake keyword.control.endforeach.cmake

test_nested_conditions(Abc CONDITION GCC AND (arch STREQUAL "x") COMPILE_OPTIONS -fno)
# ^^^^^^^^^^^^^^^^^^^^ meta.function-call.generic.cmake variable.function.generic
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.generic
# ^ punctuation.section.parens.begin
# ^^^^^^^^^ variable.parameter.generic
# ^^^ keyword.operator
# ^ punctuation.section.parens.begin
# ^^^^^^^^ variable.parameter.if.STREQUAL.cmake
# ^ punctuation.section.parens.end
# ^^^^^^^^^^^^^^^ variable.parameter.generic
# ^^^^ meta.string.unquoted
# ^ punctuation.section.parens.end

# <- - meta.function-call

0 comments on commit eb40ede

Please sign in to comment.