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

Remove "to" and "downto" as keywords. #327

Merged
merged 1 commit into from
Mar 15, 2021
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
4 changes: 2 additions & 2 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3148,8 +3148,8 @@ and parseForRest hasOpeningParen pattern startPos p =
Parser.expect In p;
let e1 = parseExpr p in
let direction = match p.Parser.token with
| To -> Asttypes.Upto
| Downto -> Asttypes.Downto
| Lident "to" -> Asttypes.Upto
| Lident "downto" -> Asttypes.Downto
| token ->
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Asttypes.Upto
Expand Down
10 changes: 3 additions & 7 deletions src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type t =
| Lazy
| Tilde
| Question
| If | Else | For | In | To | Downto | While | Switch
| If | Else | For | In | While | Switch
| When
| EqualGreater | MinusGreater
| External
Expand Down Expand Up @@ -131,8 +131,6 @@ let toString = function
| Else -> "else"
| For -> "for"
| In -> "in"
| To -> "to"
| Downto -> "downto"
| While -> "while"
| Switch -> "switch"
| When -> "when"
Expand Down Expand Up @@ -168,7 +166,6 @@ let keywordTable = function
| "as" -> As
| "assert" -> Assert
| "constraint" -> Constraint
| "downto" -> Downto
| "else" -> Else
| "exception" -> Exception
| "export" -> Export
Expand All @@ -189,7 +186,6 @@ let keywordTable = function
| "private" -> Private
| "rec" -> Rec
| "switch" -> Switch
| "to" -> To
| "true" -> True
| "try" -> Try
| "type" -> Typ
Expand All @@ -200,10 +196,10 @@ let keywordTable = function
[@@raises Not_found]

let isKeyword = function
| And | As | Assert | Constraint | Downto | Else | Exception | Export
| 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 | To | True | Try | Typ | When | While | With -> true
| Switch | True | Try | Typ | When | While | With -> true
| _ -> false

let lookupKeyword str =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,19 +247,19 @@ let [%rescript.patternhole ] = 3
Syntax error!
parsing/errors/structure/letBindingPatternKeyword.js:1:5-8
1 │ let open = 1
2 │ let to = 3
2 │ let for = 3
3 │

\`open\` is a reserved keyword. Keywords need to be escaped: \\\\\\"open\\"


Syntax error!
parsing/errors/structure/letBindingPatternKeyword.js:2:5-6
parsing/errors/structure/letBindingPatternKeyword.js:2:5-7
1 │ let open = 1
2 │ let to = 3
2 │ let for = 3
3 │

\`to\` is a reserved keyword. Keywords need to be escaped: \\\\\\"to\\"
\`for\` is a reserved keyword. Keywords need to be escaped: \\\\\\"for\\"


========================================================"
Expand Down
2 changes: 1 addition & 1 deletion tests/parsing/errors/structure/letBindingPatternKeyword.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let open = 1
let to = 3
let for = 3
8 changes: 4 additions & 4 deletions tests/parsing/errors/typeDef/__snapshots__/parse.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ exports[`typeParams.js 1`] = `
"=====Parsetree==========================================
type nonrec 'a node = {
_value: 'a Js.Nullable.value }
type nonrec ('from, 'to) derivedNode =
type nonrec ('from, 'for) derivedNode =
{
mutable value: 'to_ ;
updateF: 'from -> 'to_ }
Expand Down Expand Up @@ -240,14 +240,14 @@ type nonrec ('from, 'foo) derivedNode =


Syntax error!
parsing/errors/typeDef/typeParams.js:5:26-27
parsing/errors/typeDef/typeParams.js:5:26-28
3 │ }
4 │
5 │ type derivedNode<'from, 'to> = {
5 │ type derivedNode<'from, 'for> = {
6 │ mutable value: 'to_,
7 │ updateF: 'from => 'to_,

\`to\` is a reserved keyword. Keywords need to be escaped: \\\\\\"to\\"
\`for\` is a reserved keyword. Keywords need to be escaped: \\\\\\"for\\"


Syntax error!
Expand Down
2 changes: 1 addition & 1 deletion tests/parsing/errors/typeDef/typeParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type node('a) = {
_value: Js.Nullable.value<'a>
}

type derivedNode<'from, 'to> = {
type derivedNode<'from, 'for> = {
mutable value: 'to_,
updateF: 'from => 'to_,
}
Expand Down