-
-
Save UltraInstinct05/96fa99e1aaeb32b12d1e62109d61fcc2 to your computer and use it in GitHub Desktop.
%YAML 1.2 | |
--- | |
file_extensions: | |
- cottle | |
scope: source.cottle | |
contexts: | |
main: | |
- include: cottle_code_block | |
- include: expressions | |
comment: | |
- match: \_(?!\w+) | |
scope: punctuation.definition.comment.cottle | |
push: comment_body | |
comment_body: | |
- meta_scope: comment.line.underscore.cottle | |
- match: ($\n?)|(?=\}) | |
pop: true | |
cottle_code_block: | |
- match: \{ | |
scope: punctuation.section.block.begin.cottle | |
push: cottle_code_block_body | |
cottle_code_block_body: | |
- meta_scope: meta.block.cottle | |
- match: \} | |
scope: punctuation.section.block.end.cottle | |
pop: true | |
- include: statements | |
- include: builtin_functions | |
- include: comment | |
- include: cottle_code_block | |
- include: group_expression | |
- include: expressions | |
- match: \b(echo|dump|set|to)\b | |
scope: constant.language.cottle | |
builtin_functions: | |
- match: |- | |
(?x: | |
\b(and|cmp|default|defined|eq|ge|gt|has|le|lt|ne|not|or|xor|when|abs|add | |
|ceil|cos|div|floor|max|min|mod|mul|pow|rand|round|sin|sub|cat|cross| | |
|except|find|filter|flip|join|len|map|range|slice|sort|union|zip|char | |
|format|lcase|match|ord|split|token|ucase|cast|type|call)\b | |
)(?=\() | |
scope: meta.function-call.cottle | |
captures: | |
1: support.function.builtin.cottle | |
2: punctuation.section.arguments.begin.cottle | |
push: builtin_functions_body | |
builtin_functions_body: | |
- match: \( | |
scope: punctuation.section.arguments.begin.cottle | |
set: builtin_functions_parameters | |
builtin_functions_parameters: | |
- meta_scope: meta.function-call.cottle | |
- match: \) | |
scope: punctuation.section.arguments.end.cottle | |
pop: true | |
- include: expressions | |
- match: ',' | |
scope: punctuation.separator.arguments.cottle | |
statements: | |
- include: for_statement | |
- include: while_statement | |
- include: if_statement | |
- include: else_statement | |
- include: elif_statement | |
while_statement: | |
- match: \b(while)\b | |
scope: keyword.control.loop.while.cottle | |
push: while_statement_body | |
while_statement_body: | |
- meta_scope: meta.while.cottle | |
- match: ':' | |
scope: punctuation.section.block.loop.while.cottle | |
pop: true | |
- include: expressions | |
for_statement: | |
- match: \b(for)\b | |
scope: keyword.control.loop.for.cottle | |
push: for_statement_body | |
for_statement_body: | |
- meta_scope: meta.for.cottle | |
- match: \b(in)\b | |
scope: keyword.control.loop.for.in.cottle | |
set: in_statement | |
- include: expressions | |
in_statement: | |
- match: ':' | |
scope: punctuation.section.block.loop.for.cottle | |
pop: true | |
- include: expressions | |
else_statement: | |
- match: (\|\s*)\b(else)\b(?:\s*(:))? | |
scope: meta.else.cottle | |
captures: | |
1: punctuation.definition.else.cottle | |
2: keyword.control.conditional.else.cottle | |
3: punctuation.section.conditional.block.else.cottle | |
if_statement: | |
- match: \b(if)\b | |
scope: keyword.control.conditional.if.cottle | |
push: if_statement_body | |
if_statement_body: | |
- meta_scope: meta.if.cottle | |
- match: ':' | |
scope: punctuation.section.conditional.block.if.cottle | |
pop: true | |
- include: expressions | |
elif_statement: | |
- match: (\|\s*)\b(elif)\b | |
captures: | |
1: punctuation.definition.elif.cottle | |
2: keyword.control.conditional.elseif.cottle | |
push: elif_statement_body | |
elif_statement_body: | |
- meta_scope: meta.elif.cottle | |
- match: ':' | |
scope: punctuation.section.conditional.block.if.cottle | |
pop: true | |
- include: expressions | |
expressions: | |
- include: group_expression | |
- include: map | |
- include: operators | |
- include: number | |
- include: string | |
- include: booleans | |
booleans: | |
- match: \b(true|false)\b | |
scope: constant.language.boolean.cottle | |
map: | |
- match: \[ | |
scope: punctuation.definition.map.begin.cottle | |
push: map_body | |
map_body: | |
- meta_scope: meta.map.cottle | |
- match: \] | |
scope: punctuation.definition.map.end.cottle | |
pop: true | |
- include: expressions | |
- match: ':' | |
scope: punctuation.separator.mapping.key-value.cottle | |
- match: ',' | |
scope: punctuation.separator.sequence.cottle | |
group_expression: | |
- match: \( | |
scope: punctuation.section.group.begin.cottle | |
push: group_expression_body | |
group_expression_body: | |
- meta_scope: meta.group.cottle | |
- match: \) | |
scope: punctuation.section.group.end.cottle | |
pop: true | |
- include: expressions | |
operators: | |
- match: '(\+|\-|\*|\/|\%)' | |
scope: keyword.operator.arithmetic.cottle | |
- match: '[!<>]=' | |
scope: keyword.operator.comparison.cottle | |
- match: '[<>]' | |
scope: keyword.operator.comparison.cottle | |
- match: '[|&]{2}' | |
scope: keyword.operator.logical.cottle | |
- match: '=' | |
scope: keyword.operator.assignment.cottle | |
- match: '!' | |
scope: keyword.operator.logical.cottle | |
number: | |
- match: \d+ | |
scope: meta.number.integer.decimal.cottle | |
captures: | |
0: constant.numeric.value.cottle | |
string: | |
- include: double_quoted_string | |
- include: single_quoted_string | |
double_quoted_string: | |
- match: \" | |
scope: punctuation.definition.string.begin.cottle | |
push: double_quoted_string_body | |
double_quoted_string_body: | |
- meta_scope: meta.string.cottle string.quoted.double.cottle | |
- match: \" | |
scope: punctuation.definition.string.end.cottle | |
pop: true | |
- match: \{ | |
scope: punctuation.section.block.begin.cottle | |
push: cottle_code_block_body_within_string | |
cottle_code_block_body_within_string: | |
- clear_scopes: 1 | |
- meta_scope: meta.block.cottle | |
- match: \} | |
scope: punctuation.section.block.end.cottle | |
pop: true | |
- include: statements | |
- include: builtin_functions | |
- include: comment | |
- include: cottle_code_block | |
- include: group_expression | |
- include: expressions | |
- match: \b(echo|dump|set|to)\b | |
scope: constant.language.cottle | |
single_quoted_string: | |
- match: \' | |
scope: punctuation.definition.string.begin.cottle | |
push: single_quoted_string_body | |
single_quoted_string_body: | |
- meta_scope: meta.string.cottle string.quoted.single.cottle | |
- match: \' | |
scope: punctuation.definition.string.end.cottle | |
pop: true | |
- match: \{ | |
scope: punctuation.section.block.begin.cottle | |
push: cottle_code_block_body_within_string |
I've changed your cottle_code_block_body_within_string context in this way
Aah ! Good catch with this one. Yeah, this is much more suitable than mine. I don't know why I did not do it this way :P
Look at lines 10, 14, and 18, and also at the last dot at line 20: these should be all strings
Hmm... The issue with this is that they don't have an identifying nature that could be used to mark them as strings ? I thought these are just plain text.
My understanding is that we should rule that whatever remains that is not already catched by all the syntax rules then is a sring.unquoted. Problem is making it working inside code blocks...?
HOW to make this rule i don't know.
My understanding is that we should rule that whatever remains that is not already catched by all the syntax rules then is a sring.unquoted.
Unfortunately, there isn't (to my knowledge) a way to do something like that.
We're almost there, my friend!!!
Here's an updated working script:
This renders the comments with all the brackets and multiline also
2. I've changed your cottle_code_block_body_within_string context in this way
If i'm not missing something, it works as well without the duplicated code. am i right?
Now, I see i have problems explaining the last part that's not working (i'm italian, pardon me for my poor english) so i changed the color theme to make strings really stand out, with an Orange background. It's ugly but it shows what i need:
Look at lines 10, 14, and 18, and also at the last dot at line 20: these should be all strings (so, have the orange background). These are unquoted, but should be catched as strings.
That's the last part not working.
THANKS A LOT AGAIN.