moonbit-syntax-highlighter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSE.upstream +21 -0
- package/README.md +73 -0
- package/package.json +63 -0
- package/src/content.d.ts +3 -0
- package/src/content.js +9 -0
- package/src/grammar.d.ts +5 -0
- package/src/grammar.js +10 -0
- package/src/index.d.ts +7 -0
- package/src/index.js +3 -0
- package/src/shiki.d.ts +14 -0
- package/src/shiki.js +17 -0
- package/syntaxes/moonbit.sublime-syntax +550 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nanaloveyuki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE.upstream
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hyrious
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# moonbit-syntax-highlighter
|
|
2
|
+
|
|
3
|
+
Reusable MoonBit syntax grammar package for front-end documentation tooling.
|
|
4
|
+
|
|
5
|
+
This package vendors a MoonBit TextMate-style syntax definition and exposes stable Node-side entry points that documentation tools can consume.
|
|
6
|
+
|
|
7
|
+
It is framework-agnostic by design: the package ships raw grammar access, metadata, and a small registration helper instead of binding itself to a single docs stack.
|
|
8
|
+
|
|
9
|
+
## What This Package Exports
|
|
10
|
+
|
|
11
|
+
- `moonbitGrammarPath`: absolute local path to the vendored `moonbit.sublime-syntax`
|
|
12
|
+
- `moonbitGrammar`: raw grammar file contents as a string
|
|
13
|
+
- `readMoonbitGrammar()`: reads the packaged grammar from disk
|
|
14
|
+
- `moonbitLanguage`: language metadata for consumers that accept a custom language registration object
|
|
15
|
+
- `createMoonbitLanguageRegistration()`: returns metadata plus inline grammar content for tools that prefer in-memory registration
|
|
16
|
+
- `moonbitAliases`: common aliases such as `moonbit`, `mbt`, and `mbti`
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add moonbit-syntax-highlighter
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Basic Usage
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import {
|
|
28
|
+
createMoonbitLanguageRegistration,
|
|
29
|
+
moonbitGrammarPath,
|
|
30
|
+
} from 'moonbit-syntax-highlighter'
|
|
31
|
+
|
|
32
|
+
const language = createMoonbitLanguageRegistration()
|
|
33
|
+
|
|
34
|
+
console.log(language.scopeName)
|
|
35
|
+
console.log(moonbitGrammarPath)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { moonbitGrammar } from 'moonbit-syntax-highlighter/content'
|
|
40
|
+
|
|
41
|
+
console.log(moonbitGrammar.slice(0, 40))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Intended Consumers
|
|
45
|
+
|
|
46
|
+
- Shiki-based documentation sites such as VitePress or Astro
|
|
47
|
+
- Markdown pipelines that can register external TextMate-style grammars
|
|
48
|
+
- Internal tooling that needs a stable MoonBit language metadata entry point
|
|
49
|
+
|
|
50
|
+
## Source and Attribution
|
|
51
|
+
|
|
52
|
+
The vendored syntax source in `syntaxes/moonbit.sublime-syntax` is based on the MIT-licensed MoonBit Sublime syntax project by `hyrious`:
|
|
53
|
+
|
|
54
|
+
- upstream repo: `https://github.com/hyrious/moonbit-syntax-highlight`
|
|
55
|
+
- upstream file: `MoonBit.sublime-syntax`
|
|
56
|
+
|
|
57
|
+
This package preserves upstream attribution in `LICENSE.upstream` and is intended to make the grammar easier to consume from documentation tooling.
|
|
58
|
+
|
|
59
|
+
## Current Scope
|
|
60
|
+
|
|
61
|
+
This first version focuses on packaging and reuse. It does not yet add framework-specific adapters, snapshot tests, or MoonBit-specific semantic highlighting.
|
|
62
|
+
|
|
63
|
+
## Local Development
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm run check
|
|
67
|
+
pnpm run dev
|
|
68
|
+
pnpm run pack:check
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`pnpm run dev` uses Node watch mode to rerun the package self-check whenever files change.
|
|
72
|
+
|
|
73
|
+
`pnpm run pack:check` builds the tarball locally so you can inspect the exact files that would be published.
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "moonbit-syntax-highlighter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable MoonBit syntax grammar package for documentation tooling and front-end highlighters.",
|
|
5
|
+
"author": "Nanaloveyuki",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"packageManager": "pnpm@11.5.3",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Nanaloveyuki/moonbit-syntax-highlighter-npm.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/Nanaloveyuki/moonbit-syntax-highlighter-npm#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Nanaloveyuki/moonbit-syntax-highlighter-npm/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"moonbit",
|
|
19
|
+
"syntax",
|
|
20
|
+
"highlight",
|
|
21
|
+
"shiki",
|
|
22
|
+
"textmate",
|
|
23
|
+
"grammar",
|
|
24
|
+
"vitepress"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"syntaxes",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"LICENSE.upstream"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "node --watch scripts/check.js",
|
|
35
|
+
"check": "node scripts/check.js",
|
|
36
|
+
"pack:check": "pnpm pack --pack-destination .pack"
|
|
37
|
+
},
|
|
38
|
+
"types": "./src/index.d.ts",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./src/index.d.ts",
|
|
42
|
+
"default": "./src/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./grammar": {
|
|
45
|
+
"types": "./src/grammar.d.ts",
|
|
46
|
+
"default": "./src/grammar.js"
|
|
47
|
+
},
|
|
48
|
+
"./content": {
|
|
49
|
+
"types": "./src/content.d.ts",
|
|
50
|
+
"default": "./src/content.js"
|
|
51
|
+
},
|
|
52
|
+
"./shiki": {
|
|
53
|
+
"types": "./src/shiki.d.ts",
|
|
54
|
+
"default": "./src/shiki.js"
|
|
55
|
+
},
|
|
56
|
+
"./syntaxes/moonbit.sublime-syntax": "./syntaxes/moonbit.sublime-syntax",
|
|
57
|
+
"./package.json": "./package.json"
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false,
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/content.d.ts
ADDED
package/src/content.js
ADDED
package/src/grammar.d.ts
ADDED
package/src/grammar.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
|
|
3
|
+
export const moonbitScopeName = 'source.moonbit'
|
|
4
|
+
|
|
5
|
+
export const moonbitAliases = ['moonbit', 'mbt', 'mbti']
|
|
6
|
+
|
|
7
|
+
export const moonbitGrammarPath = fileURLToPath(
|
|
8
|
+
new URL('../syntaxes/moonbit.sublime-syntax', import.meta.url),
|
|
9
|
+
)
|
|
10
|
+
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { moonbitAliases, moonbitGrammarPath, moonbitScopeName } from './grammar.js'
|
|
2
|
+
export { moonbitGrammar, readMoonbitGrammar } from './content.js'
|
|
3
|
+
export {
|
|
4
|
+
createMoonbitLanguageRegistration,
|
|
5
|
+
moonbitLanguage,
|
|
6
|
+
} from './shiki.js'
|
|
7
|
+
export type { MoonbitLanguageRegistration } from './shiki.js'
|
package/src/index.js
ADDED
package/src/shiki.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { moonbitAliases, moonbitGrammarPath, moonbitScopeName } from './grammar.js'
|
|
2
|
+
|
|
3
|
+
export interface MoonbitLanguageRegistration {
|
|
4
|
+
id: 'moonbit'
|
|
5
|
+
name: 'MoonBit'
|
|
6
|
+
scopeName: typeof moonbitScopeName
|
|
7
|
+
aliases: typeof moonbitAliases
|
|
8
|
+
path: typeof moonbitGrammarPath
|
|
9
|
+
grammar: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare const moonbitLanguage: Omit<MoonbitLanguageRegistration, 'grammar'>
|
|
13
|
+
|
|
14
|
+
export declare function createMoonbitLanguageRegistration(): MoonbitLanguageRegistration
|
package/src/shiki.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { moonbitGrammarPath, moonbitScopeName, moonbitAliases } from './grammar.js'
|
|
2
|
+
import { moonbitGrammar } from './content.js'
|
|
3
|
+
|
|
4
|
+
export const moonbitLanguage = {
|
|
5
|
+
id: 'moonbit',
|
|
6
|
+
name: 'MoonBit',
|
|
7
|
+
scopeName: moonbitScopeName,
|
|
8
|
+
aliases: moonbitAliases,
|
|
9
|
+
path: moonbitGrammarPath,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createMoonbitLanguageRegistration() {
|
|
13
|
+
return {
|
|
14
|
+
...moonbitLanguage,
|
|
15
|
+
grammar: moonbitGrammar,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
%YAML 1.2
|
|
2
|
+
---
|
|
3
|
+
# - https://www.sublimetext.com/docs/syntax.html
|
|
4
|
+
# - https://docs.moonbitlang.com/en/latest/language/introduction.html
|
|
5
|
+
# - https://github.com/moonbitlang/moonbit-docs/blob/main/next/_ext/lexer.py
|
|
6
|
+
|
|
7
|
+
file_extensions:
|
|
8
|
+
- mbt
|
|
9
|
+
- mbti
|
|
10
|
+
|
|
11
|
+
first_line_match: |-
|
|
12
|
+
(?xi:
|
|
13
|
+
^ \s* // .*? -\*- .*? \bmoonbit\b .*? -\*- # editorconfig
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
name: MoonBit
|
|
17
|
+
scope: source.moonbit
|
|
18
|
+
version: 2
|
|
19
|
+
|
|
20
|
+
variables:
|
|
21
|
+
# https://docs.moonbitlang.com/en/latest/language/introduction.html#naming-conventions
|
|
22
|
+
ident_lower: '[a-z][\w_]*'
|
|
23
|
+
ident_upper: '[A-Z][\w_]*'
|
|
24
|
+
ident_path: '[a-z][\w_/]*'
|
|
25
|
+
builtin_types: '(?:Eq|Compare|Hash|Show|Logger|Default|ToJson|FromJson|None|Some|ArrayView|Array|FixedArray|Int16|Int64|Int|UInt16|UInt64|UInt|BigInt|Option|Result|BytesView|Bytes?|Bool|Unit|Char|String|Float|Double|Error|Tuple|Hasher|Iter2?|IterResult|Json|Map|Set|StringBuilder|UninitializedArray)'
|
|
26
|
+
op_functions: '(?:not|land|lnot|lor|lxor|op_add|op_sub|op_div|op_mul|op_mod|op_equal|op_shl|op_shr)'
|
|
27
|
+
escaped_char: '\\(?:[nrtb\"''\\]|x\h{2}|o[0-3][0-7]{2}|u\{(?:\h_*){1,6}\})'
|
|
28
|
+
int_suffixes: '[uUlL]+'
|
|
29
|
+
dec_literal: '\d[\d_]*'
|
|
30
|
+
hex_literal: '\h[\h_]*'
|
|
31
|
+
float_exponent: '[eE][+-]?{{dec_literal}}'
|
|
32
|
+
float_power: '[pP][+-]?{{dec_literal}}'
|
|
33
|
+
|
|
34
|
+
contexts:
|
|
35
|
+
prototype:
|
|
36
|
+
- include: comments
|
|
37
|
+
|
|
38
|
+
main:
|
|
39
|
+
- include: statements
|
|
40
|
+
|
|
41
|
+
comments:
|
|
42
|
+
- include: line-comments
|
|
43
|
+
|
|
44
|
+
line-comments:
|
|
45
|
+
- match: ///\s*(@[_\.\w]+)?
|
|
46
|
+
scope: punctuation.definition.comment.moonbit
|
|
47
|
+
captures:
|
|
48
|
+
1: entity.other.attribute-name.documentation.moonbit
|
|
49
|
+
push: doc-comment-body
|
|
50
|
+
- match: //
|
|
51
|
+
scope: punctuation.definition.comment.moonbit
|
|
52
|
+
push: line-comment-body
|
|
53
|
+
- match: '#deprecated\b'
|
|
54
|
+
scope: punctuation.definition.comment.moonbit entity.other.attribute-name.documentation.moonbit
|
|
55
|
+
|
|
56
|
+
# https://docs.moonbitlang.com/en/latest/language/docs.html
|
|
57
|
+
doc-comment-body:
|
|
58
|
+
- meta_include_prototype: false
|
|
59
|
+
- meta_scope: comment.block.documentation.moonbit
|
|
60
|
+
- match: $\n?
|
|
61
|
+
pop: true
|
|
62
|
+
|
|
63
|
+
line-comment-body:
|
|
64
|
+
- meta_include_prototype: false
|
|
65
|
+
- meta_scope: comment.line.double-slash.moonbit
|
|
66
|
+
- match: $\n?
|
|
67
|
+
pop: true
|
|
68
|
+
|
|
69
|
+
statements:
|
|
70
|
+
- include: type-declarations
|
|
71
|
+
- include: function-definitions
|
|
72
|
+
- include: expressions
|
|
73
|
+
|
|
74
|
+
type-declarations:
|
|
75
|
+
- match: \b(type!?)\s+({{ident_upper}})(\[)
|
|
76
|
+
captures:
|
|
77
|
+
1: keyword.declaration.type.moonbit
|
|
78
|
+
2: entity.name.type.moonbit
|
|
79
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
80
|
+
push: type-parameters
|
|
81
|
+
- match: \b(type!?)\s+({{ident_upper}})
|
|
82
|
+
captures:
|
|
83
|
+
1: keyword.declaration.type.moonbit
|
|
84
|
+
2: entity.name.type.moonbit
|
|
85
|
+
- match: \b(impl)\s*(\[)
|
|
86
|
+
captures:
|
|
87
|
+
1: keyword.declaration.trait.moonbit
|
|
88
|
+
2: punctuation.definition.generic.begin.moonbit
|
|
89
|
+
push: type-parameters
|
|
90
|
+
- match: \b(impl)\b
|
|
91
|
+
scope: keyword.declaration.trait.moonbit
|
|
92
|
+
- match: \b(trait)\s+({{ident_upper}})
|
|
93
|
+
captures:
|
|
94
|
+
1: keyword.declaration.trait.moonbit
|
|
95
|
+
2: entity.name.trait.moonbit
|
|
96
|
+
- match: \b(enum)\s+({{ident_upper}})\s*(\[)
|
|
97
|
+
captures:
|
|
98
|
+
1: keyword.declaration.enum.moonbit
|
|
99
|
+
2: entity.name.enum.moonbit
|
|
100
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
101
|
+
push: type-parameters
|
|
102
|
+
- match: \b(enum)\s+({{ident_upper}})
|
|
103
|
+
captures:
|
|
104
|
+
1: keyword.declaration.enum.moonbit
|
|
105
|
+
2: entity.name.enum.moonbit
|
|
106
|
+
- match: \b(struct)\s+({{ident_upper}})\s*(\[)
|
|
107
|
+
captures:
|
|
108
|
+
1: keyword.declaration.struct.moonbit
|
|
109
|
+
2: entity.name.struct.moonbit
|
|
110
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
111
|
+
push: type-parameters
|
|
112
|
+
- match: \b(struct)\s+({{ident_upper}})
|
|
113
|
+
captures:
|
|
114
|
+
1: keyword.declaration.struct.moonbit
|
|
115
|
+
2: entity.name.struct.moonbit
|
|
116
|
+
|
|
117
|
+
function-definitions:
|
|
118
|
+
- match: (\#)({{ident_lower}})\s*(\()
|
|
119
|
+
captures:
|
|
120
|
+
1: punctuation.definition.annotation.moonbit
|
|
121
|
+
2: variable.annotation.moonbit
|
|
122
|
+
3: punctuation.section.group.begin.moonbit
|
|
123
|
+
push: parameters
|
|
124
|
+
- match: (\#)({{ident_lower}})\s*
|
|
125
|
+
captures:
|
|
126
|
+
1: punctuation.definition.annotation.moonbit
|
|
127
|
+
2: variable.annotation.moonbit
|
|
128
|
+
- match: \b(fn)\s+(?:({{ident_upper}})(\:\:))*({{ident_lower}})(!?)\s*(\[)
|
|
129
|
+
captures:
|
|
130
|
+
1: keyword.declaration.function.moonbit
|
|
131
|
+
2: support.type.moonbit
|
|
132
|
+
3: punctuation.accessor.double-colon.moonbit
|
|
133
|
+
4: entity.name.function.moonbit
|
|
134
|
+
5: keyword.declaration.error.moonbit
|
|
135
|
+
6: punctuation.definition.generic.begin.moonbit
|
|
136
|
+
push: type-parameters
|
|
137
|
+
- match: \b(fn)\s+(?:({{ident_upper}})(\:\:))*({{ident_lower}})(!?)\s*(\()
|
|
138
|
+
captures:
|
|
139
|
+
1: keyword.declaration.function.moonbit
|
|
140
|
+
2: support.type.moonbit
|
|
141
|
+
3: punctuation.accessor.double-colon.moonbit
|
|
142
|
+
4: entity.name.function.moonbit
|
|
143
|
+
5: keyword.declaration.error.moonbit
|
|
144
|
+
6: punctuation.section.group.begin.moonbit
|
|
145
|
+
push: parameters
|
|
146
|
+
- match: \b(fn)\s+(main)\s*(\{)
|
|
147
|
+
captures:
|
|
148
|
+
1: keyword.declaration.function.moonbit
|
|
149
|
+
2: keyword.other.moonbit
|
|
150
|
+
3: punctuation.section.block.begin.moonbit
|
|
151
|
+
- match: \b(fn)(!?)\s*(\[)
|
|
152
|
+
captures:
|
|
153
|
+
1: keyword.declaration.function.moonbit
|
|
154
|
+
2: keyword.declaration.interface.moonbit
|
|
155
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
156
|
+
push: type-parameters
|
|
157
|
+
- match: \b(with)\s+({{ident_lower}})\s*(\()
|
|
158
|
+
captures:
|
|
159
|
+
1: keyword.declaration.impl.moonbit
|
|
160
|
+
2: entity.name.function.moonbit
|
|
161
|
+
3: punctuation.section.group.begin.moonbit
|
|
162
|
+
push: parameters
|
|
163
|
+
|
|
164
|
+
type-parameters:
|
|
165
|
+
- match: '(\])\s*(?:({{ident_upper}})(\:\:))*({{ident_lower}})(!?)\s*(\()'
|
|
166
|
+
captures:
|
|
167
|
+
1: punctuation.definition.generic.end.moonbit
|
|
168
|
+
2: support.type.moonbit
|
|
169
|
+
3: punctuation.accessor.double-colon.moonbit
|
|
170
|
+
4: entity.name.function.moonbit
|
|
171
|
+
5: keyword.declaration.error.moonbit
|
|
172
|
+
6: punctuation.section.group.begin.moonbit
|
|
173
|
+
set: parameters
|
|
174
|
+
- match: '(\])\s*(\()'
|
|
175
|
+
captures:
|
|
176
|
+
1: punctuation.definition.generic.end.moonbit
|
|
177
|
+
2: punctuation.section.group.begin.moonbit
|
|
178
|
+
set: parameters
|
|
179
|
+
- match: \(
|
|
180
|
+
scope: punctuation.section.group.begin.moonbit
|
|
181
|
+
push: parameters
|
|
182
|
+
- match: \[
|
|
183
|
+
scope: punctuation.definition.generic.begin.moonbit
|
|
184
|
+
push: type-parameters
|
|
185
|
+
- match: \]
|
|
186
|
+
scope: punctuation.definition.generic.end.moonbit
|
|
187
|
+
pop: true
|
|
188
|
+
- match: '{{ident_upper}}'
|
|
189
|
+
scope: variable.parameter.generic.moonbit
|
|
190
|
+
- include: variables
|
|
191
|
+
- include: operators
|
|
192
|
+
|
|
193
|
+
parameters:
|
|
194
|
+
- match: (\))\s*(->)
|
|
195
|
+
captures:
|
|
196
|
+
1: punctuation.section.group.end.moonbit
|
|
197
|
+
2: storage.type.function.arrow.moonbit
|
|
198
|
+
set: return-type
|
|
199
|
+
- match: \)
|
|
200
|
+
scope: punctuation.section.group.end.moonbit
|
|
201
|
+
pop: true
|
|
202
|
+
- include: expressions
|
|
203
|
+
- match: '\b{{ident_lower}}\b'
|
|
204
|
+
scope: variable.parameter.moonbit
|
|
205
|
+
- match: '\b{{ident_upper}}\b(!?)'
|
|
206
|
+
scope: support.type.moonbit
|
|
207
|
+
captures:
|
|
208
|
+
1: keyword.declaration.error.moonbit
|
|
209
|
+
- match: ':'
|
|
210
|
+
scope: punctuation.separator.type.moonbit
|
|
211
|
+
- match: \(
|
|
212
|
+
scope: punctuation.section.group.begin.moonbit
|
|
213
|
+
push: brace-body
|
|
214
|
+
- match: \[
|
|
215
|
+
scope: punctuation.definition.generic.begin.moonbit
|
|
216
|
+
push: bracket-body
|
|
217
|
+
|
|
218
|
+
return-type:
|
|
219
|
+
- match: $\n?
|
|
220
|
+
pop: true
|
|
221
|
+
- match: \b(raise)\b
|
|
222
|
+
scope: keyword.control.moonbit
|
|
223
|
+
- match: \{
|
|
224
|
+
scope: punctuation.section.block.begin.moonbit
|
|
225
|
+
pop: true
|
|
226
|
+
- match: '='
|
|
227
|
+
scope: keyword.operator.assignment.moonbit
|
|
228
|
+
pop: true
|
|
229
|
+
- match: \!\!
|
|
230
|
+
scope: keyword.declaration.async.moonbit
|
|
231
|
+
- match: \!
|
|
232
|
+
scope: keyword.declaration.error.moonbit
|
|
233
|
+
- match: \?
|
|
234
|
+
scope: keyword.operator.none.moonbit
|
|
235
|
+
- match: '(@)({{ident_path}})'
|
|
236
|
+
captures:
|
|
237
|
+
1: punctuation.definition.variable.moonbit
|
|
238
|
+
2: variable.other.constant.moonbit
|
|
239
|
+
- match: '({{ident_upper}})(\[)'
|
|
240
|
+
captures:
|
|
241
|
+
1: support.type.moonbit
|
|
242
|
+
2: punctuation.definition.generic.begin.moonbit
|
|
243
|
+
push: bracket-body
|
|
244
|
+
- include: types
|
|
245
|
+
|
|
246
|
+
brace-body:
|
|
247
|
+
- match: \)
|
|
248
|
+
scope: punctuation.section.group.end.moonbit
|
|
249
|
+
pop: true
|
|
250
|
+
- include: expressions
|
|
251
|
+
|
|
252
|
+
bracket-body:
|
|
253
|
+
- match: \]
|
|
254
|
+
scope: punctuation.definition.generic.end.moonbit
|
|
255
|
+
pop: true
|
|
256
|
+
- include: type-parameters
|
|
257
|
+
|
|
258
|
+
expressions:
|
|
259
|
+
- include: variables
|
|
260
|
+
- include: strings
|
|
261
|
+
- include: keywords
|
|
262
|
+
- include: function-calls
|
|
263
|
+
- include: braces
|
|
264
|
+
- include: numbers
|
|
265
|
+
- include: operators
|
|
266
|
+
|
|
267
|
+
braces:
|
|
268
|
+
- match: '\)'
|
|
269
|
+
scope: punctuation.section.group.end.moonbit
|
|
270
|
+
pop: true
|
|
271
|
+
- match: '\('
|
|
272
|
+
scope: punctuation.section.group.begin.moonbit
|
|
273
|
+
push: expressions
|
|
274
|
+
|
|
275
|
+
function-calls:
|
|
276
|
+
- match: '\b(not)(\()'
|
|
277
|
+
captures:
|
|
278
|
+
1: keyword.operator.logical.moonbit
|
|
279
|
+
2: punctuation.section.group.begin.moonbit
|
|
280
|
+
push: function-arguments
|
|
281
|
+
- match: '\b({{ident_lower}}!{,2}\??)\s*(\()'
|
|
282
|
+
captures:
|
|
283
|
+
1: variable.function.moonbit
|
|
284
|
+
2: punctuation.section.group.begin.moonbit
|
|
285
|
+
push: function-arguments
|
|
286
|
+
|
|
287
|
+
function-arguments:
|
|
288
|
+
- match: '\)'
|
|
289
|
+
scope: punctuation.section.group.end.moonbit
|
|
290
|
+
pop: true
|
|
291
|
+
- include: expressions
|
|
292
|
+
|
|
293
|
+
variables:
|
|
294
|
+
- match: \b({{ident_upper}})(\:\:)
|
|
295
|
+
captures:
|
|
296
|
+
1: support.type.moonbit
|
|
297
|
+
2: punctuation.accessor.double-colon.moonbit
|
|
298
|
+
- match: '(@)({{ident_path}})'
|
|
299
|
+
captures:
|
|
300
|
+
1: punctuation.definition.variable.moonbit
|
|
301
|
+
2: variable.other.constant.moonbit
|
|
302
|
+
- match: '({{ident_lower}})(~)'
|
|
303
|
+
captures:
|
|
304
|
+
1: entity.name.label.moonbit variable.parameter.moonbit
|
|
305
|
+
2: punctuation.definition.label.moonbit
|
|
306
|
+
- match: '({{ident_lower}})(=)'
|
|
307
|
+
captures:
|
|
308
|
+
1: variable.parameter.moonbit
|
|
309
|
+
2: keyword.operator.assignment.moonbit
|
|
310
|
+
|
|
311
|
+
types:
|
|
312
|
+
- match: \b({{builtin_types}})(!?)\s*(\[)
|
|
313
|
+
captures:
|
|
314
|
+
1: support.type.builtin.moonbit
|
|
315
|
+
2: keyword.declaration.error.moonbit
|
|
316
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
317
|
+
push: type-parameters
|
|
318
|
+
- match: \b({{builtin_types}})\b(!?)(\??)
|
|
319
|
+
scope: support.type.builtin.moonbit
|
|
320
|
+
captures:
|
|
321
|
+
2: keyword.declaration.error.moonbit
|
|
322
|
+
3: keyword.declaration.optional.moonbit
|
|
323
|
+
- match: \b({{ident_upper}})(!?)\s*(\[)
|
|
324
|
+
captures:
|
|
325
|
+
1: storage.type.moonbit
|
|
326
|
+
2: keyword.declaration.error.moonbit
|
|
327
|
+
3: punctuation.definition.generic.begin.moonbit
|
|
328
|
+
push: type-parameters
|
|
329
|
+
- match: \b({{ident_upper}})\b(!?)(\??)
|
|
330
|
+
scope: storage.type.moonbit
|
|
331
|
+
captures:
|
|
332
|
+
2: keyword.declaration.error.moonbit
|
|
333
|
+
3: keyword.declaration.optional.moonbit
|
|
334
|
+
|
|
335
|
+
keywords:
|
|
336
|
+
- match: \b(package)\b
|
|
337
|
+
scope: keyword.declaration.moonbit
|
|
338
|
+
- match: \b(import)\b
|
|
339
|
+
scope: keyword.import.moonbit
|
|
340
|
+
- include: bool
|
|
341
|
+
- match: \b(pub)\((all|open|readonly)\)
|
|
342
|
+
captures:
|
|
343
|
+
1: storage.modifier.moonbit
|
|
344
|
+
2: keyword.other.moonbit
|
|
345
|
+
- match: \b(pub|priv)\b
|
|
346
|
+
scope: storage.modifier.moonbit
|
|
347
|
+
- match: \b(extern|test|init|async|as)\b
|
|
348
|
+
scope: keyword.other.moonbit
|
|
349
|
+
- include: types
|
|
350
|
+
- match: \b(self)\b
|
|
351
|
+
scope: keyword.other.moonbit
|
|
352
|
+
- match: \b(Self)\b
|
|
353
|
+
scope: storage.type.moonbit
|
|
354
|
+
- match: \b(letrec|let|and)\b
|
|
355
|
+
scope: keyword.declaration.variable.moonbit
|
|
356
|
+
- match: \b(const|mut)\b
|
|
357
|
+
scope: storage.modifier.moonbit
|
|
358
|
+
- match: \b(fnalias|fn)\b(!?)
|
|
359
|
+
scope: keyword.declaration.function.moonbit
|
|
360
|
+
captures:
|
|
361
|
+
2: keyword.declaration.error.moonbit
|
|
362
|
+
- match: \b(impl|with|derive)\b
|
|
363
|
+
scope: keyword.declaration.impl.moonbit
|
|
364
|
+
- match: \b(type!?|enum|struct|traitalias|trait|typealias)\b
|
|
365
|
+
scope: keyword.declaration.type.moonbit
|
|
366
|
+
- match: \b(guard|else|for|if|loop|match|while|in)\b
|
|
367
|
+
scope: keyword.control.moonbit
|
|
368
|
+
- match: \b(catch!)
|
|
369
|
+
scope: keyword.control.moonbit
|
|
370
|
+
- match: \b(try|catch|raise)\b
|
|
371
|
+
scope: keyword.control.moonbit
|
|
372
|
+
- match: \b(break|continue)\b
|
|
373
|
+
scope: keyword.control.moonbit
|
|
374
|
+
- match: \b(return)\b
|
|
375
|
+
scope: keyword.control.moonbit
|
|
376
|
+
- match: \b(is)\b
|
|
377
|
+
scope: keyword.other.moonbit
|
|
378
|
+
- match: \b(_)\b
|
|
379
|
+
scope: variable.language.underscore.moonbit
|
|
380
|
+
|
|
381
|
+
# https://docs.moonbitlang.com/en/latest/language/fundamentals.html#boolean
|
|
382
|
+
bool:
|
|
383
|
+
- match: \b(false)\b
|
|
384
|
+
scope: constant.language.boolean.false.moonbit
|
|
385
|
+
- match: \b(true)\b
|
|
386
|
+
scope: constant.language.boolean.true.moonbit
|
|
387
|
+
|
|
388
|
+
# https://docs.moonbitlang.com/en/latest/language/fundamentals.html#number
|
|
389
|
+
numbers:
|
|
390
|
+
- include: floats
|
|
391
|
+
- include: bigints
|
|
392
|
+
- include: integers
|
|
393
|
+
|
|
394
|
+
floats:
|
|
395
|
+
- match: '\b0x({{hex_literal}})\.(?:{{hex_literal}})?(?:{{float_exponent}})?({{float_power}})'
|
|
396
|
+
scope: constant.numeric.float.moonbit
|
|
397
|
+
- match: '\b0x({{hex_literal}})\.({{hex_literal}})(?:{{float_exponent}})?'
|
|
398
|
+
scope: constant.numeric.float.moonbit
|
|
399
|
+
- match: '\b0x({{hex_literal}})({{float_exponent}})\b'
|
|
400
|
+
scope: constant.numeric.float.moonbit
|
|
401
|
+
- match: '\b0x({{hex_literal}})\.(?![A-Za-z._''])'
|
|
402
|
+
scope: constant.numeric.float.moonbit
|
|
403
|
+
- match: '\b({{dec_literal}})\.(?:{{dec_literal}})?(?:{{float_exponent}})?({{float_power}})'
|
|
404
|
+
scope: constant.numeric.float.moonbit
|
|
405
|
+
- match: '\b({{dec_literal}})\.({{dec_literal}})(?:{{float_exponent}})?'
|
|
406
|
+
scope: constant.numeric.float.moonbit
|
|
407
|
+
- match: '\b({{dec_literal}})({{float_exponent}})\b'
|
|
408
|
+
scope: constant.numeric.float.moonbit
|
|
409
|
+
- match: '\b({{dec_literal}})\.(?![A-Za-z._''])'
|
|
410
|
+
scope: constant.numeric.float.moonbit
|
|
411
|
+
|
|
412
|
+
integers:
|
|
413
|
+
- match: '\b({{dec_literal}})({{int_suffixes}})?\b'
|
|
414
|
+
captures:
|
|
415
|
+
1: constant.numeric.integer.decimal.moonbit
|
|
416
|
+
2: constant.numeric.suffix.moonbit
|
|
417
|
+
- match: '\b(0x{{hex_literal}})({{int_suffixes}})?\b'
|
|
418
|
+
captures:
|
|
419
|
+
1: constant.numeric.integer.hexadecimal.moonbit
|
|
420
|
+
2: constant.numeric.suffix.moonbit
|
|
421
|
+
- match: '\b(0o[0-7][0-7_]*)({{int_suffixes}})?\b'
|
|
422
|
+
captures:
|
|
423
|
+
1: constant.numeric.integer.octal.moonbit
|
|
424
|
+
2: constant.numeric.suffix.moonbit
|
|
425
|
+
- match: '\b(0b[0-1][0-1_]*)({{int_suffixes}})?\b'
|
|
426
|
+
captures:
|
|
427
|
+
1: constant.numeric.integer.binary.moonbit
|
|
428
|
+
2: constant.numeric.suffix.moonbit
|
|
429
|
+
|
|
430
|
+
bigints:
|
|
431
|
+
- match: '\b({{dec_literal}})([nN])\b'
|
|
432
|
+
captures:
|
|
433
|
+
1: constant.numeric.integer.decimal.moonbit
|
|
434
|
+
2: constant.numeric.suffix.moonbit
|
|
435
|
+
- match: '\b(0x{{hex_literal}})([nN])\b'
|
|
436
|
+
captures:
|
|
437
|
+
1: constant.numeric.integer.decimal.moonbit
|
|
438
|
+
2: constant.numeric.suffix.moonbit
|
|
439
|
+
|
|
440
|
+
# https://docs.moonbitlang.com/en/latest/language/fundamentals.html#string
|
|
441
|
+
strings:
|
|
442
|
+
- match: '(#\|)?b"'
|
|
443
|
+
scope: punctuation.definition.string.begin.moonbit
|
|
444
|
+
push: binary-string-content
|
|
445
|
+
- match: '"'
|
|
446
|
+
scope: punctuation.definition.string.begin.moonbit
|
|
447
|
+
push: string-content
|
|
448
|
+
- match: '#\|'
|
|
449
|
+
scope: punctuation.definition.string.begin.moonbit
|
|
450
|
+
push: raw-string-content
|
|
451
|
+
- match: '\$\|'
|
|
452
|
+
scope: punctuation.definition.string.begin.moonbit
|
|
453
|
+
push: escape-string-content
|
|
454
|
+
- match: "'"
|
|
455
|
+
scope: punctuation.definition.string.begin.moonbit
|
|
456
|
+
push: char-content
|
|
457
|
+
|
|
458
|
+
raw-string-content:
|
|
459
|
+
- meta_include_prototype: false
|
|
460
|
+
- meta_scope: string.unquoted.moonbit
|
|
461
|
+
- match: $\n?
|
|
462
|
+
pop: true
|
|
463
|
+
|
|
464
|
+
escape-string-content:
|
|
465
|
+
- meta_include_prototype: false
|
|
466
|
+
- meta_scope: string.unquoted.moonbit
|
|
467
|
+
- match: $\n?
|
|
468
|
+
pop: true
|
|
469
|
+
- include: string-interpolations
|
|
470
|
+
- include: escaped-chars
|
|
471
|
+
|
|
472
|
+
string-content:
|
|
473
|
+
- meta_include_prototype: false
|
|
474
|
+
- meta_scope: string.quoted.double.moonbit
|
|
475
|
+
- match: '"'
|
|
476
|
+
scope: punctuation.definition.string.end.moonbit
|
|
477
|
+
pop: true
|
|
478
|
+
- include: string-interpolations
|
|
479
|
+
- include: escaped-chars
|
|
480
|
+
- include: internal-functions
|
|
481
|
+
|
|
482
|
+
internal-functions:
|
|
483
|
+
- match: '%[_\.\w]+'
|
|
484
|
+
scope: keyword.other.moonbit
|
|
485
|
+
|
|
486
|
+
binary-string-content:
|
|
487
|
+
- meta_include_prototype: false
|
|
488
|
+
- meta_scope: string.unquoted.moonbit
|
|
489
|
+
- match: '"'
|
|
490
|
+
scope: punctuation.definition.string.end.moonbit
|
|
491
|
+
pop: true
|
|
492
|
+
- include: escaped-chars
|
|
493
|
+
|
|
494
|
+
char-content:
|
|
495
|
+
- meta_include_prototype: false
|
|
496
|
+
- meta_scope: string.quoted.single.moonbit
|
|
497
|
+
- match: "'"
|
|
498
|
+
scope: punctuation.definition.string.end.moonbit
|
|
499
|
+
pop: true
|
|
500
|
+
- include: escaped-chars
|
|
501
|
+
|
|
502
|
+
string-interpolations:
|
|
503
|
+
- match: '\\{'
|
|
504
|
+
scope: punctuation.section.interpolation.begin.moonbit
|
|
505
|
+
push: string-interpolation-content
|
|
506
|
+
|
|
507
|
+
string-interpolation-content:
|
|
508
|
+
- clear_scopes: true
|
|
509
|
+
- meta_scope: meta.interpolation.moonbit
|
|
510
|
+
- meta_content_scope: source.moonbit.embedded
|
|
511
|
+
- match: '}'
|
|
512
|
+
scope: punctuation.section.interpolation.end.moonbit
|
|
513
|
+
pop: true
|
|
514
|
+
- include: expressions
|
|
515
|
+
|
|
516
|
+
escaped-chars:
|
|
517
|
+
- match: '{{escaped_char}}'
|
|
518
|
+
scope: constant.character.escape.moonbit
|
|
519
|
+
|
|
520
|
+
operators:
|
|
521
|
+
- match: \.\.\.
|
|
522
|
+
scope: keyword.operator.word.moonbit
|
|
523
|
+
- match: '=>'
|
|
524
|
+
scope: keyword.operator.arrow.moonbit
|
|
525
|
+
- match: '->'
|
|
526
|
+
scope: storage.type.function.arrow.moonbit
|
|
527
|
+
- match: ':(?!:)'
|
|
528
|
+
scope: punctuation.separator.moonbit
|
|
529
|
+
- match: '=(?!=)'
|
|
530
|
+
scope: keyword.operator.assignment.moonbit
|
|
531
|
+
- match: '\.\.<|\.\.=|\.\.(?!\.)'
|
|
532
|
+
scope: keyword.operator.range.moonbit
|
|
533
|
+
- match: '~'
|
|
534
|
+
scope: punctuation.definition.label.moonbit
|
|
535
|
+
- match: ','
|
|
536
|
+
scope: punctuation.separator.moonbit
|
|
537
|
+
- match: ';'
|
|
538
|
+
scope: punctuation.terminator.moonbit
|
|
539
|
+
- match: '\.'
|
|
540
|
+
scope: punctuation.accessor.dot.moonbit
|
|
541
|
+
- match: '{'
|
|
542
|
+
scope: punctuation.section.block.begin.moonbit
|
|
543
|
+
- match: '}'
|
|
544
|
+
scope: punctuation.section.block.end.moonbit
|
|
545
|
+
- match: '\?'
|
|
546
|
+
scope: keyword.operator.none.moonbit
|
|
547
|
+
- match: '\+|-|\*|\/|%|\|>|>>|<<|&&|\|\||\&|\||<=?|>=?|==|!='
|
|
548
|
+
scope: keyword.operator.moonbit
|
|
549
|
+
- match: \b{{op_functions}}\b
|
|
550
|
+
scope: keyword.operator.word.moonbit
|