Last active
April 27, 2018 17:38
-
-
Save stevetranby/71a422a61385971eef01a79a2dea2ab0 to your computer and use it in GitHub Desktop.
WIP Syntax for the 'Ion' Language (from Bitwise Project) for Sublime Text 3
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 | |
--- | |
# References: | |
# http://www.sublimetext.com/docs/3/syntax.html | |
# https://www.sublimetext.com/docs/3/settings.html | |
# https://www.sublimetext.com/docs/3/scope_naming.html | |
# https://github.com/shogas/vim-ion/blob/master/syntax/ion.vim | |
# https://github.com/odin-lang/sublime-odin/blob/master/Odin.sublime-syntax | |
# | |
# TODO: look at the following for improvements/enhancements | |
# https://packagecontrol.io/packages/C%20Improved | |
# https://github.com/sublimehq/Packages/blob/master/C%2B%2B/C.sublime-syntax | |
file_extensions: ion | |
scope: source.ion | |
variables: | |
reserved_words: 'switch' | |
identifier: '\b(?<!switch)[[:alpha:]_][[:alnum:]_]*\b' | |
type_chars: '[[:alnum:]\s,._^<>\[\]-]' | |
screaming_identifier: '\b[A-Z_](?![a-z])[A-Z_0-9]+\b' | |
contexts: | |
main: | |
- include: global | |
global: | |
- include: comments | |
- include: numbers | |
- include: foreign | |
- include: functions-and-declarations | |
- include: types | |
- include: keywords # must match after func/decl/types | |
- include: custom_styling | |
- include: strings | |
- include: string-escaped-char | |
# To not highlight function calls | |
# '(func\s+)({{identifier}})\(' | |
- match: '(func\s+)?({{identifier}})\s*\(' | |
captures: | |
1: keyword.control.ion | |
2: entity.name.function.ion | |
custom_styling: | |
- match: \b({{screaming_identifier}})\b | |
captures: | |
1: storage.constant.ion | |
block-comment: | |
- match: /\* | |
scope: punctuation.definition.comment.ion | |
push: | |
- meta_scope: comment.block.ion | |
- match: \*/ | |
scope: punctuation.definition.comment.ion | |
pop: true | |
- include: block-comment | |
comments: | |
- include: block-comment | |
- match: // | |
scope: punctuation.definition.comment.ion | |
push: | |
- meta_scope: comment.line.double-slash.ion | |
- match: \n | |
pop: true | |
functions-and-declarations: | |
- match: '(var|const)?\s+({{identifier}})(\:)\s+({{identifier}})(\s+const)?([\s\*]*)\s*[\);=\[\n{]' | |
captures: | |
1: storage.type.ion | |
# 2: entity.name.tag.ion | |
3: keyword.operator.assignment.ion | |
4: storage.type.ion | |
5: storage.type.ion | |
6: storage.type.ion | |
7: storage.type.ion | |
8: storage.type.ion | |
- match: '(func)\s+({{identifier}})\(' | |
captures: | |
1: keyword.control.ion | |
2: entity.name.function.ion | |
- match: '(struct|enum)\s+({{identifier}})\s*(\{)' | |
captures: | |
1: keyword.control.ion | |
2: storage.type.ion | |
3: keyword.operator.assignment.ion | |
- match: '({{identifier}})\s*(\{)[^\}]*(\})' | |
captures: | |
1: storage.type.ion | |
2: keyword.operator.assignment.ion | |
3: keyword.operator.assignment.ion | |
- match: '(var|const)\s+({{identifier}})\s*(\=)' | |
captures: | |
1: keyword.control.ion | |
3: keyword.operator.assignment.ion | |
keywords: | |
# - match: \b(var|const)\b | |
# scope: keyword.control.ion | |
- match: \b(struct|enum|union|defer|import)\b | |
scope: keyword.control.ion | |
- match: \b(if|else|switch|case|default)\b | |
scope: keyword.control.ion | |
- match: \b(for|while|do)\b | |
scope: keyword.control.ion | |
- match: \b(break|continue|return)\b | |
scope: keyword.control.ion | |
- match: \bsizeof|offsetof|typeof|get_typeof|alignof\b | |
scope: keyword.operator.sizeof.ion | |
- match: \b(typedef)\b | |
scope: keyword.struct.ion | |
- match: \b(true|false|NULL)\b | |
scope: keyword.constant.ion | |
types: | |
- match: (true|false|NULL) | |
scope: constant.language.ion | |
- match: \b(void|bool)\b | |
scope: storage.type.others.ion | |
- match: \basm|__asm__|auto\b | |
scope: storage.type.ion | |
- match: \b(int|uint|char|uchar|schar|short|long|ulong|llong|ullong)\b | |
scope: storage.type.ion | |
- match: \b(float|double)\b | |
scope: storage.type.ion | |
- match: \b(int8|int16|int32|int64|uint8|uint16|uint32|uint64)\b | |
scope: storage.type.ion | |
#operators | |
- match: (:=|=)+ | |
scope: keyword.operator.assignment.ion | |
- match: (==|<=|>=|>|<|\|\|) | |
scope: keyword.operator.logic.ion | |
- match: (~|\^|&&|&) | |
scope: keyword.operator.binary.ion | |
- match: (\+\+|\-\-|\+|\-|\-\=|\*|/) | |
scope: keyword.operator.math.ion | |
- match: '\((\:)([^)}]*]*(\*)*)\)' | |
captures: | |
1: keyword.operator.assignment.ion | |
2: storage.type.ion | |
3: keyword.operator.assignment.ion | |
numbers: | |
- match: \b(\d(\d|_)*(.\d(\d|_)*)?)((e|E)(\+|-)?\d+)?(d|u|l|ul|ull|ll)?\b | |
scope: constant.numeric.ion | |
- match: \b((0b(0|1|_)+)|(0o(\d|_)+)|(0d(\d|_)+)|(0[xX](\h|_)+))(d|u|l|ul|ull|ll)?\b | |
scope: constant.numeric.ion | |
foreign: | |
#tags (@foreign #foreign) | |
- match: '([#@]\s*{{identifier}})' | |
#scope: meta.preprocessor.macro.ion | |
scope: keyword.tag.ion | |
- match: \#static_assert | |
scope: meta.preprocessor.macro.ion | |
strings: | |
- match: '"""' | |
scope: punctuation.definition.string.begin.ion | |
push: | |
- meta_scope: string.quoted.double.ion | |
- match: '"""' | |
scope: punctuation.definition.string.end.ion | |
pop: true | |
- include: string-escaped-char | |
- match: '"' | |
scope: punctuation.definition.string.begin.ion | |
push: | |
- meta_scope: string.quoted.double.ion | |
- match: '"' | |
scope: punctuation.definition.string.end.ion | |
pop: true | |
- include: string-escaped-char | |
- match: "`" | |
scope: punctuation.definition.string.begin.ion | |
push: | |
- meta_scope: string.quoted.raw.ion | |
- match: "`" | |
scope: punctuation.definition.string.end.ion | |
pop: true | |
- match: "'" | |
scope: punctuation.definition.string.begin.ion | |
push: | |
- meta_scope: string.quoted.raw.ion | |
- match: "'" | |
scope: punctuation.definition.string.end.ion | |
pop: true | |
- include: string-escaped-char | |
string-escaped-char: | |
- match: '\\(\\|[0abfnrutv''"]|x\h{2}|u\h{4}|U\h{8}|[0-7]{3})' | |
scope: constant.character.escape.ion | |
# for C-like printf, I believe Bitewise wants to get rid of it) | |
- match: "%[.\\-+*0-9#]*(llu|lu|ul|ull|lld|ld|lli|li|llo|lo|ll|lf)" | |
scope: constant.character.other.ion | |
# https://en.wikipedia.org/wiki/Printf_format_string | |
- match: "%[.\\-+*0-9#]*(d|i|u|l|f|F|e|E|g|G|x|X|o|a|A|n)" | |
scope: constant.character.other.ion | |
- match: "%[.\\-+*0-9#]*(c|s|p|%)" | |
scope: constant.character.other.ion | |
- match: \\. | |
scope: invalid.illegal.unknown-escape.ion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did a grammar a few days ago:
Here is it:
https://github.com/Platin21/ion.tmbundle