@scalar/highlight 0.2.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/CHANGELOG.md +13 -0
- package/README.md +324 -0
- package/dist/all.d.ts +28 -0
- package/dist/all.d.ts.map +1 -0
- package/dist/all.js +105 -0
- package/dist/compat/hljs.d.ts +24 -0
- package/dist/compat/hljs.d.ts.map +1 -0
- package/dist/compat/hljs.js +95 -0
- package/dist/compat/index.d.ts +24 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +21 -0
- package/dist/compat/languages.d.ts +46 -0
- package/dist/compat/languages.d.ts.map +1 -0
- package/dist/compat/languages.js +236 -0
- package/dist/compat/syntax-highlight.d.ts +37 -0
- package/dist/compat/syntax-highlight.d.ts.map +1 -0
- package/dist/compat/syntax-highlight.js +133 -0
- package/dist/core/compile.d.ts +3 -0
- package/dist/core/compile.d.ts.map +1 -0
- package/dist/core/compile.js +142 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/registry.d.ts +14 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +77 -0
- package/dist/core/render.d.ts +67 -0
- package/dist/core/render.d.ts.map +1 -0
- package/dist/core/render.js +216 -0
- package/dist/core/scopes.d.ts +94 -0
- package/dist/core/scopes.d.ts.map +1 -0
- package/dist/core/scopes.js +113 -0
- package/dist/core/tokenize.d.ts +18 -0
- package/dist/core/tokenize.d.ts.map +1 -0
- package/dist/core/tokenize.js +131 -0
- package/dist/core/types.d.ts +99 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +10 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/langs/bash.d.ts +4 -0
- package/dist/langs/bash.d.ts.map +1 -0
- package/dist/langs/bash.js +123 -0
- package/dist/langs/c.d.ts +4 -0
- package/dist/langs/c.d.ts.map +1 -0
- package/dist/langs/c.js +196 -0
- package/dist/langs/clojure.d.ts +4 -0
- package/dist/langs/clojure.d.ts.map +1 -0
- package/dist/langs/clojure.js +213 -0
- package/dist/langs/cpp.d.ts +4 -0
- package/dist/langs/cpp.d.ts.map +1 -0
- package/dist/langs/cpp.js +391 -0
- package/dist/langs/csharp.d.ts +4 -0
- package/dist/langs/csharp.d.ts.map +1 -0
- package/dist/langs/csharp.js +307 -0
- package/dist/langs/css.d.ts +4 -0
- package/dist/langs/css.d.ts.map +1 -0
- package/dist/langs/css.js +94 -0
- package/dist/langs/dart.d.ts +4 -0
- package/dist/langs/dart.d.ts.map +1 -0
- package/dist/langs/dart.js +262 -0
- package/dist/langs/diff.d.ts +10 -0
- package/dist/langs/diff.d.ts.map +1 -0
- package/dist/langs/diff.js +26 -0
- package/dist/langs/dockerfile.d.ts +4 -0
- package/dist/langs/dockerfile.d.ts.map +1 -0
- package/dist/langs/dockerfile.js +308 -0
- package/dist/langs/elixir.d.ts +4 -0
- package/dist/langs/elixir.d.ts.map +1 -0
- package/dist/langs/elixir.js +343 -0
- package/dist/langs/fsharp.d.ts +4 -0
- package/dist/langs/fsharp.d.ts.map +1 -0
- package/dist/langs/fsharp.js +330 -0
- package/dist/langs/go.d.ts +5 -0
- package/dist/langs/go.d.ts.map +1 -0
- package/dist/langs/go.js +90 -0
- package/dist/langs/graphql.d.ts +4 -0
- package/dist/langs/graphql.d.ts.map +1 -0
- package/dist/langs/graphql.js +185 -0
- package/dist/langs/haskell.d.ts +4 -0
- package/dist/langs/haskell.d.ts.map +1 -0
- package/dist/langs/haskell.js +375 -0
- package/dist/langs/html.d.ts +14 -0
- package/dist/langs/html.d.ts.map +1 -0
- package/dist/langs/html.js +71 -0
- package/dist/langs/http.d.ts +4 -0
- package/dist/langs/http.d.ts.map +1 -0
- package/dist/langs/http.js +185 -0
- package/dist/langs/ini.d.ts +4 -0
- package/dist/langs/ini.d.ts.map +1 -0
- package/dist/langs/ini.js +227 -0
- package/dist/langs/java.d.ts +4 -0
- package/dist/langs/java.d.ts.map +1 -0
- package/dist/langs/java.js +178 -0
- package/dist/langs/javascript.d.ts +4 -0
- package/dist/langs/javascript.d.ts.map +1 -0
- package/dist/langs/javascript.js +226 -0
- package/dist/langs/json.d.ts +10 -0
- package/dist/langs/json.d.ts.map +1 -0
- package/dist/langs/json.js +46 -0
- package/dist/langs/kotlin.d.ts +4 -0
- package/dist/langs/kotlin.d.ts.map +1 -0
- package/dist/langs/kotlin.js +220 -0
- package/dist/langs/lua.d.ts +4 -0
- package/dist/langs/lua.d.ts.map +1 -0
- package/dist/langs/lua.js +330 -0
- package/dist/langs/makefile.d.ts +4 -0
- package/dist/langs/makefile.d.ts.map +1 -0
- package/dist/langs/makefile.js +266 -0
- package/dist/langs/markdown.d.ts +11 -0
- package/dist/langs/markdown.d.ts.map +1 -0
- package/dist/langs/markdown.js +71 -0
- package/dist/langs/matlab.d.ts +4 -0
- package/dist/langs/matlab.d.ts.map +1 -0
- package/dist/langs/matlab.js +352 -0
- package/dist/langs/mojo.d.ts +4 -0
- package/dist/langs/mojo.d.ts.map +1 -0
- package/dist/langs/mojo.js +337 -0
- package/dist/langs/nginx.d.ts +4 -0
- package/dist/langs/nginx.d.ts.map +1 -0
- package/dist/langs/nginx.js +168 -0
- package/dist/langs/objectivec.d.ts +4 -0
- package/dist/langs/objectivec.d.ts.map +1 -0
- package/dist/langs/objectivec.js +287 -0
- package/dist/langs/ocaml.d.ts +4 -0
- package/dist/langs/ocaml.d.ts.map +1 -0
- package/dist/langs/ocaml.js +309 -0
- package/dist/langs/perl.d.ts +4 -0
- package/dist/langs/perl.d.ts.map +1 -0
- package/dist/langs/perl.js +435 -0
- package/dist/langs/php.d.ts +4 -0
- package/dist/langs/php.d.ts.map +1 -0
- package/dist/langs/php.js +325 -0
- package/dist/langs/powershell.d.ts +4 -0
- package/dist/langs/powershell.d.ts.map +1 -0
- package/dist/langs/powershell.js +308 -0
- package/dist/langs/python.d.ts +4 -0
- package/dist/langs/python.d.ts.map +1 -0
- package/dist/langs/python.js +350 -0
- package/dist/langs/r.d.ts +4 -0
- package/dist/langs/r.d.ts.map +1 -0
- package/dist/langs/r.js +265 -0
- package/dist/langs/ruby.d.ts +4 -0
- package/dist/langs/ruby.d.ts.map +1 -0
- package/dist/langs/ruby.js +365 -0
- package/dist/langs/rust.d.ts +10 -0
- package/dist/langs/rust.d.ts.map +1 -0
- package/dist/langs/rust.js +116 -0
- package/dist/langs/scala.d.ts +4 -0
- package/dist/langs/scala.d.ts.map +1 -0
- package/dist/langs/scala.js +308 -0
- package/dist/langs/sql.d.ts +5 -0
- package/dist/langs/sql.d.ts.map +1 -0
- package/dist/langs/sql.js +57 -0
- package/dist/langs/swift.d.ts +33 -0
- package/dist/langs/swift.d.ts.map +1 -0
- package/dist/langs/swift.js +256 -0
- package/dist/langs/yaml.d.ts +11 -0
- package/dist/langs/yaml.d.ts.map +1 -0
- package/dist/langs/yaml.js +123 -0
- package/dist/lazy.d.ts +69 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +200 -0
- package/dist/style.css +308 -0
- package/package.json +86 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elixir.
|
|
3
|
+
*
|
|
4
|
+
* Most of the grammar is about the two things Elixir overloads hardest:
|
|
5
|
+
*
|
|
6
|
+
* - Sigils. `~r/…/u`, `~w[…]a` and `~s{…}` accept eight delimiters, and a
|
|
7
|
+
* closer that depends on the opener would need a backreference, which the
|
|
8
|
+
* compiler rejects. So there is one state per delimiter family, and the four
|
|
9
|
+
* paired families nest the way Elixir itself nests them.
|
|
10
|
+
* - `?`. It ends a predicate name (`valid?`) and it opens a codepoint literal
|
|
11
|
+
* (`?a`). Predicate and bang names are matched from their first letter, so
|
|
12
|
+
* they claim their own `?` before the codepoint rule is ever tried at it.
|
|
13
|
+
*
|
|
14
|
+
* Three smaller calls worth knowing about:
|
|
15
|
+
*
|
|
16
|
+
* - A lowercase name behind a module alias is a function, not a field, so
|
|
17
|
+
* `IO.puts "hi"` reads as a call without needing parentheses, while
|
|
18
|
+
* `item.sku` stays a member.
|
|
19
|
+
* - `@moduledoc """…"""` is documentation rather than a string literal — the
|
|
20
|
+
* same call `python.ts` makes for a docstring.
|
|
21
|
+
* - Every `{` pushes a state, so a map or a tuple inside `#{…}` cannot close
|
|
22
|
+
* the interpolation early.
|
|
23
|
+
*
|
|
24
|
+
* Ordinary locals and pattern variables deliberately match no rule and inherit
|
|
25
|
+
* the block foreground. Elixir function heads are patterns rather than name
|
|
26
|
+
* lists, so there is no honest way to pick the bindings out of one.
|
|
27
|
+
*/
|
|
28
|
+
/** Local, function and attribute names. Elixir identifiers are ASCII. */
|
|
29
|
+
const ID = '[a-z_]\\w*';
|
|
30
|
+
/** A name plus the `?`/`!` Elixir lets a function name end in. */
|
|
31
|
+
const NAME = `${ID}[?!]?`;
|
|
32
|
+
/** The operators an atom may name, longest spelling of each shape first. */
|
|
33
|
+
const OPS = '\\{\\}|\\[\\]|\\.\\.\\.?|<>|<=|>=|[=!]==?|=~|\\+\\+?|--?|\\*\\*?|\\|\\||&&|[<>/|]';
|
|
34
|
+
/**
|
|
35
|
+
* A sigil introducer. Lowercase sigils are a single letter; uppercase ones may
|
|
36
|
+
* be several since Elixir 1.15 (`~JSON"…"`).
|
|
37
|
+
*
|
|
38
|
+
* The cap bounds how far each of the ten delimiter rules scans before it gives
|
|
39
|
+
* up on a run of capitals that never reaches a delimiter. That is a constant
|
|
40
|
+
* factor rather than a complexity class — an uncapped `[A-Z]+` is still linear,
|
|
41
|
+
* because each `~` only ever sees its own run — but it is worth up to 2.4x on
|
|
42
|
+
* Node and 3.7x on Bun over capital-heavy input. Six letters is past every
|
|
43
|
+
* sigil anyone ships.
|
|
44
|
+
*/
|
|
45
|
+
const SIGIL = '~(?:[A-Z]{1,6}|[a-z])';
|
|
46
|
+
const elixir = {
|
|
47
|
+
name: 'elixir',
|
|
48
|
+
aliases: ['ex', 'exs'],
|
|
49
|
+
states: {
|
|
50
|
+
root: {
|
|
51
|
+
rules: [
|
|
52
|
+
// `#{` only interpolates inside a literal; in code a `#` always opens a
|
|
53
|
+
// comment, so this rule comes first and needs no guard.
|
|
54
|
+
{ match: '#[^\\n]*', scope: 'comment' },
|
|
55
|
+
// ---- documentation and module attributes ---------------------------
|
|
56
|
+
{
|
|
57
|
+
match: '(@(?:module|type|short)?doc)([ \\t]*)(""")',
|
|
58
|
+
scope: ['decorator', null, 'comment.doc'],
|
|
59
|
+
push: 'doc-heredoc',
|
|
60
|
+
},
|
|
61
|
+
// `@spec`, `@behaviour` and `@timeout` all read as annotations here.
|
|
62
|
+
// A plain `@timeout` is really a compile-time constant, but splitting
|
|
63
|
+
// the two would mean shipping a list of the attributes Elixir defines.
|
|
64
|
+
{ match: `@${ID}`, scope: 'decorator' },
|
|
65
|
+
// ---- heredocs, sigils and strings ----------------------------------
|
|
66
|
+
// Heredocs before their one-character openers, and sigil heredocs
|
|
67
|
+
// before sigil strings, so `~S"""` is not read as `~S"` plus `""`.
|
|
68
|
+
{
|
|
69
|
+
match: `(${SIGIL})(""")`,
|
|
70
|
+
scope: ['string.special', 'string'],
|
|
71
|
+
push: 'heredoc-double',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
match: `(${SIGIL})(''')`,
|
|
75
|
+
scope: ['string.special', 'string'],
|
|
76
|
+
push: 'heredoc-single',
|
|
77
|
+
},
|
|
78
|
+
{ match: '"""', scope: 'string', push: 'heredoc-double' },
|
|
79
|
+
{ match: "'''", scope: 'string', push: 'heredoc-single' },
|
|
80
|
+
// One state per closing delimiter. `~r` bodies are scoped `string`
|
|
81
|
+
// rather than `regexp` for the same reason `ruby.ts` does it for `%r`:
|
|
82
|
+
// telling them apart would double the state count for a colour most
|
|
83
|
+
// themes give the sigil's introducer anyway.
|
|
84
|
+
{
|
|
85
|
+
match: `(${SIGIL})(\\()`,
|
|
86
|
+
scope: ['string.special', 'string'],
|
|
87
|
+
push: 'sigil-paren',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
match: `(${SIGIL})(\\[)`,
|
|
91
|
+
scope: ['string.special', 'string'],
|
|
92
|
+
push: 'sigil-bracket',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
match: `(${SIGIL})(\\{)`,
|
|
96
|
+
scope: ['string.special', 'string'],
|
|
97
|
+
push: 'sigil-brace',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
match: `(${SIGIL})(<)`,
|
|
101
|
+
scope: ['string.special', 'string'],
|
|
102
|
+
push: 'sigil-angle',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
match: `(${SIGIL})(/)`,
|
|
106
|
+
scope: ['string.special', 'string'],
|
|
107
|
+
push: 'sigil-slash',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
match: `(${SIGIL})(\\|)`,
|
|
111
|
+
scope: ['string.special', 'string'],
|
|
112
|
+
push: 'sigil-pipe',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
match: `(${SIGIL})(")`,
|
|
116
|
+
scope: ['string.special', 'string'],
|
|
117
|
+
push: 'string',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
match: `(${SIGIL})(')`,
|
|
121
|
+
scope: ['string.special', 'string'],
|
|
122
|
+
push: 'charlist',
|
|
123
|
+
},
|
|
124
|
+
{ match: '"', scope: 'string', push: 'string' },
|
|
125
|
+
// A charlist. `~c"…"` is the modern spelling and shares the state.
|
|
126
|
+
{ match: "'", scope: 'string', push: 'charlist' },
|
|
127
|
+
// ---- atoms ---------------------------------------------------------
|
|
128
|
+
// The scan stops at the closing quote or the line break, so a stray
|
|
129
|
+
// `:"` costs one line rather than the rest of the file.
|
|
130
|
+
{ match: ':"(?:[^"\\\\\\n]|\\\\.)*"', scope: 'constant' },
|
|
131
|
+
// A name has to follow the colon, which keeps `::` and the `:` of a
|
|
132
|
+
// keyword list out. The vocabulary has no atom scope, so it borrows
|
|
133
|
+
// `constant` — the literal colour, which is where atoms usually land.
|
|
134
|
+
{ match: ':[A-Za-z_]\\w*[?!]?', scope: 'constant' },
|
|
135
|
+
// An operator atom, which AST code is full of: `{:+, [], [1, 2]}`,
|
|
136
|
+
// `[:<>, :{}]`. `ruby.ts` spells the same case the same way. The
|
|
137
|
+
// trailing lookahead is what keeps a keyword-list value out — in
|
|
138
|
+
// `[limit: -1]` the `:-` is a delimiter and a minus sign, and only a
|
|
139
|
+
// real atom is followed straight by whitespace or a closer. `&` and `!`
|
|
140
|
+
// are left out for the same reason: `[by: &fun/1]` keeps its capture.
|
|
141
|
+
{ match: `:(?:${OPS})(?=[\\s,)\\]}])`, scope: 'constant' },
|
|
142
|
+
// A keyword-list key: `do:`, `parts: 3`, `name: "x"`. Ahead of the
|
|
143
|
+
// keyword rules so `do:` is a key rather than a block opener, and it
|
|
144
|
+
// requires no space before the colon so a typespec `sku :: t` is left
|
|
145
|
+
// to the `::` operator. A quoted key (`"a b": 1`) stays a string.
|
|
146
|
+
{ match: `\\b${NAME}(?=:(?![:=]))`, scope: 'property' },
|
|
147
|
+
// ---- keywords ------------------------------------------------------
|
|
148
|
+
{
|
|
149
|
+
match: '(\\b(?:defmodule|defprotocol|defimpl)\\b)([ \\t]+)([A-Z]\\w*(?:\\.[A-Z]\\w*)*)',
|
|
150
|
+
scope: ['keyword.declaration', null, 'namespace'],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
match: `(\\b(?:defp?|defmacrop?|defguardp?|defdelegate)\\b)([ \\t]+)(${NAME})`,
|
|
154
|
+
scope: ['keyword.declaration', null, 'function'],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
match: '\\b(?:def(?:p|macrop?|guardp?|delegate|struct|exception|overridable|impl|protocol|module)?|fn)\\b',
|
|
158
|
+
scope: 'keyword.declaration',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
match: '\\b(?:after|case|catch|cond|do|else|end|for|if|raise|receive|rescue|throw|try|unless|when|with)\\b',
|
|
162
|
+
scope: 'keyword.control',
|
|
163
|
+
},
|
|
164
|
+
// `use` and `require` pull another module in, which reads the way an
|
|
165
|
+
// import does even though only `import` really is one.
|
|
166
|
+
{
|
|
167
|
+
match: '\\b(?:alias|import|require|use)\\b',
|
|
168
|
+
scope: 'keyword.import',
|
|
169
|
+
},
|
|
170
|
+
{ match: '\\b(?:and|in|not|or)\\b', scope: 'keyword.operator' },
|
|
171
|
+
{
|
|
172
|
+
match: '\\b(?:quote|unquote|unquote_splicing|super)\\b',
|
|
173
|
+
scope: 'keyword',
|
|
174
|
+
},
|
|
175
|
+
{ match: '\\b(?:true|false)\\b', scope: 'boolean' },
|
|
176
|
+
{ match: '\\bnil\\b', scope: 'constant.builtin' },
|
|
177
|
+
// `__MODULE__`, `__ENV__`, `__struct__`.
|
|
178
|
+
{ match: '\\b__\\w+__\\b', scope: 'variable.special' },
|
|
179
|
+
// ---- captures ------------------------------------------------------
|
|
180
|
+
// `&1` is the first argument of a capture, which is as close to a
|
|
181
|
+
// parameter as anything in `&(&1.qty > 0)` gets.
|
|
182
|
+
{ match: '&\\d+', scope: 'variable.parameter' },
|
|
183
|
+
// `&handle/2` — a local function reference. The arity is required, so
|
|
184
|
+
// this cannot swallow the `&` of `a && b`.
|
|
185
|
+
{ match: `(&)(${NAME})(?=/\\d)`, scope: ['operator', 'function.call'] },
|
|
186
|
+
// ---- builtins ------------------------------------------------------
|
|
187
|
+
// Ahead of the call rules so `is_map(x)` keeps its builtin colour.
|
|
188
|
+
// Every guard Kernel defines is spelled `is_*`, and `defguard` names
|
|
189
|
+
// follow the convention, so the prefix is cheaper than the list and
|
|
190
|
+
// colours a hand-written guard the same way. It does claim an ordinary
|
|
191
|
+
// function that happens to be called `is_admin`.
|
|
192
|
+
{ match: '\\bis_[a-z_]+(?=\\()', scope: 'function.builtin' },
|
|
193
|
+
{
|
|
194
|
+
match: '\\b(?:abs|apply|byte_size|div|elem|hd|inspect|length|map_size|max|min|rem|round|self|send|spawn|tl|to_string|tuple_size)\\b',
|
|
195
|
+
scope: 'function.builtin',
|
|
196
|
+
},
|
|
197
|
+
// ---- names ---------------------------------------------------------
|
|
198
|
+
// A lowercase name behind a module alias is always a function in
|
|
199
|
+
// Elixir — modules have no fields — so `IO.puts "hi"` is a call even
|
|
200
|
+
// with no parentheses in sight.
|
|
201
|
+
{
|
|
202
|
+
match: `(\\b[A-Z]\\w*)(\\.)(${NAME})`,
|
|
203
|
+
scope: ['namespace', 'punctuation', 'function.method'],
|
|
204
|
+
},
|
|
205
|
+
// `map.fetch(k)` and `&map.fetch/1` on a plain value.
|
|
206
|
+
{
|
|
207
|
+
match: `(\\.)(${NAME})(?=\\(|/\\d)`,
|
|
208
|
+
scope: ['punctuation', 'function.method'],
|
|
209
|
+
},
|
|
210
|
+
{ match: `(\\.)(${NAME})`, scope: ['punctuation', 'variable.member'] },
|
|
211
|
+
// Elixir has no SCREAMING_CASE constants — module attributes fill that
|
|
212
|
+
// role — so every CapWords name is a module alias, and the dot decides
|
|
213
|
+
// whether it is being qualified or used as a value.
|
|
214
|
+
{ match: '\\b[A-Z]\\w*(?=\\.)', scope: 'namespace' },
|
|
215
|
+
{ match: '\\b[A-Z]\\w*', scope: 'type' },
|
|
216
|
+
// A typespec spells its types as zero-arity calls, so the `binary()` of
|
|
217
|
+
// `@spec parse(binary()) :: t()` reads as a call rather than as a type.
|
|
218
|
+
// Telling them apart needs to know that `@spec` opened the line.
|
|
219
|
+
{ match: `\\b${NAME}(?=\\()`, scope: 'function.call' },
|
|
220
|
+
// A parenthesis-free predicate or bang call: `changed?`, `save!`. The
|
|
221
|
+
// lookahead keeps the `a!` of `a!=b` and the `x=~` of a match out.
|
|
222
|
+
{ match: `\\b${ID}[?!](?![=~])`, scope: 'function.call' },
|
|
223
|
+
// ---- literals ------------------------------------------------------
|
|
224
|
+
{ match: '\\b0[xX][0-9a-fA-F_]+\\b', scope: 'number' },
|
|
225
|
+
{ match: '\\b0[bB][01_]+\\b', scope: 'number' },
|
|
226
|
+
{ match: '\\b0[oO][0-7_]+\\b', scope: 'number' },
|
|
227
|
+
// Elixir requires a digit on both sides of the point, so `1..5` stays a
|
|
228
|
+
// range rather than becoming a malformed float.
|
|
229
|
+
{
|
|
230
|
+
match: '\\b\\d[\\d_]*(?:\\.\\d[\\d_]*)?(?:[eE][-+]?\\d+)?\\b',
|
|
231
|
+
scope: 'number',
|
|
232
|
+
},
|
|
233
|
+
// `?a`, `?\n`, `?\x41` — an integer codepoint, not a string. Elixir has
|
|
234
|
+
// no ternary, and a predicate name starts further left and so is always
|
|
235
|
+
// the earlier match, which leaves this rule only the real literals.
|
|
236
|
+
{
|
|
237
|
+
match: '\\?(?:\\\\x\\{?[0-9a-fA-F]+\\}?|\\\\.|[^\\s\\\\])',
|
|
238
|
+
scope: 'number',
|
|
239
|
+
},
|
|
240
|
+
// ---- syntax --------------------------------------------------------
|
|
241
|
+
// Every `{` pushes, so a map inside an interpolation cannot end it.
|
|
242
|
+
{ match: '\\{', scope: 'punctuation.bracket', push: 'brace' },
|
|
243
|
+
{
|
|
244
|
+
match: '\\|\\|\\||&&&|<<<|>>>|\\^\\^\\^|~~~|\\+\\+\\+|---|\\|>|<-|->|=>|<>|<<|>>|\\.\\.\\.|\\.\\.|::|\\|\\||&&|\\+\\+|--|=~|[=!]==?|[<>]=?|\\\\\\\\|[-+*/^&|=!%]',
|
|
245
|
+
scope: 'operator',
|
|
246
|
+
},
|
|
247
|
+
{ match: '[()\\[\\]}]', scope: 'punctuation.bracket' },
|
|
248
|
+
{ match: '[,;:]', scope: 'punctuation.delimiter' },
|
|
249
|
+
{ match: '\\.', scope: 'punctuation' },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
// ---- string bodies -------------------------------------------------------
|
|
253
|
+
/** Shared by every interpolating literal: strings, charlists, heredocs, sigils. */
|
|
254
|
+
'interp-body': {
|
|
255
|
+
rules: [
|
|
256
|
+
{
|
|
257
|
+
match: '\\\\(?:x\\{[0-9a-fA-F]+\\}|x[0-9a-fA-F]{1,2}|u\\{[0-9a-fA-F]+\\}|u[0-9a-fA-F]{4}|.)',
|
|
258
|
+
scope: 'string.escape',
|
|
259
|
+
},
|
|
260
|
+
{ match: '#\\{', scope: 'interpolation', push: 'interpolation' },
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
/**
|
|
264
|
+
* A `"` string, and also `~s"…"`. The trailing letters on the closer are a
|
|
265
|
+
* sigil's modifiers; a plain string is never followed by a bare letter in
|
|
266
|
+
* valid Elixir, so both spellings can share one state.
|
|
267
|
+
*/
|
|
268
|
+
string: {
|
|
269
|
+
default: 'string',
|
|
270
|
+
rules: [
|
|
271
|
+
{ include: 'interp-body' },
|
|
272
|
+
{ match: '"[a-zA-Z]*', pop: true },
|
|
273
|
+
// A single-line literal ends at the line break rather than swallowing
|
|
274
|
+
// the rest of the file. That gives up on the `~s"…"` spelling of a
|
|
275
|
+
// multi-line string, which real code writes as a heredoc anyway.
|
|
276
|
+
{ match: '$', pop: true },
|
|
277
|
+
],
|
|
278
|
+
},
|
|
279
|
+
charlist: {
|
|
280
|
+
default: 'string',
|
|
281
|
+
rules: [{ include: 'interp-body' }, { match: "'[a-zA-Z]*", pop: true }, { match: '$', pop: true }],
|
|
282
|
+
},
|
|
283
|
+
'heredoc-double': {
|
|
284
|
+
default: 'string',
|
|
285
|
+
rules: [{ match: '"""', pop: true }, { include: 'interp-body' }],
|
|
286
|
+
},
|
|
287
|
+
'heredoc-single': {
|
|
288
|
+
default: 'string',
|
|
289
|
+
rules: [{ match: "'''", pop: true }, { include: 'interp-body' }],
|
|
290
|
+
},
|
|
291
|
+
/** A `@doc` body reads as prose, so nothing inside it is picked apart. */
|
|
292
|
+
'doc-heredoc': {
|
|
293
|
+
default: 'comment.doc',
|
|
294
|
+
rules: [{ match: '"""', pop: true }],
|
|
295
|
+
},
|
|
296
|
+
// ---- sigils --------------------------------------------------------------
|
|
297
|
+
// Uppercase sigils do not interpolate, but they share these states with
|
|
298
|
+
// their lowercase twins: a literal `#{` inside `~S(…)` is the price of six
|
|
299
|
+
// states instead of twelve. The letters on the closer are the modifiers.
|
|
300
|
+
'sigil-paren': {
|
|
301
|
+
default: 'string',
|
|
302
|
+
rules: [
|
|
303
|
+
// Paired delimiters nest, so `~w(a (b))` closes on the outer paren.
|
|
304
|
+
{ match: '\\(', push: 'sigil-paren' },
|
|
305
|
+
{ match: '\\)[a-zA-Z]*', pop: true },
|
|
306
|
+
{ include: 'interp-body' },
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
'sigil-bracket': {
|
|
310
|
+
default: 'string',
|
|
311
|
+
rules: [
|
|
312
|
+
{ match: '\\[', push: 'sigil-bracket' },
|
|
313
|
+
{ match: '\\][a-zA-Z]*', pop: true },
|
|
314
|
+
{ include: 'interp-body' },
|
|
315
|
+
],
|
|
316
|
+
},
|
|
317
|
+
'sigil-brace': {
|
|
318
|
+
default: 'string',
|
|
319
|
+
rules: [{ match: '\\{', push: 'sigil-brace' }, { match: '\\}[a-zA-Z]*', pop: true }, { include: 'interp-body' }],
|
|
320
|
+
},
|
|
321
|
+
'sigil-angle': {
|
|
322
|
+
default: 'string',
|
|
323
|
+
rules: [{ match: '<', push: 'sigil-angle' }, { match: '>[a-zA-Z]*', pop: true }, { include: 'interp-body' }],
|
|
324
|
+
},
|
|
325
|
+
'sigil-slash': {
|
|
326
|
+
default: 'string',
|
|
327
|
+
rules: [{ match: '/[a-zA-Z]*', pop: true }, { include: 'interp-body' }],
|
|
328
|
+
},
|
|
329
|
+
'sigil-pipe': {
|
|
330
|
+
default: 'string',
|
|
331
|
+
rules: [{ match: '\\|[a-zA-Z]*', pop: true }, { include: 'interp-body' }],
|
|
332
|
+
},
|
|
333
|
+
// ---- interpolation and braces --------------------------------------------
|
|
334
|
+
interpolation: {
|
|
335
|
+
rules: [{ match: '\\}', scope: 'interpolation', pop: true }, { include: 'root' }],
|
|
336
|
+
},
|
|
337
|
+
/** Tracks brace depth so a map or a tuple cannot close an interpolation. */
|
|
338
|
+
brace: {
|
|
339
|
+
rules: [{ match: '\\}', scope: 'punctuation.bracket', pop: true }, { include: 'root' }],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
export default elixir;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsharp.d.ts","sourceRoot":"","sources":["../../src/langs/fsharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAsD5C,QAAA,MAAM,MAAM,EAAE,OAyTb,CAAA;AAED,eAAe,MAAM,CAAA"}
|