Skip to content

Commit 3d7c73d

Browse files
committed
feat: Add custom VSCode syntax highlighting for .zyn files
Created a VSCode extension for Zyn grammar files with highlighting for: - @metadata blocks (@language, @config, etc.) - Rule definitions and references - Return types (TypedDeclaration, TypedStatement, List, etc.) - JSON semantic action blocks - Command keys (define, get_child, fold_binary, etc.) - Positional arguments ($1, $2, $result) - PEG operators (~, |, *, +, ?, !, &) - Built-in tokens (SOI, EOI, ANY, etc.) Install: ln -s .vscode/extensions/zyn-syntax ~/.vscode/extensions/
1 parent 3b71c6d commit 3d7c73d

5 files changed

Lines changed: 236 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Zyn Grammar Syntax Highlighting
2+
3+
VSCode extension for syntax highlighting of `.zyn` grammar files.
4+
5+
## Installation
6+
7+
### Option 1: Symlink to extensions folder
8+
9+
```bash
10+
ln -s "$(pwd)/.vscode/extensions/zyn-syntax" ~/.vscode/extensions/zyn-syntax
11+
```
12+
13+
Then reload VSCode.
14+
15+
### Option 2: Install via VSIX
16+
17+
```bash
18+
cd .vscode/extensions/zyn-syntax
19+
npx vsce package
20+
code --install-extension zyn-syntax-0.1.0.vsix
21+
```
22+
23+
## Features
24+
25+
- Syntax highlighting for PEG grammar rules
26+
- Highlighting for semantic action blocks (JSON)
27+
- Special highlighting for:
28+
- Rule definitions and references
29+
- JSON command keys (`define`, `get_child`, etc.)
30+
- Positional arguments (`$1`, `$2`, etc.)
31+
- Built-in tokens (`SOI`, `EOI`, `ANY`, etc.)
32+
- Operators (`~`, `|`, `*`, `+`, `?`, etc.)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"comments": {
3+
"lineComment": "//"
4+
},
5+
"brackets": [
6+
["{", "}"],
7+
["[", "]"],
8+
["(", ")"]
9+
],
10+
"autoClosingPairs": [
11+
{ "open": "{", "close": "}" },
12+
{ "open": "[", "close": "]" },
13+
{ "open": "(", "close": ")" },
14+
{ "open": "\"", "close": "\"" }
15+
],
16+
"surroundingPairs": [
17+
{ "open": "{", "close": "}" },
18+
{ "open": "[", "close": "]" },
19+
{ "open": "(", "close": ")" },
20+
{ "open": "\"", "close": "\"" }
21+
]
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "zyn-syntax",
3+
"displayName": "Zyn Grammar Syntax",
4+
"description": "Syntax highlighting for .zyn grammar files",
5+
"version": "0.1.0",
6+
"engines": {
7+
"vscode": "^1.60.0"
8+
},
9+
"categories": ["Programming Languages"],
10+
"contributes": {
11+
"languages": [{
12+
"id": "zyn",
13+
"aliases": ["Zyn Grammar", "zyn"],
14+
"extensions": [".zyn"],
15+
"configuration": "./language-configuration.json"
16+
}],
17+
"grammars": [{
18+
"language": "zyn",
19+
"scopeName": "source.zyn",
20+
"path": "./syntaxes/zyn.tmLanguage.json"
21+
}]
22+
}
23+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "Zyn Grammar",
4+
"scopeName": "source.zyn",
5+
"patterns": [
6+
{ "include": "#comments" },
7+
{ "include": "#metadata-block" },
8+
{ "include": "#rule-definition" },
9+
{ "include": "#semantic-action" },
10+
{ "include": "#strings" },
11+
{ "include": "#operators" },
12+
{ "include": "#keywords" }
13+
],
14+
"repository": {
15+
"comments": {
16+
"patterns": [
17+
{
18+
"name": "comment.line.double-slash.zyn",
19+
"match": "//.*$"
20+
}
21+
]
22+
},
23+
"metadata-block": {
24+
"begin": "(@)(language|config|import|export)\\s*(\\{)",
25+
"end": "\\}",
26+
"beginCaptures": {
27+
"1": { "name": "punctuation.definition.annotation.zyn" },
28+
"2": { "name": "keyword.control.metadata.zyn" },
29+
"3": { "name": "punctuation.section.block.begin.zyn" }
30+
},
31+
"endCaptures": {
32+
"0": { "name": "punctuation.section.block.end.zyn" }
33+
},
34+
"patterns": [
35+
{
36+
"match": "\\b(name|version|file_extensions|entry_point)\\b",
37+
"name": "variable.parameter.zyn"
38+
},
39+
{ "include": "#strings" },
40+
{
41+
"match": "\\[.*?\\]",
42+
"name": "meta.array.zyn"
43+
},
44+
{
45+
"match": ":",
46+
"name": "punctuation.separator.key-value.zyn"
47+
},
48+
{
49+
"match": ",",
50+
"name": "punctuation.separator.comma.zyn"
51+
}
52+
]
53+
},
54+
"rule-definition": {
55+
"patterns": [
56+
{
57+
"match": "^\\s*([a-z_][a-zA-Z0-9_]*)\\s*(=)",
58+
"captures": {
59+
"1": { "name": "entity.name.function.rule.zyn" },
60+
"2": { "name": "keyword.operator.assignment.zyn" }
61+
}
62+
},
63+
{
64+
"match": "\\b([a-z_][a-zA-Z0-9_]*)\\b(?!\\s*=)",
65+
"name": "variable.other.rule-reference.zyn"
66+
}
67+
]
68+
},
69+
"semantic-action": {
70+
"begin": "->\\s*(TypedProgram|TypedDeclaration|TypedStatement|TypedExpression|TypedBlock|TypedParameter|TypedField|TypedVariant|Type|List|String)\\s*\\{",
71+
"end": "\\}",
72+
"beginCaptures": {
73+
"0": { "name": "keyword.operator.arrow.zyn" },
74+
"1": { "name": "entity.name.type.return.zyn" }
75+
},
76+
"contentName": "meta.embedded.block.json",
77+
"patterns": [
78+
{ "include": "#json-content" }
79+
]
80+
},
81+
"json-content": {
82+
"patterns": [
83+
{
84+
"match": "\"(get_child|get_all_children|get_text|parse_int|define|args|commands|fold_binary|operand|operator|index)\"",
85+
"name": "support.function.json-key.zyn"
86+
},
87+
{
88+
"match": "\"\\$[0-9]+\"",
89+
"name": "variable.parameter.positional.zyn"
90+
},
91+
{
92+
"match": "\"\\$result\"",
93+
"name": "variable.parameter.result.zyn"
94+
},
95+
{
96+
"match": "\"[^\"]*\"",
97+
"name": "string.quoted.double.json.zyn"
98+
},
99+
{
100+
"match": "\\b(true|false|null)\\b",
101+
"name": "constant.language.json.zyn"
102+
},
103+
{
104+
"match": "\\b[0-9]+\\b",
105+
"name": "constant.numeric.json.zyn"
106+
},
107+
{
108+
"match": "[\\{\\}\\[\\]:,]",
109+
"name": "punctuation.json.zyn"
110+
}
111+
]
112+
},
113+
"strings": {
114+
"patterns": [
115+
{
116+
"name": "string.quoted.double.zyn",
117+
"match": "\"[^\"]*\""
118+
}
119+
]
120+
},
121+
"operators": {
122+
"patterns": [
123+
{
124+
"match": "~",
125+
"name": "keyword.operator.sequence.zyn"
126+
},
127+
{
128+
"match": "\\|",
129+
"name": "keyword.operator.choice.zyn"
130+
},
131+
{
132+
"match": "[*+?]",
133+
"name": "keyword.operator.quantifier.zyn"
134+
},
135+
{
136+
"match": "!|&",
137+
"name": "keyword.operator.predicate.zyn"
138+
},
139+
{
140+
"match": "@",
141+
"name": "keyword.operator.atomic.zyn"
142+
},
143+
{
144+
"match": "_",
145+
"name": "keyword.operator.silent.zyn"
146+
}
147+
]
148+
},
149+
"keywords": {
150+
"patterns": [
151+
{
152+
"match": "\\b(SOI|EOI|ANY|ASCII_DIGIT|ASCII_ALPHA|ASCII_ALPHANUMERIC|WHITESPACE|COMMENT|NEWLINE)\\b",
153+
"name": "support.constant.builtin.zyn"
154+
}
155+
]
156+
}
157+
}
158+
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"files.associations": {
3-
"*.zyn": "pest"
3+
"*.zyn": "zyn"
44
}
55
}

0 commit comments

Comments
 (0)