Skip to content

Commit 70bb2ee

Browse files
authored
Added TextMate grammar for Kaleidoscope (#332)
* This allows highlighting in an editor supporting that. - VS does but has a [bug](https://developercommunity.visualstudio.com/t/Text-editor-highligts-matches-even-when/10988990) where it doesn't honor "Show selection matches" * Minor doc readme updates.
1 parent 60bf427 commit 70bb2ee

5 files changed

Lines changed: 96 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ the use of the library.
118118

119119
>[!NOTE]
120120
> Visual Studio Code is NOT officially supported. Such support is welcome as a PR as long as
121-
> it does not impact the use of VS 2022 nor the automated build. [Obviously this comment
121+
> it does not impact the use of VS 20xx nor the automated build. [Obviously this comment
122122
> should be removed if such a PR is made!]
123123
124124
#### Using Visual Studio

src/Samples/Kaleidoscope/Chapter6/mandel.kls

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
# unary operator to perform a logical NOT
12
def unary!(v)
23
if v then
34
0
45
else
56
1;
67

8+
# unary operator to perform a mathematical negation
79
def unary-(v)
810
0-v;
911

12+
# Comparison operator
1013
def binary> 10 (LHS RHS)
1114
RHS < LHS;
1215

16+
# Logical OR operator
1317
def binary| 5 (LHS RHS)
1418
if LHS then
1519
1
@@ -18,17 +22,21 @@ def binary| 5 (LHS RHS)
1822
else
1923
0;
2024

25+
# Logical AND operator
2126
def binary& 6 (LHS RHS)
2227
if !LHS then
2328
0
2429
else
2530
!!RHS;
2631

32+
# arithmatic equality test
2733
def binary== 9 (LHS RHS)
2834
!(LHS < RHS | LHS > RHS);
2935

36+
# selector operator
3037
def binary : 1 (x y) y;
3138

39+
# declare access to built-in function
3240
extern putchard(char);
3341

3442
def printdensity(d)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# TextMate support
2+
This folder provides TextMate Grammar support. It is based on the [HighlightJS](../../../../docfx/templates/Ubiquity/public/Kaleidoscope.js)
3+
grammar used in the documentation template for the site docs. This allows highlighting in
4+
an editor.
5+
6+
## VisualStudio
7+
In Visual Studio copies of subfolders of this folder can be placed into the user profile
8+
folder `.vs/Extensions` to enable syntax highlighting of the Kaleidoscope
9+
language files.
10+
11+
>[!NOTE]
12+
> For Windows the user profile is available in an environment varialbe. In PowerShell that
13+
> is accessed as `$env:userprofile`. In classic CMD prompts it is `%USERPROFILE%`. Normally
14+
> it is `C:\Users\<UserName>` but can vary depending on how your system is set up.
15+
16+
Example:
17+
```
18+
📁 %USERPROFILE%
19+
└─📁 .vs
20+
└─📁 Extensions
21+
└─📁 Kaleidoscope
22+
└─📁 syntaxes
23+
└─📄 Kaleidoscope.plist
24+
```
25+
This will enable syntax highlighting for all Kaleidoscope files (.kls) loaded
26+
after this file is present (any editors without highlighting need to be closed
27+
and re-opened as the set of contributing highlighters is determined once at file load.)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<plist version="1.0">
2+
<dict>
3+
<key>uuid</key>
4+
<string>6F193C25-558C-4DFF-8807-A304287C8EEE</string>
5+
<key>name</key>
6+
<string>Kaleidoscope</string>
7+
<key>scopeName</key>
8+
<string>source.kaleidoscope</string>
9+
<key>fileTypes</key>
10+
<array>
11+
<string>kls</string>
12+
</array>
13+
<key>patterns</key>
14+
<array>
15+
<dict>
16+
<!-- NOTE: In VS these become tagged as "keyword" unless overridden with a custom definition -->
17+
<key>name</key>
18+
<string>keyword.control.kaleidoscope</string>
19+
<key>match</key>
20+
<string>\b(def|extern|if|then|else|for|in|var|unary|binary)\b</string>
21+
</dict>
22+
<dict>
23+
<!-- NOTE: In VS these become tagged as "keyword" unless overridden with a custom definition -->
24+
<key>name</key>
25+
<string>support.function.kaleidoscope</string>
26+
<key>match</key>
27+
<string>\b(putchard|printd)\b</string>
28+
</dict>
29+
<dict>
30+
<!-- NOTE: In VS these become tagged as "comment" unless overridden with a custom definition -->
31+
<key>name</key>
32+
<string>comment.line.number-sign.kaleidoscope</string>
33+
<key>begin</key>
34+
<string>#</string>
35+
<key>end</key>
36+
<string>\n</string>
37+
</dict>
38+
<dict>
39+
<!-- NOTE: In VS these become tagged as "number" unless overridden with a custom definition -->
40+
<key>name</key>
41+
<string>constant.numeric.kaleidoscope</string>
42+
<key>match</key>
43+
<string>-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+)?</string>
44+
</dict>
45+
<dict>
46+
<!-- NOTE: In VS these become tagged as "identifier" unless overridden with a custom definition -->
47+
<key>name</key>
48+
<string>variable.other.kaleidoscope</string>
49+
<key>match</key>
50+
<string>[A-Za-z\$_][0-9A-Za-z\$_]*</string>
51+
</dict>
52+
</array>
53+
</dict>
54+
</plist>

src/Ubiquity.NET.Llvm.slnx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<Project Path="Samples/Kaleidoscope/Kaleidoscope.Grammar/Kaleidoscope.Grammar.csproj" />
6565
<Project Path="Samples/Kaleidoscope/Kaleidoscope.Runtime/Kaleidoscope.Runtime.csproj" />
6666
</Folder>
67+
<Folder Name="/Samples/Kaleidoscope/TextMate/">
68+
<File Path="Samples/Kaleidoscope/TextMate/ReadMe.md" />
69+
</Folder>
70+
<Folder Name="/Samples/Kaleidoscope/TextMate/syntaxes/">
71+
<File Path="Samples/Kaleidoscope/TextMate/syntaxes/Kaleidoscope.plist" />
72+
</Folder>
6773
<Folder Name="/Tests/">
6874
<Project Path="Interop/InteropTests/Ubiquity.NET.Llvm.Interop.UT.csproj" />
6975
<Project Path="Samples/Kaleidoscope/Kaleidoscope.Tests/Kaleidoscope.Tests.csproj" />

0 commit comments

Comments
 (0)