Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

remove "import" #597

Merged
merged 3 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Diagnostics = Res_diagnostics
module CommentTable = Res_comments_table
module ResPrinter = Res_printer
module Scanner = Res_scanner
module JsFfi = Res_js_ffi
module Parser = Res_parser

let mkLoc startLoc endLoc =
Expand Down Expand Up @@ -721,30 +720,6 @@ let parseModuleLongIdent ~lowercase p =
(* Parser.eatBreadcrumb p; *)
moduleIdent

(* `window.location` or `Math` or `Foo.Bar` *)
let parseIdentPath p =
let rec loop p acc =
match p.Parser.token with
| Uident ident | Lident ident -> (
Parser.next p;
let lident = Longident.Ldot (acc, ident) in
match p.Parser.token with
| Dot ->
Parser.next p;
loop p lident
| _ -> lident)
| _t -> acc
in
match p.Parser.token with
| Lident ident | Uident ident -> (
Parser.next p;
match p.Parser.token with
| Dot ->
Parser.next p;
loop p (Longident.Lident ident)
| _ -> Longident.Lident ident)
| _ -> Longident.Lident "_"

let verifyJsxOpeningClosingName p nameExpr =
let closing =
match p.Parser.token with
Expand Down Expand Up @@ -5336,12 +5311,6 @@ and parseStructureItemRegion p =
parseNewlineOrSemicolonStructure p;
let loc = mkLoc startPos p.prevEndPos in
Some (Ast_helper.Str.primitive ~loc externalDef)
| Import ->
let importDescr = parseJsImport ~startPos ~attrs p in
parseNewlineOrSemicolonStructure p;
let loc = mkLoc startPos p.prevEndPos in
let structureItem = JsFfi.toParsetree importDescr in
Some {structureItem with pstr_loc = loc}
| Exception ->
let exceptionDef = parseExceptionDef ~attrs p in
parseNewlineOrSemicolonStructure p;
Expand Down Expand Up @@ -5403,23 +5372,6 @@ and parseStructureItemRegion p =
| _ -> None)
[@@progress Parser.next, Parser.expect]

and parseJsImport ~startPos ~attrs p =
Parser.expect Token.Import p;
let importSpec =
match p.Parser.token with
| Token.Lident _ | Token.At ->
let decl =
match parseJsFfiDeclaration p with
| Some decl -> decl
| None -> assert false
in
JsFfi.Default decl
| _ -> JsFfi.Spec (parseJsFfiDeclarations p)
in
let scope = parseJsFfiScope p in
let loc = mkLoc startPos p.prevEndPos in
JsFfi.importDescr ~attrs ~importSpec ~scope ~loc

and parseJsExport ~attrs p =
let exportStart = p.Parser.startPos in
Parser.expect Token.Export p;
Expand Down Expand Up @@ -5457,49 +5409,6 @@ and parseSignJsExport ~attrs p =
let loc = mkLoc exportStart p.prevEndPos in
Ast_helper.Sig.value valueDesc ~loc

and parseJsFfiScope p =
match p.Parser.token with
| Token.Lident "from" -> (
Parser.next p;
match p.token with
| String s ->
Parser.next p;
JsFfi.Module s
| Uident _ | Lident _ ->
let value = parseIdentPath p in
JsFfi.Scope value
| _ -> JsFfi.Global)
| _ -> JsFfi.Global

and parseJsFfiDeclarations p =
Parser.expect Token.Lbrace p;
let decls =
parseCommaDelimitedRegion ~grammar:Grammar.JsFfiImport ~closing:Rbrace
~f:parseJsFfiDeclaration p
in
Parser.expect Rbrace p;
decls

and parseJsFfiDeclaration p =
let startPos = p.Parser.startPos in
let attrs = parseAttributes p in
match p.Parser.token with
| Lident _ ->
let ident, _ = parseLident p in
let alias =
match p.token with
| As ->
Parser.next p;
let ident, _ = parseLident p in
ident
| _ -> ident
in
Parser.expect Token.Colon p;
let typ = parseTypExpr p in
let loc = mkLoc startPos p.prevEndPos in
Some (JsFfi.decl ~loc ~alias ~attrs ~name:ident ~typ)
| _ -> None

