Skip to content

Commit ce503a1

Browse files
committed
Allow $ in identifiers
1 parent 699d02b commit ce503a1

File tree

14 files changed

+120
-72
lines changed

14 files changed

+120
-72
lines changed

compiler/frontend/ast_utf8_string_interp.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ type exn += Error of pos * pos * error
6464

6565
let valid_lead_identifier_char x =
6666
match x with
67-
| 'a' .. 'z' | '_' -> true
67+
| 'a' .. 'z' | '_' | '$' -> true
6868
| _ -> false
6969

7070
(** Invariant: [valid_lead_identifier] has to be [valid_identifier] *)
7171
let valid_identifier_char x =
7272
match x with
73-
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '\'' -> true
73+
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '\'' | '$' -> true
7474
| _ -> false
7575

7676
let valid_identifier s =

compiler/syntax/src/res_printer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ let classify_ident_content ?(allow_uident = false) ?(allow_hyphen = false) txt =
406406
match String.unsafe_get txt i with
407407
| '\\' -> UppercaseExoticIdent
408408
| 'A' .. 'Z' when allow_uident -> loop (i + 1)
409-
| 'a' .. 'z' | '_' -> loop (i + 1)
409+
| 'a' .. 'z' | '_' | '$' -> loop (i + 1)
410410
| _ -> ExoticIdent
411411
else
412412
match String.unsafe_get txt i with
413-
| 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '\'' | '_' -> loop (i + 1)
413+
| 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '\'' | '_' | '$' -> loop (i + 1)
414414
| '-' when allow_hyphen -> loop (i + 1)
415415
| _ -> ExoticIdent
416416
in

compiler/syntax/src/res_scanner.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ let scan_identifier scanner =
190190
let start_off = scanner.offset in
191191
let rec skip_good_chars scanner =
192192
match scanner.ch with
193-
| 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '\'' ->
193+
| 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '\'' | '$' ->
194194
next scanner;
195195
skip_good_chars scanner
196196
| _ -> ()
@@ -751,7 +751,7 @@ let rec scan scanner =
751751
let token =
752752
match scanner.ch with
753753
(* peeking 0 char *)
754-
| 'A' .. 'Z' | 'a' .. 'z' -> scan_identifier scanner
754+
| 'A' .. 'Z' | 'a' .. 'z' | '$' -> scan_identifier scanner
755755
| '0' .. '9' -> scan_number scanner
756756
| '`' ->
757757
next scanner;

