|
1 | 1 | # 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 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 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 |
0 commit comments