1
0
Fork 0
mirror of https://github.com/Reuh/sublime-anselme.git synced 2025-10-27 11:49:30 +00:00

Rewrite for Anselme v2.0.0-alpha

This commit is contained in:
Étienne Fildadut 2023-12-18 18:39:59 +01:00
parent 7501facc8a
commit 35daa005cc
3 changed files with 230 additions and 209 deletions

View file

@ -1,237 +1,258 @@
%YAML 1.2 %YAML 1.2
--- ---
# http://www.sublimetext.com/docs/3/syntax.html name: anselme v2
name: Anselme
comment: "Anselme v25, and probably later, syntax"
file_extensions: file_extensions:
- ans - ans
- anselme - anselme
scope: source.anselme scope: source.anselme
version: 2
variables: variables:
identifier: '[^\~\`\^\+\-\=\<\>\/\[\]\*\{\}\|\\\_\!\?\,\;\:\(\)\"\@\&\$\#\%\.\d\s][^\~\`\^\+\-\=\<\>\/\[\]\*\{\}\|\\\_\!\?\,\;\:\(\)\"\@\&\$\#\%\.]*' identifier_disallowed: '\.\~\`\^\+\-\=\<\>\/\[\]\*\{\}\|\\\_\!\?\,\;\:\(\)\"\@\&\$\#\%'
operator: '[;:=+-/*%^,~?#|&!><!.$]+' identifier: |-
(?x:
[^0-9\s\'{{identifier_disallowed}}][^{{identifier_disallowed}}]*
|\_( \! | \- | \* | \~ )
|( \! )\_
|\_( \|\> | \+ | \- | \/ | \/\/ | \* | \^ | \% | \& | \| | \=\= | \= | \!\= | \>\= | \<\= | \< | \> | \~ | \~\? | \. | \:\: | \# | \: )\_
)
contexts: contexts:
# Line types prototype:
- match: '\(\('
scope: comment.line.anselme punctuation.definition.comment.anselme
push: comment
- match: '\s+'
- match: '$'
pop: true
main: main:
- match: ^\s*\(.*$ - match: ''
scope: comment.line.anselme push: primary
- match: ^\s*~[~?]?
scope: keyword.control.conditional.anselme
push: expression
- match: ^\s*@
scope: keyword.control.anselme
push: expression
- match: ^\s*#
scope: keyword.other.anselme
push: expression
- match: ^\s*\>
scope: keyword.control.conditional.anselme
push: text
- match: ^\s*:~?[$!%]
scope: keyword.other.anselme
push: function_definition_start
- match: ^\s*\:~?
scope: keyword.other.anselme
push: variable_definition_start
- match: ^\s*
push: text
# Text lines comment:
text: - meta_scope: comment.line.anselme
- meta_scope: text.anselme - match: '\(\('
- match: \\. scope: punctuation.definition.comment.anselme
scope: constant.character.escape.anselme push: comment
- match: '[~#]' - match: '\)\)|$'
scope: keyword.operator.anselme scope: punctuation.definition.comment.anselme
push: expression
- include: string_interpolable
- include: string_subtextable
- include: pop_on_line_end
# Function definition
function_definition_start:
- meta_scope: meta.function.anselme
- match: '({{identifier}}|_?{{operator}}_?|\{\}|\(\))(?:(:)({{identifier}}))?'
captures:
1: entity.name.function.anselme
2: punctuation.separator.anselme
3: entity.name.function.anselme
set: function_definition_args
- include: pop_on_line_end
function_definition_args:
- match: \(
scope: punctuation.section.parens.start.anselme
set: parameter_paren
- include: pop_on_line_end
parameter_paren:
- meta_scope: meta.function.parameters.anselme
- match: '({{identifier}})(?:(:)({{identifier}}))?(=|::)'
captures:
1: variable.parameter.anselme
2: punctuation.separator.anselme
3: variable.parameter.anselme
4: keyword.operator.anselme
push: parameter_default
- match: '({{identifier}})(?:(:)({{identifier}}))?'
captures:
1: variable.parameter.anselme
2: punctuation.separator.anselme
3: variable.parameter.anselme
- match: ','
scope: punctuation.separator.anselme
- match: \)
scope: punctuation.section.parens.end.anselme
pop: true pop: true
- include: pop_on_line_end
parameter_default:
- match: '(?=,|\))'
scope: punctuation.separator.anselme
pop: true
- include: expression
# Variable definition ## Primary elements ##
variable_definition_start:
- match: '(:)\s*({{identifier}})(?:(:)({{identifier}}))?'
captures:
1: keyword.other.anselme
2: variable.other.constant.anselme
3: punctuation.separator.anselme
4: variable.other.constant.anselme
set: variable_definition_value
- match: '(@?)\s*({{identifier}})(?:(:)({{identifier}}))?'
captures:
1: keyword.other.anselme
2: variable.other.anselme
3: punctuation.separator.anselme
4: variable.other.anselme
set: variable_definition_value
- include: pop_on_line_end
variable_definition_value:
- match: \=
scope: keyword.operator.assignment.anselme
push: expression
- include: pop_on_line_end
# Expressions primary:
expression: - match: '\d*\.\d+|\d+'
- match: \s+
- match: \d*\.\d+|\d+
scope: constant.numeric.anselme scope: constant.numeric.anselme
- match: \( push: secondary
scope: punctuation.section.parens.start.anselme - match: '\"'
push: paren
- match: \)
scope: invalid.illegal.stray-paren-end.anselme
- match: \%\[
scope: punctuation.section.brackets.start.anselme
push: string_subtext
- match: \[
scope: punctuation.section.brackets.start.anselme
push: list
- match: \]
scope: invalid.illegal.stray-bracket-end.anselme
- match: \{
scope: punctuation.section.braces.start.anselme
push: map
- match: \{
scope: invalid.illegal.stray-brace-end.anselme
- match: '({{identifier}})(?=\(|!\s*(?!\(|{{identifier}}|\[|\{))'
scope: variable.function.anselme
- match: '({{identifier}})(=)(?!{{operator}})'
captures:
1: string.unquoted.anselme
2: keyword.operator.anselme
- match: '{{identifier}}'
scope: variable.other.anselme
- match: '(?<!\s)\s*(!)\s*({{identifier}})'
captures:
1: keyword.operator.anselme
2: variable.function.anselme
- match: \.
scope: punctuation.accessor.anselme
- match: ','
scope: punctuation.separator.anselme
- match: '\$(?=\()'
scope: keyword.other.anselme
push: function_definition_args
- match: '{{operator}}'
scope: keyword.operator.anselme
- match: \"
scope: punctuation.definition.string.begin.anselme scope: punctuation.definition.string.begin.anselme
push: string push: string
- match: "" - 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: variable.other.anselme
push: secondary
- match: '{{identifier}}(?=\!(?!\s*{{identifier}})|\()'
scope: variable.function.anselme
set: secondary
- match: '{{identifier}}'
scope: variable.other.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 pop: true
# Sub-expressions prefixes_primary:
string_interpolation: - match: '(\$)\s*(\()'
- clear_scopes: true captures:
- meta_scope: meta.interpolation.anselme 1: meta.function.anselme keyword.declaration.anselme
- match: \} 2: meta.function.parameters.anselme punctuation.section.parameters.begin.anselme
scope: punctuation.section.interpolation.end.anselme push: function_parameters
pop: true - match: '\$'
- include: expression scope: keyword.declaration.anselme meta.function.anselme
set: primary
string_subtext: - match: '\~'
- clear_scopes: true scope: keyword.control.conditional.anselme
- meta_scope: meta.brackets.anselme set: primary
- meta_content_scope: text.anselme - match: '\@|\;'
- match: \] scope: keyword.control.anselme
scope: punctuation.section.brackets.end.anselme set: primary
pop: true - match: '\-'
- match: '[~#]' scope: keyword.operator.arithmetic.anselme
set: primary
- match: '\!'
scope: keyword.operator.logical.anselme
set: primary
- match: '\*'
scope: keyword.operator.anselme scope: keyword.operator.anselme
push: expression_in_subtext set: primary
- include: text
expression_in_subtext: ## Function definition ##
- match: '(?=\])' # The parameter parsing here is a very bad approximation, but properly handling this would require handling operator priority in this syntax file, so no.
scope: punctuation.section.brackets.end.anselme # 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 pop: true
- include: expression
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: string:
- meta_scope: string.quoted.double.anselme - meta_scope: meta.string.anselme string.quoted.double.anselme
- meta_content_scope: meta.string.anselme - include: expression_interpolation
- match: \\. - include: character_escape
scope: constant.character.escape.anselme - match: '\"'
- match: \"
scope: punctuation.definition.string.end.anselme scope: punctuation.definition.string.end.anselme
pop: true set: secondary
- include: string_interpolable
paren: text:
- meta_scope: text.anselme
- include: expression_interpolation
- include: character_escape
- match: '\|'
scope: keyword.other.anselme
set: secondary
## Other primary elements ##
parenthesis:
- meta_scope: meta.parens.anselme - meta_scope: meta.parens.anselme
- match: \) - match: '\)'
scope: punctuation.section.parens.end.anselme scope: punctuation.section.parens.end.anselme
set: secondary
- include: primary
tuple:
- meta_scope: meta.sequence.tuple.anselme
- include: primary
- match: '\,'
scope: punctuation.separator.sequence.anselme
- match: '\]'
scope: punctuation.section.sequence.end.anselme
set: secondary
struct:
- meta_scope: meta.mapping.anselme
- 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.control.conditional.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 pop: true
- include: expression
list: suffix_secondary:
- meta_scope: meta.brackets.anselme - match: '\;'
- match: \] scope: keyword.control.anselme
scope: punctuation.section.brackets.end.anselme set: secondary
pop: true - match: '\!'
- include: expression scope: keyword.operator.anselme
set: secondary
map: - match: '\('
- meta_scope: meta.braces.anselme scope: punctuation.section.arguments.begin.anselme
- match: \} set:
scope: punctuation.section.braces.end.anselme - match: '\)'
pop: true scope: punctuation.section.arguments.end.anselme
- include: expression set: secondary
- include: primary
# Includes
string_interpolable:
- match: \{
scope: punctuation.section.interpolation.begin.anselme
push: string_interpolation
string_subtextable:
- match: \[
scope: punctuation.section.brackets.begin.anselme
push: string_subtext
pop_on_line_end:
- match: $
pop: true

View file

@ -13,7 +13,7 @@
<key>name</key> <key>name</key>
<string>TM_COMMENT_START</string> <string>TM_COMMENT_START</string>
<key>value</key> <key>value</key>
<string>(</string> <string>((</string>
</dict> </dict>
</array> </array>
</dict> </dict>

View file

@ -8,7 +8,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>increaseIndentPattern</key> <key>increaseIndentPattern</key>
<string>^\s*([~#>]|:[$!%])</string> <string>(^.*(\$|\@|\~|\~\?|\|\>|\#|\=)\s*$)|^\s*(\:\:?[\@\!]?\$.*$)</string>
</dict> </dict>
</dict> </dict>
</plist> </plist>