packages/@rescript/runtime/Primitive_curry.res

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,19 @@ let curry_1 = (o, a0, arity) =>
8787
switch arity {
8888
| 1 => apply1(Obj.magic(o), a0)
8989
| 2 => param => apply2(Obj.magic(o), a0, param)
90-
| 3 => Obj.magic((param, \"param$1") => apply3(Obj.magic(o), a0, param, \"param$1"))
91-
| 4 =>
92-
Obj.magic((param, \"param$1", \"param$2") =>
93-
apply4(Obj.magic(o), a0, param, \"param$1", \"param$2")
94-
)
90+
| 3 => Obj.magic((param, param$1) => apply3(Obj.magic(o), a0, param, param$1))
91+
| 4 => Obj.magic((param, param$1, param$2) => apply4(Obj.magic(o), a0, param, param$1, param$2))
9592
| 5 =>
96-
Obj.magic((param, \"param$1", \"param$2", \"param$3") =>
97-
apply5(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3")
93+
Obj.magic((param, param$1, param$2, param$3) =>
94+
apply5(Obj.magic(o), a0, param, param$1, param$2, param$3)
9895
)
9996
| 6 =>
100-
Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") =>
101-
apply6(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4")
97+
Obj.magic((param, param$1, param$2, param$3, param$4) =>
98+
apply6(Obj.magic(o), a0, param, param$1, param$2, param$3, param$4)
10299
)
103100
| 7 =>
104-
Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5") =>
105-
apply7(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5")
101+
Obj.magic((param, param$1, param$2, param$3, param$4, param$5) =>
102+
apply7(Obj.magic(o), a0, param, param$1, param$2, param$3, param$4, param$5)
106103
)
107104
| _ => Obj.magic(app(o, [a0]))
108105
}
@@ -130,18 +127,16 @@ let curry_2 = (o, a0, a1, arity) =>
130127
| 1 => app(apply1(Obj.magic(o), a0), [a1])
131128
| 2 => apply2(Obj.magic(o), a0, a1)
132129
| 3 => param => apply3(Obj.magic(o), a0, a1, param)
133-
| 4 => Obj.magic((param, \"param$1") => apply4(Obj.magic(o), a0, a1, param, \"param$1"))
130+
| 4 => Obj.magic((param, param$1) => apply4(Obj.magic(o), a0, a1, param, param$1))
134131
| 5 =>
135-
Obj.magic((param, \"param$1", \"param$2") =>
136-
apply5(Obj.magic(o), a0, a1, param, \"param$1", \"param$2")
137-
)
132+
Obj.magic((param, param$1, param$2) => apply5(Obj.magic(o), a0, a1, param, param$1, param$2))
138133
| 6 =>
139-
Obj.magic((param, \"param$1", \"param$2", \"param$3") =>
140-
apply6(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3")
134+
Obj.magic((param, param$1, param$2, param$3) =>
135+
apply6(Obj.magic(o), a0, a1, param, param$1, param$2, param$3)
141136
)
142137
| 7 =>
143-
Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") =>
144-
apply7(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3", \"param$4")
138+
Obj.magic((param, param$1, param$2, param$3, param$4) =>
139+
apply7(Obj.magic(o), a0, a1, param, param$1, param$2, param$3, param$4)
145140
)
146141
| _ => Obj.magic(app(o, [a0, a1]))
147142
}
@@ -170,14 +165,14 @@ let curry_3 = (o, a0, a1, a2, arity) =>
170165
| 2 => app(apply2(Obj.magic(o), a0, a1), [a2])
171166
| 3 => apply3(Obj.magic(o), a0, a1, a2)
172167
| 4 => param => apply4(Obj.magic(o), a0, a1, a2, param)
173-
| 5 => Obj.magic((param, \"param$1") => apply5(Obj.magic(o), a0, a1, a2, param, \"param$1"))
168+
| 5 => Obj.magic((param, param$1) => apply5(Obj.magic(o), a0, a1, a2, param, param$1))
174169
| 6 =>
175-
Obj.magic((param, \"param$1", \"param$2") =>
176-
apply6(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2")
170+
Obj.magic((param, param$1, param$2) =>
171+
apply6(Obj.magic(o), a0, a1, a2, param, param$1, param$2)
177172
)
178173
| 7 =>
179-
Obj.magic((param, \"param$1", \"param$2", \"param$3") =>
180-
apply7(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2", \"param$3")
174+
Obj.magic((param, param$1, param$2, param$3) =>
175+
apply7(Obj.magic(o), a0, a1, a2, param, param$1, param$2, param$3)
181176
)
182177
| _ => Obj.magic(app(o, [a0, a1, a2]))
183178
}
@@ -207,10 +202,10 @@ let curry_4 = (o, a0, a1, a2, a3, arity) =>
207202
| 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3])
208203
| 4 => apply4(Obj.magic(o), a0, a1, a2, a3)
209204
| 5 => param => apply5(Obj.magic(o), a0, a1, a2, a3, param)
210-
| 6 => Obj.magic((param, \"param$1") => apply6(Obj.magic(o), a0, a1, a2, a3, param, \"param$1"))
205+
| 6 => Obj.magic((param, param$1) => apply6(Obj.magic(o), a0, a1, a2, a3, param, param$1))
211206
| 7 =>
212-
Obj.magic((param, \"param$1", \"param$2") =>
213-
apply7(Obj.magic(o), a0, a1, a2, a3, param, \"param$1", \"param$2")
207+
Obj.magic((param, param$1, param$2) =>
208+
apply7(Obj.magic(o), a0, a1, a2, a3, param, param$1, param$2)
214209
)
215210
| _ => Obj.magic(app(o, [a0, a1, a2, a3]))
216211
}
@@ -241,8 +236,7 @@ let curry_5 = (o, a0, a1, a2, a3, a4, arity) =>
241236
| 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4])
242237
| 5 => apply5(Obj.magic(o), a0, a1, a2, a3, a4)
243238
| 6 => param => apply6(Obj.magic(o), a0, a1, a2, a3, a4, param)
244-
| 7 =>
245-
Obj.magic((param, \"param$1") => apply7(Obj.magic(o), a0, a1, a2, a3, a4, param, \"param$1"))
239+
| 7 => Obj.magic((param, param$1) => apply7(Obj.magic(o), a0, a1, a2, a3, a4, param, param$1))
246240
| _ => Obj.magic(app(o, [a0, a1, a2, a3, a4]))
247241
}
248242

tests/syntax_tests/data/parsing/errors/pattern/expected/templateLiteral.res.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111
String interpolation is not supported in pattern matching.
1212

1313

14-
Syntax error!
15-
syntax_tests/data/parsing/errors/pattern/templateLiteral.res:5:33
16-
17-
3 │ switch l {
18-
4 │ | `zero coord ${zeroCoord}` => ()
19-
5 │ | `first coord ${zeroCoord} snd ${zeroCoord} ` => ()
20-
6 │ | _ => ()
21-
7 │ }
22-
23-
Not sure what to do with this character: "$".
24-
25-
2614
Syntax error!
2715
syntax_tests/data/parsing/errors/pattern/templateLiteral.res:5:3-46
2816

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
2-
Syntax error!
3-
syntax_tests/data/parsing/errors/scanner/badCharacter.res:1:5
4-
5-
1 │ let $ = 1
6-
7-
Not sure what to do with this character: "$".
8-
9-
10-
Syntax error!
11-
syntax_tests/data/parsing/errors/scanner/badCharacter.res:1:5-7
12-
13-
1 │ let $ = 1
14-
15-
I was expecting a name for this let-binding. Example: `let message = "hello"`
16-
17-
let 1 = [%rescript.exprhole ]
1+
let ($) = 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let count$ = signal(0)
2+
let $count = count$ + 1
3+
let value$$ = {count$, $count}
4+
let update = {...value$$, count$: $count}
5+
let fn = (~count$, ~on$count) => count$ + on$count
6+
let fromRecord = value$$.count$ + value$$.$count
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let count$ = signal 0
2+
let ($count) = count$ + 1
3+
let value$$ = { count$; ($count) }
4+
let update = { value$$ with count$ = ($count) }
5+
let fn [arity:2]~count$ ~on$count = count$ + on$count
6+
let fromRecord = value$$.count$ + value$$.($count)

tests/syntax_tests/data/ppx/react/expected/v4.res.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ module Rec = {
5757
type props = {}
5858

5959
let rec make = {
60-
let \"make$Internal" = (_: props): React.element => {
60+
let make$Internal = (_: props): React.element => {
6161
make(({}: props))
6262
}
6363
let make = {
64-
let \"V4$Rec" = props => \"make$Internal"(props)
64+
let \"V4$Rec" = props => make$Internal(props)
6565

6666
\"V4$Rec"
6767
}
@@ -74,11 +74,11 @@ module Rec1 = {
7474
type props = {}
7575

7676
let rec make = {
77-
let \"make$Internal" = (_: props): React.element => {
77+
let make$Internal = (_: props): React.element => {
7878
React.null
7979
}
8080
let make = {
81-
let \"V4$Rec1" = props => \"make$Internal"(props)
81+
let \"V4$Rec1" = props => make$Internal(props)
8282

8383
\"V4$Rec1"
8484
}
@@ -91,11 +91,11 @@ module Rec2 = {
9191
type props = {}
9292

9393
let rec make = {
94-
let \"make$Internal" = (_: props): React.element => {
94+
let make$Internal = (_: props): React.element => {
9595
mm(({}: props))
9696
}
9797
let make = {
98-
let \"V4$Rec2" = props => \"make$Internal"(props)
98+
let \"V4$Rec2" = props => make$Internal(props)
9999

100100
\"V4$Rec2"
101101
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let count$ = signal(0)
2+
let $count = count$ + 1
3+
let record$ = {count$, $count}
4+
let access = record$.count$ + record$.$count

0 commit comments

Comments
 (0)