Created
March 8, 2024 01:31
-
-
Save hyrious/5714b101235a4ed00fcf22059be62056 to your computer and use it in GitHub Desktop.
Lezer Parser Grammar in Sublime Text for Itself
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 | |
--- | |
# - https://www.sublimetext.com/docs/syntax.html | |
# - https://lezer.codemirror.net/docs/guide/#writing-a-grammar | |
# - https://github.com/lezer-parser/generator/blob/main/src/parse.ts | |
file_extensions: | |
- grammar | |
name: Lezer | |
scope: source.lezer | |
version: 2 | |
variables: {} | |
contexts: | |
prototype: | |
- include: comments | |
main: | |
- include: externals | |
- include: markers | |
- include: at | |
- include: keywords | |
- include: rules | |
- include: generics | |
- include: character-classes | |
- include: strings | |
- include: symbols | |
markers: | |
- match: '([!~])(\w+)' | |
scope: storage.modifier.lezer | |
captures: | |
1: punctuation.definition.marker.begin.lezer | |
2: entity.name.label.lezer | |
externals: | |
- match: '(@)(context)\s+(\w+)' | |
captures: | |
1: punctuation.definition.annotation.lezer keyword.import.lezer | |
2: keyword.import.lezer | |
3: variable.other.readwrite.lezer | |
- match: '(@)(external)\s+(specialize)\s+(\{)' | |
captures: | |
1: punctuation.definition.annotation.lezer keyword.import.lezer | |
2: keyword.import.lezer | |
3: meta.import-type.lezer keyword.import.lezer | |
4: punctuation.section.group.begin.lezer | |
push: external-specialize-body | |
- match: '(@)(external)\s+(tokens|prop|extend|specialize|propSource)\s+(\w+)' | |
captures: | |
1: punctuation.definition.annotation.lezer keyword.import.lezer | |
2: keyword.import.lezer | |
3: meta.import-type.lezer keyword.import.lezer | |
4: variable.other.readwrite.lezer | |
external-specialize-body: | |
- match: '(\})\s*(\w+)' | |
captures: | |
1: punctuation.section.group.end.lezer | |
2: variable.other.readwrite.lezer | |
pop: true | |
- include: rules | |
- include: strings | |
- include: symbols | |
keywords: | |
- match: '\bfrom\b' | |
scope: keyword.import.from.lezer | |
symbols: | |
- match: '\{' | |
scope: punctuation.section.block.begin.lezer | |
- match: '\}' | |
scope: punctuation.section.block.end.lezer | |
- match: ',' | |
scope: punctuation.separator.comma.lezer | |
- match: '\|' | |
scope: punctuation.separator.lezer | |
- match: '\(' | |
scope: punctuation.section.group.begin.lezer | |
- match: '\)' | |
scope: punctuation.section.group.end.lezer | |
- match: '=' | |
scope: keyword.operator.assignment.lezer | |
- match: '[+\*\?]' | |
scope: keyword.operator.quantifier.lezer | |
at: | |
- match: '(@)\w+' | |
scope: keyword.other.lezer | |
captures: | |
1: punctuation.definition.annotation.lezer | |
rules: | |
- match: '\b([[:upper:]]\w*)' | |
scope: meta.rule.lezer entity.name.function.lezer | |
- match: '\b(\w+)' | |
scope: meta.rule.hidden.lezer entity.name.constant.lezer | |
generics: | |
- match: '\<' | |
scope: punctuation.definition.generic.begin.lezer | |
push: generic-body | |
generic-body: | |
- meta_scope: meta.generic.lezer | |
- match: '\>' | |
scope: punctuation.definition.generic.end.lezer | |
pop: true | |
- match: '\b(\w+)' | |
scope: meta.generic.lezer support.class.lezer | |
- include: strings | |
- include: symbols | |
strings: | |
- match: '"' | |
scope: punctuation.definition.string.begin.lezer | |
push: double-quoted-string-body | |
- match: "'" | |
scope: punctuation.definition.string.begin.lezer | |
push: single-quoted-string-body | |
double-quoted-string-body: | |
- meta_include_prototype: false | |
- meta_scope: meta.string.lezer string.quoted.double.lezer | |
- match: \" | |
scope: punctuation.definition.string.end.lezer | |
pop: true | |
- match: \n | |
scope: invalid.illegal.newline.lezer | |
pop: true | |
- include: string-content | |
single-quoted-string-body: | |
- meta_include_prototype: false | |
- meta_scope: meta.string.lezer string.quoted.single.lezer | |
- match: \' | |
scope: punctuation.definition.string.end.lezer | |
pop: true | |
- match: \n | |
scope: invalid.illegal.newline.lezer | |
pop: true | |
- include: string-content | |
string-content: | |
- match: \\\n | |
scope: constant.character.escape.newline.lezer | |
- match: \\(.) | |
scope: constant.character.escape.lezer | |
character-classes: | |
- match: '[\$\!]\[' | |
scope: punctuation.definition.character-class.begin.lezer | |
push: character-class-body | |
character-class-body: | |
- meta_include_prototype: false | |
- meta_scope: meta.character-class.lezer constant.other.character-class.set.lezer | |
- match: \] | |
scope: punctuation.definition.character-class.end.lezer | |
pop: true | |
- match: |- | |
(?x) | |
(?: | |
(\\[wWsSdD]|\.)| | |
(\\(?:[trnvf0]|c[A-Z]|x[\da-fA-F]{2}|u[\da-fA-F]{4}|.))| | |
. | |
) | |
(\-) | |
(?: | |
(\\[wWsSdD]|\.)| | |
(\\(?:[trnvf0]|c[A-Z]|x[\da-fA-F]{2}|u[\da-fA-F]{4}|.))| | |
[^]] | |
) | |
scope: constant.other.character-class.range.lezer | |
captures: | |
1: constant.other.character-class.escape.backslash.lezer | |
2: constant.character.escape.backslash.lezer | |
3: punctuation.definition.range.lezer | |
4: constant.other.character-class.escape.backslash.lezer | |
5: constant.character.escape.backslash.lezer | |
- match: '\\[wWsSdD]|\.' | |
scope: constant.other.character-class.escape.backslash.lezer | |
- match: '\\([trnvf0\\]|c[A-Z]|x[\da-fA-F]{2}|u[\da-fA-F]{4}|.)' | |
scope: constant.character.escape.backslash.lezer | |
comments: | |
- include: line-comments | |
- include: block-comments | |
line-comments: | |
- match: //+ | |
scope: punctuation.definition.comment.lezer | |
push: line-comment-body | |
line-comment-body: | |
- meta_include_prototype: false | |
- meta_scope: comment.line.double-dash.lezer | |
- match: \n | |
pop: true | |
block-comments: | |
- match: /\*\*+/ | |
scope: comment.block.empty.lezer punctuation.definition.comment.lezer | |
- match: /\*\*+ | |
scope: comment.block.documentation.lezer punctuation.definition.comment.begin.lezer | |
push: doc-comment-body | |
- match: /\* | |
scope: punctuation.definition.comment.begin.lezer | |
push: block-comment-body | |
block-comment-body: | |
- meta_include_prototype: false | |
- meta_scope: comment.block.lezer | |
- include: block-comment-end | |
block-comment-end: | |
- meta_include_prototype: false | |
- match: \*+/ | |
scope: punctuation.definition.comment.end.lezer | |
pop: true | |
doc-comment-body: | |
- meta_include_prototype: false | |
- meta_scope: comment.block.documentation.lezer | |
- include: block-comment-end | |
- match: ^\s*(\*)(?!/) | |
captures: | |
1: punctuation.definition.comment.lezer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment