Last active
April 11, 2021 13:21
-
-
Save UltraInstinct05/96fa99e1aaeb32b12d1e62109d61fcc2 to your computer and use it in GitHub Desktop.
A syntax for Cottle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, there isn't (to my knowledge) a way to do something like that.