My approach would make that illegal, since I can’t instruct the engine to not escape embeds when in certain contexts (like inside parentheses). The closest legal construct would be
if True:
(
print("This is, sadly, correctly indented."))
That’s what I meant when I said your solution is more robust: it allows greater flexibility (I myself don’t mind the gramar for mylang being stricter. In fact, with line wrap I could even force a whole function signature to be expressed in a single line).
Here you go in any case:
[code]%YAML 1.2
file_extensions: [myl]
scope: source.myLang
contexts:
main:
- include: statements
statements:
- match: ^(?=\s*\S)
push: statement
statement:
- match: ^([\t ]*)(def)\b
captures:
1: meta.indent
2: storage.type
embed: def-then-function
embed_scope: meta.function
escape: ^(?!\1[\t ]+\S)
def-then-function:
- match: ‘’
push:
- indented-block
- expect-colon
- function-parameters
- function-name
indented-block:
# Ignore empty line
- match: ^\s*$
# pop off at a none-empty line with same indention as def
- match: ^(?!\1[\t ]+\S) #
pop: true
- include: statements
function-def:
- match: def\b
scope: keyword.declaration.function.python
set:
- expect-colon
- function-parameters
- function-name
expect-colon:
- match: ‘:’
scope: punctuation.separator.python
pop: true
- include: pop-eol
- include: else-pop
function-parameters:
- match: (
scope: punctuation.section.group.begin.python
set:
- meta_content_scope: meta.function.parameters
- match: )
scope: punctuation.section.group.end.python
pop: true
- match: \w+
scope: variable.parameter.python
- match: ‘,’
scope: punctuation.separator.python
- include: pop-eol
- include: else-pop
function-name:
- match: \w+
scope: entity.name.function.python
pop: true
- include: pop-eol
- include: else-pop
[/code]