1
0
Fork 0
mirror of https://github.com/Reuh/sublime-anselme.git synced 2025-10-27 03:49:29 +00:00
sublime-anselme/Anselme.sublime-syntax

282 lines
7.8 KiB
YAML
Executable file

%YAML 1.2
---
name: anselme v2
file_extensions:
- ans
- anselme
scope: source.anselme
version: 2
variables:
identifier_disallowed: '\.\~\`\^\+\-\=\<\>\/\[\]\*\{\}\|\\\_\!\?\,\;\:\(\)\"\@\&\$\#\%'
identifier: |-
(?x:
[^0-9\s\'{{identifier_disallowed}}][^{{identifier_disallowed}}]*
|\_( \! | \- | \* | \~ )
|( \! )\_
|\_( \+ | \- | \/ | \/\/ | \* | \^ | \% | \& | \| | \=\= | \= | \!\= | \>\= | \<\= | \< | \> | \. | \:\: | \# | \: )\_
)
contexts:
prototype:
- include: comments_and_whitespace
- match: '$'
pop: true
comments_and_whitespace:
- match: '\/\/'
scope: comment.line.anselme punctuation.definition.comment.anselme
push: comment
- match: '\/\*'
scope: comment.block.anselme punctuation.definition.comment.anselme
push: multiline_comment
- match: '\s+'
main:
- match: ''
push: primary
comment:
- meta_scope: comment.line.anselme
- match: '\/\/|$'
scope: punctuation.definition.comment.anselme
pop: true
multiline_comment:
- meta_scope: comment.block.anselme
- match: '\/\*'
scope: punctuation.definition.comment.anselme
push: multiline_comment
- match: '\*\/'
scope: punctuation.definition.comment.anselme
pop: true
## Primary elements ##
primary:
- match: '\d*\.\d+|\d+'
scope: constant.numeric.anselme
push: secondary
- match: '\"'
scope: punctuation.definition.string.begin.anselme
push: string
- match: '\|'
scope: keyword.other.anselme
push: text
- match: '\('
scope: punctuation.section.parens.begin.anselme
push: parenthesis
- match: '\:&?@?\$'
scope: keyword.declaration.anselme
push: function_definition
- match: '(\#)({{identifier}})'
captures:
1: keyword.declaration.anselme
2: entity.name.label.anselme
push: secondary
- match: '(\:&?@?)({{identifier}})'
captures:
1: keyword.declaration.anselme
2: variable.other.anselme
push: secondary
- match: '{{identifier}}(?=\!(?!\s*{{identifier}})|\(|\[|\{)'
scope: variable.function.anselme
set: secondary
- match: '({{identifier}})\s*(?=\:)'
scope: meta.mapping.key.anselme string.unquoted.key.anselme
push: secondary
- match: '{{identifier}}'
scope: variable.other.anselme
push: secondary
- match: '\-\-\-'
scope: text.anselme meta.separator.thematic-break.anselme punctuation.definition.thematic-break.anselme
push: secondary
- match: '\_'
scope: variable.language.anselme
push: secondary
- match: '\['
scope: punctuation.section.sequence.begin.anselme
push: tuple
- match: '\{'
scope: punctuation.section.sequence.mapping.anselme
push: struct
- include: prefixes_primary
- match: ''
pop: true
prefixes_primary:
- match: '(\$)\s*(\()'
captures:
1: meta.function.anselme keyword.declaration.anselme
2: meta.function.parameters.anselme punctuation.section.parameters.begin.anselme
push: function_parameters
- match: '\$'
scope: keyword.declaration.anselme meta.function.anselme
set: primary
- match: '\;'
scope: keyword.control.anselme
set: primary
- match: '\-|\+'
scope: keyword.operator.arithmetic.anselme
set: primary
- match: '\!'
scope: keyword.operator.logical.anselme
set: primary
- match: '\*|\%|\>'
scope: keyword.operator.anselme
set: primary
## Function definition ##
# The parameter parsing here is a very bad approximation, but properly handling this would require handling operator priority in this syntax file, so no.
# Maybe I should look at tree sitter or something.
function_parameters:
- meta_scope: meta.function.parameters.anselme
- match: '{{identifier}}'
scope: variable.parameter.anselme
embed: secondary
escape: '(?=\)|\,)'
- match: '\,'
scope: punctuation.separator.parameters.anselme
- match: '(\))\s*(\=)'
captures:
1: punctuation.section.parameters.end.anselme
2: keyword.operator.assignment.anselme
push: secondary
- match: '\)'
scope: punctuation.section.parameters.end.anselme
push: secondary
- match: ''
pop: true
function_definition:
- match: '({{identifier}})\s*(\()'
captures:
1: meta.function.parameters.anselme entity.name.function.anselme
2: meta.function.parameters.anselme punctuation.section.parameters.begin.anselme
set: function_parameters
- match: '{{identifier}}'
scope: meta.function.parameters.anselme entity.name.function.anselme
pop: true
- match: ''
pop: true
## String & text ##
expression_interpolation:
- match: '\{'
scope: punctuation.section.interpolation.begin.anselme
embed: primary
embed_scope: source.anselme.embedded
escape: '\}'
escape_captures:
0: punctuation.section.interpolation.end.anselme
character_escape:
- match: '\\.'
scope: constant.character.escape.anselme
string:
- meta_include_prototype: false
- meta_scope: meta.string.anselme string.quoted.double.anselme
- include: expression_interpolation
- include: character_escape
- match: '\"'
scope: punctuation.definition.string.end.anselme
set: secondary
text:
- meta_scope: text.anselme
- include: expression_interpolation
- include: character_escape
- match: '\|'
scope: keyword.other.anselme
set: secondary
## Other primary elements ##
parenthesis:
- meta_include_prototype: false
- meta_scope: meta.parens.anselme
- match: '\)'
scope: punctuation.section.parens.end.anselme
set: secondary
- include: comments_and_whitespace
- include: primary
tuple:
- meta_include_prototype: false
- meta_scope: meta.sequence.tuple.anselme
- include: comments_and_whitespace
- include: primary
- match: '\,'
scope: punctuation.separator.sequence.anselme
- match: '\]'
scope: punctuation.section.sequence.end.anselme
set: secondary
struct:
- meta_include_prototype: false
- meta_scope: meta.mapping.anselme
- include: comments_and_whitespace
- include: primary
- match: '\,'
scope: punctuation.separator.sequence.anselme
- match: '\}'
scope: punctuation.section.mapping.end.anselme
set: secondary
## Secondary operators ##
secondary:
- match: '\;'
scope: keyword.control.anselme
push: primary
- match: '\,'
scope: punctuation.separator.sequence.anselme
push: primary
- match: '\#|\:\:|\:|\-\>'
scope: keyword.operator.anselme
push: primary
- match: '\&|\|'
scope: keyword.operator.logical.anselme
push: primary
- match: '\=\=|\!\=|\<\=|\>\=|\<|\>'
scope: keyword.operator.comparison.anselme
push: primary
- match: '\+|\-|\*|\/|\%|\^'
scope: keyword.operator.arithmetic.anselme
push: primary
- match: '\.'
scope: punctuation.accessor.anselme
push: primary
- match: '(\!)\s*({{identifier}})'
scope: meta.function-call
captures:
1: keyword.operaor.anselme
2: variable.function.anselme
set: secondary
- match: '\!'
scope: keyword.operaor.anselme
push: primary
- match: '\='
scope: keyword.operator.assignment.anselme
push: primary
- include: suffix_secondary
- match: ''
pop: true
suffix_secondary:
- match: '\;'
scope: keyword.control.anselme
set: secondary
- match: '\!'
scope: keyword.operator.anselme
set: secondary
- match: '\('
scope: punctuation.section.arguments.begin.anselme
set:
- match: '\)'
scope: punctuation.section.arguments.end.anselme
set: secondary
- include: primary