From eb40ede56c2d4d5a4a129b2a5bc7095a2df46bb1 Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Tue, 21 Feb 2023 17:04:50 +0300 Subject: [PATCH] Add support for nested parenthesis and inline conditional expressions There's a lot of such code in Qt and KDE world. Fixes #68 --- CMake.sublime-syntax | 9 +++++++-- syntax_test.txt | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CMake.sublime-syntax b/CMake.sublime-syntax index ffd22d8..16f7a79 100644 --- a/CMake.sublime-syntax +++ b/CMake.sublime-syntax @@ -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 @@ -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: @@ -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 diff --git a/syntax_test.txt b/syntax_test.txt index 623e2b4..71b479b 100644 --- a/syntax_test.txt +++ b/syntax_test.txt @@ -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