Created
May 12, 2024 10:36
-
-
Save bokunodev/1eb135e3ad5ab161fd7ee0c9579a4289 to your computer and use it in GitHub Desktop.
Hare.sublime-syntax
This file contains hidden or 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 | |
| --- | |
| # http://www.sublimetext.com/docs/syntax.html | |
| name: Hare | |
| file_extensions: | |
| - ha | |
| scope: source.ha | |
| variables: | |
| name: '[A-Za-z_]\w*' | |
| ident: '{{name}}(?:\:\:{{name}})*' | |
| int_suff: '(?>i64|i32|i16|i8|u64|u32|u16|u8|i|u|z)' | |
| float_suff: '(?>f64|f32)' | |
| exponent: '(?:e[-+]?\d+)' | |
| builtin_types: '(?>bool|f32|f64|false|i16|i32|i64|i8|int|never|null|opaque|rune|size|str|true|u16|u32|u64|u8|uint|uintptr|valist|void|done)' | |
| contexts: | |
| main: | |
| - include: comment | |
| - include: use | |
| - include: attributes | |
| - include: declaration | |
| - include: literal | |
| - match: '\b{{builtin_types}}\b' | |
| scope: support.type.ha | |
| # type anotation and type conversion | |
| - match: '(\b(?:as|is)\b|(?<!\:):(?!:))' | |
| captures: | |
| 1: keyword.operator.ha | |
| push: | |
| - match: '(?:(nullable) )?(?:(const) )?(\**(?:\[(?:\*|_|\d*)\])?\**({{ident}}))' | |
| captures: | |
| 1: storage.modifier.ha | |
| 2: storage.modifier.ha | |
| 3: entity.name.type.ha | |
| pop: 1 | |
| - match: '\b(?>break|case|continue|def|defer|else|export|fn|for|if|match|nullable|return|static|switch|yield)\b' | |
| scope: keyword.other.ha | |
| - match: '{{name}}' | |
| scope: variable.other.ha | |
| attributes: | |
| - include: attr_symbol | |
| - include: attr_offset | |
| - include: attr_other | |
| attr_other: | |
| - match: '@(?:fini|init|test|threadlocal)\b' | |
| scope: meta.preprocessor.ha | |
| attr_packed: | |
| - match: '@packed\b' | |
| scope: meta.preprocessor.ha | |
| attr_symbol: | |
| - match: '@symbol\b' | |
| scope: meta.preprocessor.ha | |
| push: | |
| - match: \( | |
| scope: punctuation.section.parens.begin.ha | |
| push: | |
| - include: string_literal | |
| - match: \) | |
| scope: punctuation.section.parens.end.ha | |
| pop: 1 | |
| pop: 1 | |
| attr_offset: | |
| - match: '@offset\b' | |
| scope: meta.preprocessor.ha | |
| push: | |
| - match: \( | |
| scope: punctuation.section.parens.begin.ha | |
| push: | |
| - include: integer_literal | |
| - match: \) | |
| scope: punctuation.section.parens.end.ha | |
| pop: 1 | |
| pop: 1 | |
| declaration: | |
| - include: type_decl | |
| - include: let_decl | |
| - include: const_decl | |
| - include: def_decl | |
| - include: fn_decl | |
| - include: fn_ptr_decl | |
| fn_decl: | |
| - match: '\b(?<=fn) ({{name}})\b' | |
| captures: | |
| 1: entity.name.function.ha | |
| push: _fn_params_ret | |
| fn_ptr_decl: | |
| - match: '\*(fn)\b' | |
| captures: | |
| 1: keyword.other.ha | |
| push: | |
| - match: '\(' | |
| scope: punctuation.section.parens.begin.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: variable.parameter.ha | |
| - match: ':' | |
| push: _type | |
| - match: '\)' | |
| scope: punctuation.section.parens.end.ha | |
| push: _type | |
| pop: 1 | |
| pop: 1 | |
| let_decl: | |
| - match: '\blet\b' | |
| scope: keyword.declaration.variable.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: variable.ha | |
| pop: 1 | |
| - match: '\(' | |
| scope: punctuation.section.parens.begin.ha | |
| push: _tupple | |
| pop: 1 | |
| const_decl: | |
| - match: '\bconst\b' | |
| scope: keyword.declaration.constant.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: entity.name.constant.ha | |
| pop: 1 | |
| - match: '\(' | |
| scope: punctuation.section.parens.begin.ha | |
| push: _tupple | |
| pop: 1 | |
| _tupple: | |
| - match: '{{ident}}' | |
| scope: variable.ha | |
| - match: '\)' | |
| scope: punctuation.section.parens.end.ha | |
| pop: 1 | |
| def_decl: | |
| - match: '\bdef\b' | |
| scope: keyword.declaration.constant.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: entity.name.constant.ha | |
| pop: 1 | |
| type_decl: | |
| - match: '\btype\b' | |
| scope: keyword.declaration.type.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: entity.name.type.ha | |
| pop: 1 | |
| literal: | |
| - include: float_literal | |
| - include: integer_literal | |
| - include: string_literal | |
| - include: rawstring_literal | |
| - include: enum_literal | |
| - include: struct_literal | |
| - include: union_literal | |
| enum_literal: | |
| - match: '\b(enum)(?: ({{name}}))?\b' | |
| captures: | |
| 1: keyword.other.ha | |
| 2: entity.name.type.ha | |
| push: | |
| - match: '\{' | |
| scope: punctuation.section.braces.begin.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: variable.other.member.ha | |
| push: | |
| - include: integer_literal | |
| - match: '=' | |
| scope: keyword.operator.assignment.ha | |
| - match: '(?:,|$)' | |
| scope: punctuation.separator.continuation.ha | |
| pop: 1 | |
| - match: '\}' | |
| scope: punctuation.section.braces.end.ha | |
| - match: ';' | |
| scope: punctuation.terminator.ha | |
| pop: 1 | |
| pop: 1 | |
| struct_literal: | |
| - match: '\bstruct\b' | |
| scope: keyword.other.ha | |
| push: _fields | |
| union_literal: | |
| - match: '\bunion\b' | |
| scope: keyword.other.ha | |
| push: _fields | |
| string_literal: | |
| - meta_content_scope: string.quoted.double.ha | |
| - match: '"' | |
| scope: punctuation.definition.string.begin.ha | |
| push: | |
| - match: '(?:\\.)' | |
| scope: constant.character.escape.ha | |
| - match: '(?:[^"])' | |
| scope: string | |
| # short circuit highlight only one line | |
| - match: '(?:"|$)' | |
| scope: punctuation.definition.string.end.ha | |
| pop: 1 | |
| rawstring_literal: | |
| - meta_content_scope: string.quoted.triple.ha | |
| - match: '`' | |
| scope: punctuation.definition.string.begin.ha | |
| push: | |
| - match: '[^`]' | |
| scope: string | |
| - match: '`' | |
| scope: punctuation.definition.string.end.ha | |
| pop: 1 | |
| integer_literal: | |
| - include: rune_literal | |
| - include: decimal_literal | |
| - include: hexadecimal_literal | |
| - include: octal_literal | |
| - include: binary_literal | |
| rune_literal: | |
| - match: "(?:'(\\\\x\\h{2}|\\\\u\\h{4}|\\\\U\\h{8}|\\\\[0abfnrtv'\"]|[^'])')" | |
| scope: constant.numeric.ha | |
| decimal_literal: | |
| - match: '\b(?:\d+(?:_\d+)?{{int_suff}}?)\b' | |
| scope: constant.numeric.ha | |
| hexadecimal_literal: | |
| - match: '\b(?:0x\h+{{int_suff}}?)\b' | |
| scope: constant.numeric.ha | |
| octal_literal: | |
| - match: '\b(?:0o[0-7]+{{int_suff}}?)\b' | |
| scope: constant.numeric.ha | |
| binary_literal: | |
| - match: '\b(?:0o[01][01]+{{int_suff}}?)\b' | |
| scope: constant.numeric.ha | |
| float_literal: | |
| - match: '\b(?:\d+\.\d+{{exponent}}?{{float_suff}}?)\b' | |
| scope: constant.numeric.ha | |
| use: | |
| - match: '\buse\b' | |
| scope: keyword.import.ha | |
| push: | |
| - match: ';' | |
| scope: punctuation.terminator.ha | |
| pop: 1 | |
| - match: '{{ident}}' | |
| scope: support.module.ha | |
| - match: '=' | |
| scope: keyword.operator.assignment.ha | |
| push: | |
| - match: '{{ident}}' | |
| scope: support.module.ha | |
| pop: 1 | |
| pop: 1 | |
| - match: '::' | |
| scope: punctuation.accessor.double-colon.ha | |
| push: | |
| - match: '\{' | |
| scope: punctuation.section.braces.begin.ha | |
| - match: '{{name}}' | |
| scope: support.module.ha | |
| - match: '\}' | |
| scope: punctuation.section.braces.end.ha | |
| pop: 1 | |
| comment: | |
| - meta_scope: comment.line.double-slash.ha | |
| - match: '//' | |
| scope: punctuation.definition.comment.ha | |
| push: | |
| - match: '\bFIXME:' | |
| scope: string.other.tag.todo.critical | |
| - match: '\bTODO:' | |
| scope: string.other.tag.todo.high | |
| - match: '\bXXX:' | |
| scope: string.other.tag.todo.low | |
| - match: '[^\n]' | |
| scope: comment.ha | |
| - match: '$' | |
| pop: 1 | |
| _type: | |
| - match: '(?:(nullable) )?(?:(const) )?(\**(?:\[(?:\d*|_|\*)\])?\**({{ident}}))' | |
| captures: | |
| 1: storage.modifier.ha | |
| 2: storage.modifier.ha | |
| 3: entity.name.type.ha | |
| pop: 1 | |
| - match: '\(' | |
| push: _tuple_tagged_union | |
| pop: 1 | |
| - match: '\*(fn)\b' | |
| captures: | |
| 1: keyword.other.ha | |
| push: _fn_params_ret | |
| pop: 1 | |
| - match: '\bstruct\b' | |
| scope: keyword.other.ha | |
| push: _fields | |
| pop: 1 | |
| - match: '\bunion\b' | |
| scope: keyword.other.ha | |
| push: _fields | |
| pop: 1 | |
| _tuple_tagged_union: | |
| - match: '(?:(nullable) )?(?:(const) )?(\**(?:\[(?:\d*|_|\*)\])?\**({{ident}}))' | |
| captures: | |
| 1: storage.modifier.ha | |
| 2: storage.modifier.ha | |
| 3: entity.name.type.ha | |
| - match: '(?:,|\|)' | |
| scope: punctuation.separator.sequence.ha | |
| - match: '\)' | |
| scope: punctuation.section.parens.end.ha | |
| pop: 1 | |
| _fn_params_ret: | |
| - match: '\(' | |
| scope: punctuation.section.parens.begin.ha | |
| push: | |
| - match: '{{name}}' | |
| scope: variable.parameter.ha | |
| - match: ':' | |
| push: _type | |
| - match: '\)' | |
| scope: punctuation.section.parens.end.ha | |
| push: _type | |
| pop: 1 | |
| pop: 1 | |
| _fields: | |
| - include: attr_packed | |
| - include: attr_offset | |
| - match: '\{' | |
| push: | |
| - match: '{{name}}' | |
| scope: variable.other.member.ha | |
| push: | |
| - match: ':' | |
| scope: punctuation.definition.annotation.ha | |
| push: _type | |
| pop: 1 | |
| - match: '\}' | |
| scope: punctuation.terminator.ha | |
| pop: 1 | |
| pop: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment