Skip to content

Commit 6d227ab

Browse files
committed
wip
1 parent f45ec35 commit 6d227ab

File tree

4 files changed

+40
-55
lines changed

4 files changed

+40
-55
lines changed

jscomp/stdlib-406/release.ninja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ o stdlib-406/pervasivesU.cmj : cc_cmi stdlib-406/pervasivesU.res | stdlib-406/pe
6868
o stdlib-406/pervasivesU.cmi : cc stdlib-406/pervasivesU.resi | stdlib-406/pervasives.cmj $bsc others
6969
o stdlib-406/queue.cmj : cc_cmi stdlib-406/queue.res | stdlib-406/queue.cmi $bsc others
7070
o stdlib-406/queue.cmi : cc stdlib-406/queue.resi | stdlib-406/pervasives.cmj $bsc others
71-
o stdlib-406/random.cmj : cc_cmi stdlib-406/random.res | stdlib-406/array.cmj stdlib-406/char.cmj stdlib-406/digest.cmj stdlib-406/int32.cmj stdlib-406/int64.cmj stdlib-406/random.cmi stdlib-406/string.cmj $bsc others
71+
o stdlib-406/random.cmj : cc_cmi stdlib-406/random.res | stdlib-406/array.cmj stdlib-406/char.cmj stdlib-406/digest.cmj stdlib-406/int32.cmj stdlib-406/int64.cmj stdlib-406/random.cmi $bsc others
7272
o stdlib-406/random.cmi : cc stdlib-406/random.resi | stdlib-406/int32.cmi stdlib-406/int64.cmi stdlib-406/pervasives.cmj $bsc others
7373
o stdlib-406/set.cmj : cc_cmi stdlib-406/set.res | stdlib-406/list.cmj stdlib-406/set.cmi $bsc others
7474
o stdlib-406/set.cmi : cc stdlib-406/set.resi | stdlib-406/pervasives.cmj $bsc others

jscomp/syntax/src/res_core.ml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,20 +384,39 @@ let buildLongident words =
384384
| hd :: tl -> List.fold_left (fun p s -> Longident.Ldot (p, s)) (Lident hd) tl
385385

386386
let makeInfixOperator (p : Parser.t) token startPos endPos =
387+
(* FIXME: why this always gonna be true???? *)
388+
let isBinaryOp =
389+
Lexing.(Scanner.isBinaryOp p.scanner.src startPos.pos_cnum endPos.pos_cnum)
390+
in
387391
let stringifiedToken =
388-
if token = Token.MinusGreater then
389-
if p.uncurried_config = Legacy then "|." else "|.u"
390-
else if token = Token.PlusPlus then "^"
391-
else if token = Token.BangEqual then "<>"
392-
else if token = Token.BangEqualEqual then "!="
393-
else if token = Token.Equal then (
394-
(* TODO: could have a totally different meaning like x->fooSet(y)*)
395-
Parser.err ~startPos ~endPos p
396-
(Diagnostics.message "Did you mean `==` here?");
397-
"=")
398-
else if token = Token.EqualEqual then "="
399-
else if token = Token.EqualEqualEqual then "=="
400-
else Token.toString token
392+
if isBinaryOp then
393+
match token with
394+
| Token.Minus ->
395+
print_endline "@@@ binary";
396+
Ext_ident.wrap_exotic "-"
397+
| Token.PlusPlus -> Ext_ident.wrap_exotic "^"
398+
| Token.BangEqual -> Ext_ident.wrap_exotic "<>"
399+
| Token.BangEqualEqual -> Ext_ident.wrap_exotic "!="
400+
| Token.Equal ->
401+
(* TODO: could have a totally different meaning like x->fooSet(y)*)
402+
Parser.err ~startPos ~endPos p
403+
(Diagnostics.message "Did you mean `==` here?");
404+
"="
405+
| Token.EqualEqual -> Ext_ident.wrap_exotic "="
406+
| Token.EqualEqualEqual -> Ext_ident.wrap_exotic "=="
407+
| Token.GreaterThan -> Ext_ident.wrap_exotic ">"
408+
| Token.LessThan -> Ext_ident.wrap_exotic "<"
409+
| token -> Ext_ident.wrap_exotic (Token.toString token)
410+
else
411+
(* unary *)
412+
match token with
413+
| Token.Minus ->
414+
print_endline "@@@ unary";
415+
Ext_ident.wrap_exotic "~-"
416+
| Token.MinusDot -> Ext_ident.wrap_exotic "~-."
417+
| Token.MinusGreater when p.uncurried_config = Legacy -> "|."
418+
| Token.MinusGreater -> "|.u"
419+
| token -> Ext_ident.wrap_exotic (Token.toString token)
401420
in
402421
let loc = mkLoc startPos endPos in
403422
let operator = Location.mkloc (Longident.Lident stringifiedToken) loc in

jscomp/syntax/src/res_scanner.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ let scanExoticIdentifier scanner =
323323
(String.sub [@doesNotRaise]) scanner.src (startOff + 2)
324324
(scanner.offset - startOff - 3)
325325
in
326-
if name = String.empty then (
327-
let endPos = position scanner in
328-
scanner.err ~startPos ~endPos
329-
(Diagnostics.message "A quoted identifier can't be empty string.");
330-
Token.Lident ident)
331-
else if Token.isInfixOperatorTxt name then Token.Lident name
332-
else Token.Lident ident
326+
let _ =
327+
if name = String.empty then
328+
let endPos = position scanner in
329+
scanner.err ~startPos ~endPos
330+
(Diagnostics.message "A quoted identifier can't be empty string.")
331+
in
332+
Token.Lident ident
333333

334334
let scanStringEscapeSequence ~startPos scanner =
335335
let scan ~n ~base ~max =

jscomp/syntax/src/res_token.ml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -257,38 +257,4 @@ let isKeywordTxt str =
257257
true
258258
with Not_found -> false
259259

260-
let infixOperatorTable = function
261-
| "==" -> EqualEqual
262-
| "===" -> EqualEqualEqual
263-
| "-" -> Minus
264-
| "-." -> MinusDot
265-
| "+" -> Plus
266-
| "+." -> PlusDot
267-
| "++" -> PlusPlus
268-
| "/" -> Forwardslash
269-
| "/." -> ForwardslashDot
270-
| ">" -> GreaterThan
271-
| "<" -> LessThan
272-
| "*" -> Asterisk
273-
| "*." -> AsteriskDot
274-
| "**" -> Exponentiation
275-
| "||" -> Lor
276-
| "&&" -> Land
277-
| "!=" -> BangEqual
278-
| "!==" -> BangEqualEqual
279-
| ">=" -> GreaterEqual
280-
| "<=" -> LessEqual
281-
| _ -> raise Not_found
282-
[@@raises Not_found]
283-
284-
let isInfixOperatorTxt str =
285-
match str with
286-
| "=" | "<>" | "^" | "~-" | "~-." | ":=" | "|." | "|.u" | "|>" ->
287-
true (* Allow internally aliases to OCaml ones *)
288-
| _ -> (
289-
try
290-
let _ = infixOperatorTable str in
291-
true
292-
with Not_found -> false)
293-
294260
let catch = Lident "catch"

0 commit comments

Comments
 (0)