Skip to content

Commit e16b524

Browse files
committedJun 7, 2018
wast-sublime-syntax
1 parent 0af6bf7 commit e16b524

16 files changed

+1219
-0
lines changed
 

‎README.md

+208
Original file line numberDiff line numberDiff line change
@@ -1 +1,209 @@
11
# wast-sublime-syntax
2+
3+
WAST, the [text format][1] of [WebAssembly][2], is a very low-level but
4+
human-readable and writable stack-based language. It is a tree of
5+
[s-expressions][3], generally, though instructions can also be written linearly.
6+
7+
This is a [Sublime Syntax][4] definition for WAST. It requires
8+
[Sublime Text version 3][5] or greater.
9+
10+
<!-- MarkdownTOC autolink=true -->
11+
12+
- [Highlighting examples](#highlighting-examples)
13+
- [Symbols](#symbols)
14+
- [Other meta-features](#other-meta-features)
15+
- [Scopes](#scopes)
16+
- [Limitations](#limitations)
17+
18+
<!-- /MarkdownTOC -->
19+
20+
## Highlighting examples
21+
22+
Using the themes Monokai, Propeller, Welded, and Excelsior
23+
(from [ES Sublime][6]) respectively:
24+
25+
![Using Monokai](https://github.com/bathos/wast-sublime-syntax/raw/master/examples/monokai.png)
26+
![Using Propeller](https://github.com/bathos/wast-sublime-syntax/raw/master/examples/propeller.png)
27+
![Using Welded](https://github.com/bathos/wast-sublime-syntax/raw/master/examples/welded.png)
28+
![Using Excelsior](https://github.com/bathos/wast-sublime-syntax/raw/master/examples/excelsior.png)
29+
30+
I haven’t included any customized themes presently. I may add one later that
31+
highlights s-expressions by depth, since I think it would be an interesting
32+
experiment.
33+
34+
## Symbols
35+
36+
Functions, globals and types will appear in the local symbol list if they have
37+
been given names, but not if they’re anonymous (that is, only referenced by
38+
index).
39+
40+
Exports will appear in both the local and global symbol lists.
41+
42+
## Other meta-features
43+
44+
There is a definition for comments but, presently, no definition for indents. I
45+
still don’t know quite what that should look like — there seem to be some very
46+
different approaches to formatting s-expressions in the wild and I don’t have
47+
enough context yet to know which to choose. (Feedback or PRs welcome.)
48+
49+
## Scopes
50+
51+
The following scopes are provided. Mostly this sticks to TextMate conventions
52+
but with additional precision in some cases and, for certain stuff, minor abuse
53+
of not-quite-applicable-but-common scopes in order to help improve compatibility
54+
with existing color schemes. In particular, I used `storage.type.constant` in
55+
order to force distinct coloring for some things that are semantically not all
56+
“constant”.
57+
58+
- `comment.block.wast`
59+
- `comment.line.wast`
60+
- `constant.character.escape.byte.wast`
61+
- `constant.character.escape.char.wast`
62+
- `constant.numeric.float.wast`
63+
- `constant.numeric.integer.wast`
64+
- `entity.name.export.wast`
65+
- `entity.name.function.wast`
66+
- `entity.name.memory.wast`
67+
- `entity.name.module.import.wast`
68+
- `entity.name.module.wast`
69+
- `entity.name.statement.wast`
70+
- `entity.name.table.wast`
71+
- `entity.name.type.wast`
72+
- `invalid.illegal.wast`
73+
- `keyword.control.conditional.wast`
74+
- `keyword.control.flow.wast`
75+
- `keyword.declaration.offset.wast`
76+
- `keyword.operator.assignment.wast`
77+
- `keyword.operator.word.wast`
78+
- `keyword.other.export.wast`
79+
- `keyword.other.import.wast`
80+
- `keyword.other.module.wast`
81+
- `keyword.other.offset.wast`
82+
- `keyword.other.start.wast`
83+
- `meta.block.conditional.wast`
84+
- `meta.block.loop.wast`
85+
- `meta.block.wast`
86+
- `meta.function-call.wast`
87+
- `meta.group.limit.wast`
88+
- `meta.invocation.wast`
89+
- `meta.s-expression.data.wast`
90+
- `meta.s-expression.elem.wast`
91+
- `meta.s-expression.export-description.wast`
92+
- `meta.s-expression.export.wast`
93+
- `meta.s-expression.expression.wast`
94+
- `meta.s-expression.function.wast`
95+
- `meta.s-expression.functype.wast`
96+
- `meta.s-expression.global.wast`
97+
- `meta.s-expression.globaltype.wast`
98+
- `meta.s-expression.import.wast`
99+
- `meta.s-expression.instruction.wast`
100+
- `meta.s-expression.local.wast`
101+
- `meta.s-expression.memory.wast`
102+
- `meta.s-expression.module.wast`
103+
- `meta.s-expression.offset.wast`
104+
- `meta.s-expression.param.wast`
105+
- `meta.s-expression.result.wast`
106+
- `meta.s-expression.start.begin.wast`
107+
- `meta.s-expression.table.wast`
108+
- `meta.s-expression.type.wast`
109+
- `meta.s-expression.typeuse.wast`
110+
- `punctuation.definition.block.begin.wast`
111+
- `punctuation.definition.block.conditional.begin.wast`
112+
- `punctuation.definition.block.conditional.end.wast`
113+
- `punctuation.definition.block.end.wast`
114+
- `punctuation.definition.block.loop.begin.wast`
115+
- `punctuation.definition.block.loop.end.wast`
116+
- `punctuation.definition.comment.begin.wast`
117+
- `punctuation.definition.comment.end.wast`
118+
- `punctuation.definition.data.begin.wast`
119+
- `punctuation.definition.data.end.wast`
120+
- `punctuation.definition.elem.begin.wast`
121+
- `punctuation.definition.elem.end.wast`
122+
- `punctuation.definition.export.begin.wast`
123+
- `punctuation.definition.export.end.wast`
124+
- `punctuation.definition.exportdesc.begin.wast`
125+
- `punctuation.definition.exportdesc.end.wast`
126+
- `punctuation.definition.expression.begin.wast`
127+
- `punctuation.definition.expression.end.wast`
128+
- `punctuation.definition.function.begin.wast`
129+
- `punctuation.definition.function.end.wast`
130+
- `punctuation.definition.functype.begin.wast`
131+
- `punctuation.definition.functype.end.wast`
132+
- `punctuation.definition.global.begin.wast`
133+
- `punctuation.definition.global.end.wast`
134+
- `punctuation.definition.globaltype.begin.wast`
135+
- `punctuation.definition.globaltype.end.wast`
136+
- `punctuation.definition.import.begin.wast`
137+
- `punctuation.definition.import.end.wast`
138+
- `punctuation.definition.instruction.begin.wast`
139+
- `punctuation.definition.instruction.end.wast`
140+
- `punctuation.definition.local.begin.wast`
141+
- `punctuation.definition.local.end.wast`
142+
- `punctuation.definition.memory.begin.wast`
143+
- `punctuation.definition.memory.end.wast`
144+
- `punctuation.definition.module.begin.wast`
145+
- `punctuation.definition.module.end.wast`
146+
- `punctuation.definition.offset.begin.wast`
147+
- `punctuation.definition.offset.end.wast`
148+
- `punctuation.definition.param.begin.wast`
149+
- `punctuation.definition.param.end.wast`
150+
- `punctuation.definition.result.begin.wast`
151+
- `punctuation.definition.result.end.wast`
152+
- `punctuation.definition.start.begin.wast`
153+
- `punctuation.definition.start.end.wast`
154+
- `punctuation.definition.string.begin.wast`
155+
- `punctuation.definition.string.end.wast`
156+
- `punctuation.definition.table.begin.wast`
157+
- `punctuation.definition.table.end.wast`
158+
- `punctuation.definition.type.begin.wast`
159+
- `punctuation.definition.type.end.wast`
160+
- `punctuation.definition.typeuse.begin.wast`
161+
- `punctuation.definition.typeuse.end.wast`
162+
- `source.wast`
163+
- `storage.modifier.mutable.wast`
164+
- `storage.modifier.result.wast`
165+
- `storage.modifier.type.wast`
166+
- `storage.modifier.wast`
167+
- `storage.type.constant.wast`
168+
- `storage.type.data.wast`
169+
- `storage.type.elem.wast`
170+
- `storage.type.function.wast`
171+
- `storage.type.global.wast`
172+
- `storage.type.local.wast`
173+
- `storage.type.memory.wast`
174+
- `storage.type.param.wast`
175+
- `storage.type.table.wast`
176+
- `storage.type.type.wast`
177+
- `string.quoted.double.wast`
178+
- `support.function.memory.wast`
179+
- `support.function.numeric.wast`
180+
- `support.function.variable.wast`
181+
- `support.type.wast`
182+
- `variable.other.index.wast`
183+
- `variable.other.readwrite.wast`
184+
- `variable.other.wast`
185+
- `variable.parameter.wast`
186+
187+
## Limitations
188+
189+
As with most languages, Sublime Syntax and Text Mate syntax definitions can
190+
model WAST correctly at the lexical level, but newline blindness prevents ideal
191+
scoping of some constructs.
192+
193+
In this case, however, there are not many issues that arise from this — really
194+
there’s just one. Whenever "(" is followed by a keyword, if there is a newline
195+
or a multiline comment between them, this syntax definition will not match that
196+
s-expression correctly. Since it would be unusual/unreadable if there really
197+
were newlines or comments in that position, I haven’t included any special
198+
recovery logic, only this caveat emptor.
199+
200+
Some higher level syntactic constraints are applied, like only allowing one
201+
_start_ field, but plenty of other well-formedness constraints are not applied,
202+
even where they technically could be expressed in terms of Sublime Syntax.
203+
204+
[1]: https://webassembly.github.io/spec/core/text/index.html
205+
[2]: https://webassembly.github.io/spec/core/index.html
206+
[3]: https://en.wikipedia.org/wiki/S-expression
207+
[4]: https://www.sublimetext.com/docs/3/syntax.html
208+
[5]: https://www.sublimetext.com/3
209+
[6]: https://github.com/bathos/Ecmascript-Sublime

‎comments.tmPreferences

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Comments</string>
7+
<key>scope</key>
8+
<string>source.wast</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>shellVariables</key>
12+
<array>
13+
<dict>
14+
<key>name</key>
15+
<string>TM_COMMENT_START</string>
16+
<key>value</key>
17+
<string>;; </string>
18+
</dict>
19+
<dict>
20+
<key>name</key>
21+
<string>TM_COMMENT_START_2</string>
22+
<key>value</key>
23+
<string>(;</string>
24+
</dict>
25+
<dict>
26+
<key>name</key>
27+
<string>TM_COMMENT_END_2</string>
28+
<key>value</key>
29+
<string>;)</string>
30+
</dict>
31+
</array>
32+
</dict>
33+
</dict>
34+
</plist>

‎comments.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
name: Comments
3+
scope: source.wast
4+
settings:
5+
shellVariables:
6+
- name: TM_COMMENT_START
7+
value: ';; '
8+
- name: TM_COMMENT_START_2
9+
value: '(;'
10+
- name: TM_COMMENT_END_2
11+
value: ';)'

‎examples/excelsior.png

336 KB
Loading

‎examples/monokai.png

319 KB
Loading

‎examples/propeller.png

319 KB
Loading

‎examples/welded.png

321 KB
Loading

‎symbol-export.tmPreferences

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Export Symbol</string>
7+
<key>scope</key>
8+
<string>source.wast entity.name.export.wast</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>showInIndexedSymbolList</key>
12+
<integer>1</integer>
13+
<key>showInSymbolList</key>
14+
<integer>1</integer>
15+
<key>symbolTransformation</key>
16+
<string>s/(.+)/module export $1/;</string>
17+
</dict>
18+
</dict>
19+
</plist>

‎symbol-export.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
name: Export Symbol
3+
scope: source.wast entity.name.export.wast
4+
settings:
5+
showInSymbolList: 1
6+
showInIndexedSymbolList: 1
7+
symbolTransformation: s/(.+)/module export $1/;

‎symbol-function.tmPreferences

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Function Symbol</string>
7+
<key>scope</key>
8+
<string>source.wast entity.name.function.wast</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>showInIndexedSymbolList</key>
12+
<integer>0</integer>
13+
<key>showInSymbolList</key>
14+
<integer>1</integer>
15+
<key>symbolTransformation</key>
16+
<string>s/(.+)/func $1/;</string>
17+
</dict>
18+
</dict>
19+
</plist>

‎symbol-function.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
name: Function Symbol
3+
scope: source.wast entity.name.function.wast
4+
settings:
5+
showInSymbolList: 1
6+
showInIndexedSymbolList: 0
7+
symbolTransformation: s/(.+)/func $1/;

‎symbol-global.tmPreferences

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Global Symbol</string>
7+
<key>scope</key>
8+
<string>source.wast meta.s-expression.global.wast variable.other.wast</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>showInIndexedSymbolList</key>
12+
<integer>0</integer>
13+
<key>showInSymbolList</key>
14+
<integer>1</integer>
15+
<key>symbolTransformation</key>
16+
<string>s/(.+)/global $1/;</string>
17+
</dict>
18+
</dict>
19+
</plist>

‎symbol-global.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
name: Global Symbol
3+
scope: source.wast meta.s-expression.global.wast variable.other.wast
4+
settings:
5+
showInSymbolList: 1
6+
showInIndexedSymbolList: 0
7+
symbolTransformation: s/(.+)/global $1/;

‎symbol-type.tmPreferences

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Type Symbol</string>
7+
<key>scope</key>
8+
<string>source.wast entity.name.type.wast</string>
9+
<key>settings</key>
10+
<dict>
11+
<key>showInIndexedSymbolList</key>
12+
<integer>0</integer>
13+
<key>showInSymbolList</key>
14+
<integer>1</integer>
15+
<key>symbolTransformation</key>
16+
<string>s/(.+)/type $1/;</string>
17+
</dict>
18+
</dict>
19+
</plist>

‎symbol-type.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [PackageDev] target_format: plist, ext: tmPreferences
2+
name: Type Symbol
3+
scope: source.wast entity.name.type.wast
4+
settings:
5+
showInSymbolList: 1
6+
showInIndexedSymbolList: 0
7+
symbolTransformation: s/(.+)/type $1/;

‎wast.sublime-syntax

+862
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.