(* include-statement ::= include module-expr *)
and parseIncludeStatement ~attrs p =
let startPos = p.Parser.startPos in
Expand Down Expand Up @@ -6113,9 +6022,6 @@ and parseSignatureItemRegion p =
parseNewlineOrSemicolonSignature p;
let loc = mkLoc startPos p.prevEndPos in
Some (Ast_helper.Sig.extension ~attrs ~loc extension)
| Import ->
Parser.next p;
parseSignatureItemRegion p
| _ -> (
match attrs with
| (({Asttypes.loc = attrLoc}, _) as attr) :: _ ->
Expand Down
12 changes: 2 additions & 10 deletions src/res_grammar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type t =
| TypeConstraint
| AtomicTypExpr
| ListExpr
| JsFfiImport
| Pattern
| AttributePayload
| TagNames
Expand Down Expand Up @@ -116,7 +115,6 @@ let toString = function
| AtomicTypExpr -> "a type"
| ListExpr -> "an ocaml list expr"
| PackageConstraint -> "a package constraint"
| JsFfiImport -> "js ffi import"
| JsxChild -> "jsx child"
| Pattern -> "pattern"
| ExprFor -> "a for expression"
Expand Down Expand Up @@ -162,8 +160,8 @@ let isJsxAttributeStart = function
| _ -> false

let isStructureItemStart = function
| Token.Open | Let | Typ | External | Import | Export | Exception | Include
| Module | AtAt | PercentPercent | At ->
| Token.Open | Let | Typ | External | Export | Exception | Include | Module
| AtAt | PercentPercent | At ->
true
| t when isExprStart t -> true
| _ -> false
Expand Down Expand Up @@ -254,10 +252,6 @@ let isAttributeStart = function
| Token.At -> true
| _ -> false

let isJsFfiImportStart = function
| Token.Lident _ | At -> true
| _ -> false

let isJsxChildStart = isAtomicExprStart

let isBlockExprStart = function
Expand Down Expand Up @@ -296,7 +290,6 @@ let isListElement grammar token =
| PackageConstraint -> token = And
| ConstructorDeclaration -> token = Bar
| JsxAttribute -> isJsxAttributeStart token
| JsFfiImport -> isJsFfiImportStart token
| AttributePayload -> token = Lparen
| TagNames -> token = Hash
| _ -> false
Expand All @@ -318,7 +311,6 @@ let isListTerminator grammar token =
| TypeParams, Rparen
| ParameterList, (EqualGreater | Lbrace)
| JsxAttribute, (Forwardslash | GreaterThan)
| JsFfiImport, Rbrace
| StringFieldDeclarations, Rbrace ->
true
| Attribute, token when token <> At -> true
Expand Down
121 changes: 0 additions & 121 deletions src/res_js_ffi.ml

This file was deleted.

9 changes: 3 additions & 6 deletions src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type t =
| Backtick
| BarGreater
| Try
| Import
| Export
| DocComment of Location.t * string
| ModuleComment of Location.t * string
Expand Down Expand Up @@ -205,7 +204,6 @@ let toString = function
| Backtick -> "`"
| BarGreater -> "|>"
| Try -> "try"
| Import -> "import"
| Export -> "export"
| DocComment (_loc, s) -> "DocComment " ^ s
| ModuleComment (_loc, s) -> "ModuleComment " ^ s
Expand All @@ -222,7 +220,6 @@ let keywordTable = function
| "false" -> False
| "for" -> For
| "if" -> If
| "import" -> Import
| "in" -> In
| "include" -> Include
| "lazy" -> Lazy
Expand All @@ -245,9 +242,9 @@ let keywordTable = function

let isKeyword = function
| And | As | Assert | Constraint | Else | Exception | Export | External
| False | For | If | Import | In | Include | Land | Lazy | Let | List | Lor
| Module | Mutable | Of | Open | Private | Rec | Switch | True | Try | Typ
| When | While ->
| False | For | If | In | Include | Land | Lazy | Let | List | Lor | Module
| Mutable | Of | Open | Private | Rec | Switch | True | Try | Typ | When
| While ->
true
| _ -> false

Expand Down
12 changes: 0 additions & 12 deletions tests/parsing/grammar/ffi/expected/import.res.txt

This file was deleted.

7 changes: 0 additions & 7 deletions tests/parsing/grammar/ffi/import.res

This file was deleted.

27 changes: 0 additions & 27 deletions tests/parsing/grammar/structure/expected/jsFfiSugar.res.txt

This file was deleted.

Loading