Skip to content

Commit 10cf306

Browse files
committed
Interpolation, poly variant spread, parens fixes
1 parent 4687335 commit 10cf306

File tree

3 files changed

+70
-21
lines changed

3 files changed

+70
-21
lines changed

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,31 @@
22

33
The official Sublime Text plugin for ReScript.
44

5+
## Prerequisite
6+
7+
`bs-platform 8.2.0` installed locally in your project.
8+
59
## Install
610

711
Get it from https://packagecontrol.io/packages/ReScript
812

913
## Features
1014

11-
- Highlighting
12-
- Formatting: Command Palette (`cmd-shift-p`) -> ReScript: Format File
15+
- Syntax highlighting (`.res`, `.resi`).
16+
- Formatting: Command Palette (`cmd-shift-p`) -> ReScript: Format File. caveats:
17+
- Currently requires the file to be part of a ReScript project, i.e. with a `bsconfig.json`.
18+
- Cannot be a temporary file.
19+
20+
## Upcoming Features
21+
22+
- Syntax errors diagnosis (only after formatting).
23+
- Formatting of temporary files
24+
- Formatting of files outside of a ReScript project root
25+
- Type diagnosis
1326

1427
## Config
1528

16-
- Command Palette -> UI: Select Color Scheme. Use Mariana for best effects. Or try another one and tell us. Mariana colors tokens distinctively (and still pleasantly) enough for module and variant to be visually distinct despite both being capitalized. Gotta have accurate highlighting!
29+
- Command Palette -> UI: Select Color Scheme. Use **Mariana** for best effects (it'll be the new default Sublime Text theme!). Mariana colors tokens distinctively (and still pleasantly) enough for module and variant to be visually distinct despite both being capitalized. Gotta have accurate highlighting!
1730

1831
<!-- - Open this repo's `Default.sublime-settings`, put in the absolute path to the formatter exe in `optionalGlobalFormatter`. -->
1932

ReScript.sublime-syntax

+24-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,27 @@ contexts:
8686
2: punctuation.definition.string.begin
8787
push:
8888
# different than reason-highlightjs, for now
89+
# interpolation
8990
- meta_scope: string.quoted.other
91+
- match: \${
92+
scope: punctuation.section.interpolation.begin
93+
push:
94+
- clear_scopes: 1
95+
- match: \}
96+
scope: punctuation.section.interpolation.end
97+
pop: true
98+
# TODO: will need expression
99+
- include: operator
100+
- include: punctuations
101+
- match: (\$)
102+
captures:
103+
1: punctuation.section.interpolation
104+
push:
105+
- clear_scopes: 1
106+
- match: '{{RE_IDENT}}'
107+
pop: true
108+
- match: '(?=\S)'
109+
pop: true
90110
- match: '`'
91111
scope: punctuation.definition.string.end
92112
pop: true
@@ -122,9 +142,10 @@ contexts:
122142
# variant and modules confused
123143
# scope: entity.name.union
124144
scope: variable.function variable.other
125-
- match: '(#)[a-zA-Z][0-9a-zA-Z_]*\b'
145+
- match: '(#)(\.\.\.)?[a-zA-Z][0-9a-zA-Z_]*\b'
126146
captures:
127147
1: punctuation.definition.keyword
148+
2: punctuation.definition.keyword
128149

129150
array:
130151
- match: '\['
@@ -209,9 +230,9 @@ contexts:
209230
functorParameter:
210231
- match: \(
211232
push: functorParameter
212-
scope: punctuation.section.braces.begin
233+
scope: punctuation.section.parens.begin
213234
- match: \)
214-
scope: punctuation.section.braces.end
235+
scope: punctuation.section.parens.end
215236
pop: true
216237
- include: moduleAccessEndsWithModule
217238
- include: main

syntax_test.res

+30-15
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ let getCenterCoordinates = (aBla, doHello, ~b=1, ~c, ()) => {
107107
(x, y)
108108
}
109109

110+
a->b(c)->Some
111+
//^^ keyword.operator
112+
// ^^ keyword.operator
113+
110114
type profession = Teacher | Director
111115
// ^ source.res
112116
/* test */
@@ -141,12 +145,12 @@ module Bla = Belt.Map.Make(Bar({type t let a:b = "cc"}))
141145
// ^ source.res entity.name.namespace
142146
// ^ source.res entity.name.namespace
143147
// ^ source.res entity.name.namespace
144-
// ^ source.res punctuation.section.braces.begin
148+
// ^ source.res punctuation.section.parens.begin
145149
// ^ source.res entity.name.namespace
146-
// ^ source.res punctuation.section.braces.begin
150+
// ^ source.res punctuation.section.parens.begin
147151
// ^ source.res storage.type
148-
// ^ source.res punctuation.section.braces.end
149-
// ^ source.res punctuation.section.braces.end
152+
// ^ source.res punctuation.section.parens.end
153+
// ^ source.res punctuation.section.parens.end
150154
module SetOfIntPairs: Foo = MakeSet(IntPair)
151155
// ^ source.res entity.name.namespace
152156
// ^ source.res entity.name.namespace
@@ -269,20 +273,31 @@ let jsx = <div className="foo">
269273
</div>
270274

271275

272-
// Invalid tests
273276
let \"a b" = c
274-
let nope = `hi`
275-
// ^ source.res string.quoted.other punctuation.definition.string.begin
276-
// ^^ source.res string.quoted.other
277-
// ^ source.res string.quoted.other punctuation.definition.string.end
278-
let nope2 = j`hi`
279-
// ^ source.res string.quoted.other variable.annotation
280-
// ^ source.res string.quoted.other punctuation.definition.string.begin
281-
// ^^ source.res string.quoted.other
282-
// ^ source.res string.quoted.other punctuation.definition.string.end
277+
let str = `hi`
278+
// ^ source.res string.quoted.other punctuation.definition.string.begin
279+
// ^^ source.res string.quoted.other
280+
// ^ source.res string.quoted.other punctuation.definition.string.end
281+
let interp = j`hello $bla bye`
282+
// ^ punctuation.section.interpolation
283+
// ^^^ source.res
284+
// ^^^^^ string.quoted.other
285+
let interp = j`hello $1 bye`
286+
// ^^^^^^ string.quoted.other
287+
let interp = j`hello ${world.bla->b(a)} bye`
288+
// ^ source.res string.quoted.other punctuation.definition.string.begin
289+
// ^ source.res string.quoted.other
290+
// ^^ source.res punctuation.section.interpolation.begin
291+
// ^ punctuation.accessor
292+
// ^^ keyword.operator
293+
// ^ punctuation.section.parens.begin
294+
// ^ punctuation.section.interpolation.end
295+
// ^^^ string.quoted.other
296+
// ^ string.quoted.other punctuation.definition.string.end
283297
let variant = #foo
284298
// ^ source.res punctuation.definition.keyword
285-
type a = option<bar>
299+
let #...foo = bar
300+
// ^^^^ punctuation.definition.keyword
286301

287302
@foo(bar) let a = 1
288303
// ^ source.res meta.annotation punctuation.definition.annotation

0 commit comments

Comments
 (0)