From d34d6e98b84460d2b755a9e9b1b3e9a126c9b45a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sun, 3 Jul 2022 17:57:14 +0200 Subject: [PATCH 1/2] Remove "export". --- src/res_core.ml | 69 ------------------ src/res_grammar.ml | 6 +- src/res_token.ml | 10 +-- .../parsing/errors/signature/consecutive.resi | 3 - .../signature/expected/consecutive.resi.txt | 25 ------- .../grammar/ffi/expected/export.res.txt | 72 +++++++++++++++---- tests/parsing/other/expected/gentype.res.txt | 25 ++++++- tests/printer/ffi/expected/export.res.txt | 63 +++++++++++++--- 8 files changed, 139 insertions(+), 134 deletions(-) delete mode 100644 tests/parsing/errors/signature/consecutive.resi delete mode 100644 tests/parsing/errors/signature/expected/consecutive.resi.txt diff --git a/src/res_core.ml b/src/res_core.ml index 8c29149c..1fd5f5f2 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -2403,17 +2403,6 @@ and parseLetBindings ~attrs p = match p.Parser.token with | And -> Parser.next p; - let attrs = - match p.token with - | Export -> - let exportLoc = mkLoc p.startPos p.endPos in - Parser.next p; - let genTypeAttr = - (Location.mkloc "genType" exportLoc, Parsetree.PStr []) - in - genTypeAttr :: attrs - | _ -> attrs - in ignore (Parser.optional p Let); (* overparse for fault tolerance *) let letBinding = parseLetBindingBody ~startPos ~attrs p in @@ -5138,17 +5127,6 @@ and parseTypeDefinitions ~attrs ~name ~params ~startPos p = match p.Parser.token with | And -> Parser.next p; - let attrs = - match p.token with - | Export -> - let exportLoc = mkLoc p.startPos p.endPos in - Parser.next p; - let genTypeAttr = - (Location.mkloc "genType" exportLoc, Parsetree.PStr []) - in - genTypeAttr :: attrs - | _ -> attrs - in let typeDef = parseTypeDef ~attrs ~startPos p in loop p (typeDef :: defs) | _ -> List.rev defs @@ -5321,11 +5299,6 @@ and parseStructureItemRegion p = parseNewlineOrSemicolonStructure p; let loc = mkLoc startPos p.prevEndPos in Some (Ast_helper.Str.include_ ~loc includeStatement) - | Export -> - let structureItem = parseJsExport ~attrs p in - parseNewlineOrSemicolonStructure p; - let loc = mkLoc startPos p.prevEndPos in - Some {structureItem with pstr_loc = loc} | Module -> Parser.beginRegion p; let structureItem = parseModuleOrModuleTypeImplOrPackExpr ~attrs p in @@ -5372,43 +5345,6 @@ and parseStructureItemRegion p = | _ -> None) [@@progress Parser.next, Parser.expect] -and parseJsExport ~attrs p = - let exportStart = p.Parser.startPos in - Parser.expect Token.Export p; - let exportLoc = mkLoc exportStart p.prevEndPos in - let genTypeAttr = (Location.mkloc "genType" exportLoc, Parsetree.PStr []) in - let attrs = genTypeAttr :: attrs in - match p.Parser.token with - | Typ -> ( - match parseTypeDefinitionOrExtension ~attrs p with - | TypeDef {recFlag; types} -> Ast_helper.Str.type_ recFlag types - | TypeExt ext -> Ast_helper.Str.type_extension ext) - (* Let *) - | _ -> - let recFlag, letBindings = parseLetBindings ~attrs p in - Ast_helper.Str.value recFlag letBindings - -and parseSignJsExport ~attrs p = - let exportStart = p.Parser.startPos in - Parser.expect Token.Export p; - let exportLoc = mkLoc exportStart p.prevEndPos in - let genTypeAttr = (Location.mkloc "genType" exportLoc, Parsetree.PStr []) in - let attrs = genTypeAttr :: attrs in - match p.Parser.token with - | Typ -> ( - match parseTypeDefinitionOrExtension ~attrs p with - | TypeDef {recFlag; types} -> - let loc = mkLoc exportStart p.prevEndPos in - Ast_helper.Sig.type_ recFlag types ~loc - | TypeExt ext -> - let loc = mkLoc exportStart p.prevEndPos in - Ast_helper.Sig.type_extension ext ~loc) - (* Let *) - | _ -> - let valueDesc = parseSignLetDesc ~attrs p in - let loc = mkLoc exportStart p.prevEndPos in - Ast_helper.Sig.value valueDesc ~loc - (* include-statement ::= include module-expr *) and parseIncludeStatement ~attrs p = let startPos = p.Parser.startPos in @@ -5952,11 +5888,6 @@ and parseSignatureItemRegion p = parseNewlineOrSemicolonSignature p; let loc = mkLoc startPos p.prevEndPos in Some (Ast_helper.Sig.value ~loc externalDef) - | Export -> - let signatureItem = parseSignJsExport ~attrs p in - parseNewlineOrSemicolonSignature p; - let loc = mkLoc startPos p.prevEndPos in - Some {signatureItem with psig_loc = loc} | Exception -> let exceptionDef = parseExceptionDef ~attrs p in parseNewlineOrSemicolonSignature p; diff --git a/src/res_grammar.ml b/src/res_grammar.ml index 63cf3e55..44f0e497 100644 --- a/src/res_grammar.ml +++ b/src/res_grammar.ml @@ -123,7 +123,7 @@ let toString = function let isSignatureItemStart = function | Token.At | Let | Typ | External | Exception | Open | Include | Module | AtAt - | Export | PercentPercent -> + | PercentPercent -> true | _ -> false @@ -160,8 +160,8 @@ let isJsxAttributeStart = function | _ -> false let isStructureItemStart = function - | Token.Open | Let | Typ | External | Export | Exception | Include | Module - | AtAt | PercentPercent | At -> + | Token.Open | Let | Typ | External | Exception | Include | Module | AtAt + | PercentPercent | At -> true | t when isExprStart t -> true | _ -> false diff --git a/src/res_token.ml b/src/res_token.ml index a0263160..4955d763 100644 --- a/src/res_token.ml +++ b/src/res_token.ml @@ -93,7 +93,6 @@ type t = | Backtick | BarGreater | Try - | Export | DocComment of Location.t * string | ModuleComment of Location.t * string @@ -204,7 +203,6 @@ let toString = function | Backtick -> "`" | BarGreater -> "|>" | Try -> "try" - | Export -> "export" | DocComment (_loc, s) -> "DocComment " ^ s | ModuleComment (_loc, s) -> "ModuleComment " ^ s @@ -215,7 +213,6 @@ let keywordTable = function | "constraint" -> Constraint | "else" -> Else | "exception" -> Exception - | "export" -> Export | "external" -> External | "false" -> False | "for" -> For @@ -241,10 +238,9 @@ let keywordTable = function [@@raises Not_found] let isKeyword = function - | And | As | Assert | Constraint | Else | Exception | Export | External - | False | For | If | In | Include | Land | Lazy | Let | List | Lor | Module - | Mutable | Of | Open | Private | Rec | Switch | True | Try | Typ | When - | While -> + | And | As | Assert | Constraint | Else | Exception | External | False | For + | If | In | Include | Land | Lazy | Let | List | Lor | Module | Mutable | Of + | Open | Private | Rec | Switch | True | Try | Typ | When | While -> true | _ -> false diff --git a/tests/parsing/errors/signature/consecutive.resi b/tests/parsing/errors/signature/consecutive.resi deleted file mode 100644 index 4433b3b3..00000000 --- a/tests/parsing/errors/signature/consecutive.resi +++ /dev/null @@ -1,3 +0,0 @@ -let x: int let y: float - -export z1: int export z2: float diff --git a/tests/parsing/errors/signature/expected/consecutive.resi.txt b/tests/parsing/errors/signature/expected/consecutive.resi.txt deleted file mode 100644 index 7dcd3b91..00000000 --- a/tests/parsing/errors/signature/expected/consecutive.resi.txt +++ /dev/null @@ -1,25 +0,0 @@ - - Syntax error! - tests/parsing/errors/signature/consecutive.resi:1:11-14 - - 1 │ let x: int let y: float - 2 │ - 3 │ export z1: int export z2: float - - consecutive specifications on a line must be separated by ';' or a newline - - - Syntax error! - tests/parsing/errors/signature/consecutive.resi:3:15-21 - - 1 │ let x: int let y: float - 2 │ - 3 │ export z1: int export z2: float - 4 │ - - consecutive specifications on a line must be separated by ';' or a newline - -val x : int -val y : float -val z1 : int[@@genType ] -val z2 : float[@@genType ] \ No newline at end of file diff --git a/tests/parsing/grammar/ffi/expected/export.res.txt b/tests/parsing/grammar/ffi/expected/export.res.txt index 0df452bf..f95dc33d 100644 --- a/tests/parsing/grammar/ffi/expected/export.res.txt +++ b/tests/parsing/grammar/ffi/expected/export.res.txt @@ -1,15 +1,57 @@ -type nonrec callback = ReactEvent.Mouse.t -> unit[@@genType ] -type nonrec t = int[@@genType ] -and s = string[@@genType ] -type nonrec t = int[@@genType ] -and s = string -type nonrec t = int -and s = string[@@genType ] -let callback _ = Js.log {js|Clicked|js}[@@genType ] -let callback _ = Js.log {js|Clicked|js}[@@genType ] -let x = {js|hello world|js}[@@genType ] -and y = 2[@@genType ] -let x = {js|hello world|js}[@@genType ] -and y = 2[@@genType ] -let x = {js|hello world|js} -and y = 2[@@genType ] \ No newline at end of file + + Syntax error! + tests/parsing/grammar/ffi/export.res:1:7-11 + + 1 │ export type callback = ReactEvent.Mouse.t => unit + 2 │ + 3 │ export type t = int and export s = string + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/parsing/grammar/ffi/export.res:3:31-32 + + 1 │ export type callback = ReactEvent.Mouse.t => unit + 2 │ + 3 │ export type t = int and export s = string + 4 │ export type t = int and s = string + 5 │ type t = int and export s = string + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/parsing/grammar/ffi/export.res:5:24-25 + + 3 │ export type t = int and export s = string + 4 │ export type t = int and s = string + 5 │ type t = int and export s = string + 6 │ + 7 │ export let callback = _ => Js.log("Clicked") + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/parsing/grammar/ffi/export.res:10:40-41 + + 8 │ export callback = _ => Js.log("Clicked") + 9 │ + 10 │ export let x = "hello world" and export y = 2 + 11 │ export x = "hello world" and export y = 2 + 12 │ let x = "hello world" and export y = 2 + + Did you forget a `=` here? + + + Syntax error! + tests/parsing/grammar/ffi/export.res:12:33-34 + + 10 │ export let x = "hello world" and export y = 2 + 11 │ export x = "hello world" and export y = 2 + 12 │ let x = "hello world" and export y = 2 + 13 │ + + Did you forget a `=` here? + diff --git a/tests/parsing/other/expected/gentype.res.txt b/tests/parsing/other/expected/gentype.res.txt index 6e7804e5..c1f02ad6 100644 --- a/tests/parsing/other/expected/gentype.res.txt +++ b/tests/parsing/other/expected/gentype.res.txt @@ -1,3 +1,22 @@ -module M : sig type nonrec t = int[@@genType ] val x : int[@@genType ] end = - struct type nonrec t = int - let x = 34 end \ No newline at end of file + + Syntax error! + tests/parsing/other/gentype.res:1:12-2:8 + + 1 │ module M: { + 2 │ export type t = int + 3 │ export x: int + 4 │ } = { + + Did you forget a `}` here? + + + Syntax error! + tests/parsing/other/gentype.res:2:9-13 + + 1 │ module M: { + 2 │ export type t = int + 3 │ export x: int + 4 │ } = { + + consecutive statements on a line must be separated by ';' or a newline + diff --git a/tests/printer/ffi/expected/export.res.txt b/tests/printer/ffi/expected/export.res.txt index 5609fe48..4066aa0d 100644 --- a/tests/printer/ffi/expected/export.res.txt +++ b/tests/printer/ffi/expected/export.res.txt @@ -1,12 +1,57 @@ -@genType type callback = ReactEvent.Mouse.t => unit -@genType type t = int @genType and s = string -@genType type t = int and s = string -type t = int @genType and s = string + Syntax error! + tests/printer/ffi/export.res:1:7-11 -@genType let callback = _ => Js.log("Clicked") -@genType let callback = _ => Js.log("Clicked") + 1 │ export type callback = ReactEvent.Mouse.t => unit + 2 │ + 3 │ export type t = int and export s = string + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/printer/ffi/export.res:3:31-32 + + 1 │ export type callback = ReactEvent.Mouse.t => unit + 2 │ + 3 │ export type t = int and export s = string + 4 │ export type t = int and s = string + 5 │ type t = int and export s = string + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/printer/ffi/export.res:5:24-25 + + 3 │ export type t = int and export s = string + 4 │ export type t = int and s = string + 5 │ type t = int and export s = string + 6 │ + 7 │ export let callback = _ => Js.log("Clicked") + + consecutive statements on a line must be separated by ';' or a newline + + + Syntax error! + tests/printer/ffi/export.res:10:40-41 + + 8 │ export callback = _ => Js.log("Clicked") + 9 │ + 10 │ export let x = "hello world" and export y = 2 + 11 │ export x = "hello world" and export y = 2 + 12 │ let x = "hello world" and export y = 2 + + Did you forget a `=` here? + + + Syntax error! + tests/printer/ffi/export.res:12:33-34 + + 10 │ export let x = "hello world" and export y = 2 + 11 │ export x = "hello world" and export y = 2 + 12 │ let x = "hello world" and export y = 2 + 13 │ + + Did you forget a `=` here? -@genType let x = "hello world" @genType and y = 2 -@genType let x = "hello world" @genType and y = 2 -let x = "hello world" @genType and y = 2 From 33b62708dd6ade19a1c3c5cf50b739e983830e33 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sun, 3 Jul 2022 18:00:58 +0200 Subject: [PATCH 2/2] Changelog and roundtrip tests. --- CHANGELOG.md | 1 + tests/printer/ffi/export.res | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 tests/printer/ffi/export.res diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f87068..370864cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Implement syntax for arity zero vs arity one in uncurried application in [#139](https://github.com/rescript-lang/syntax/pull/139) * Fix parsing of first class module exprs as part of binary/ternary expr in [#256](https://github.com/rescript-lang/syntax/pull/256) * Fix formatter hanging on deeply nested function calls [#261](https://github.com/rescript-lang/syntax/issues/261) +* Remove parsing of "import" and "export" which was never officially supported. ## ReScript 9.0.0 diff --git a/tests/printer/ffi/export.res b/tests/printer/ffi/export.res deleted file mode 100644 index da2f54e6..00000000 --- a/tests/printer/ffi/export.res +++ /dev/null @@ -1,12 +0,0 @@ -export type callback = ReactEvent.Mouse.t => unit - -export type t = int and export s = string -export type t = int and s = string -type t = int and export s = string - -export let callback = _ => Js.log("Clicked") -export callback = _ => Js.log("Clicked") - -export let x = "hello world" and export y = 2 -export x = "hello world" and export y = 2 -let x = "hello world" and export y = 2