Skip to content

Commit d0038d3

Browse files
authored
feat!: Remove -> token in favor of => (#2177)
1 parent 271d7cb commit d0038d3

File tree

6 files changed

+528
-538
lines changed

6 files changed

+528
-538
lines changed

compiler/src/parsing/lexer.re

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ let rec token = lexbuf => {
273273
| "/" => positioned(SLASH)
274274
| "|" => positioned(PIPE)
275275
| "-" => positioned(DASH)
276-
| "->" => positioned(ARROW)
277-
| "=>" => positioned(THICKARROW)
276+
| "=>" => positioned(ARROW)
278277
| "type" => positioned(TYPE)
279278
| "enum" => positioned(ENUM)
280279
| "record" => positioned(RECORD)

compiler/src/parsing/parser.messages

Lines changed: 513 additions & 513 deletions
Large diffs are not rendered by default.

compiler/src/parsing/parser.mly

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Grain_parsing = struct end
2020
%token <string> STRING BYTES CHAR
2121
%token LBRACK LBRACKRCARET RBRACK LPAREN RPAREN LBRACE RBRACE LCARET RCARET
2222
%token COMMA SEMI AS
23-
%token THICKARROW ARROW
23+
%token ARROW
2424
%token EQUAL GETS
2525
%token UNDERSCORE
2626
%token COLON QUESTION DOT ELLIPSIS
@@ -99,7 +99,6 @@ module Grain_parsing = struct end
9999
comma
100100
eos
101101
arrow
102-
thickarrow
103102
equal
104103
const
105104
pattern
@@ -192,13 +191,6 @@ comma:
192191
arrow:
193192
| ARROW opt_eols {}
194193

195-
thickarrow:
196-
| THICKARROW opt_eols {}
197-
198-
either_arrow:
199-
| arrow {}
200-
| thickarrow {}
201-
202194
equal:
203195
| EQUAL opt_eols {}
204196

@@ -324,9 +316,9 @@ data_typ:
324316
| qualified_uid %prec _below_infix { Type.constr ~loc:(to_loc $loc) $1 [] }
325317

326318
typ:
327-
| FUN data_typ either_arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled $2] $4 }
328-
| FUN LIDENT either_arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled (Type.var ~loc:(to_loc $loc($2)) $2)] $4 }
329-
| FUN lparen arg_typs? rparen either_arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
319+
| FUN data_typ arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled $2] $4 }
320+
| FUN LIDENT arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled (Type.var ~loc:(to_loc $loc($2)) $2)] $4 }
321+
| FUN lparen arg_typs? rparen arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
330322
| lparen tuple_typs rparen { Type.tuple ~loc:(to_loc $loc) $2 }
331323
| lparen typ rparen { $2 }
332324
| LIDENT { Type.var ~loc:(to_loc $loc) $1 }
@@ -542,8 +534,8 @@ lam_args:
542534
| lseparated_nonempty_list(comma, lam_arg) comma? { $1 }
543535

544536
lam_expr:
545-
| FUN lparen lam_args? rparen thickarrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
546-
| FUN LIDENT thickarrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) [LambdaArgument.mk ~loc:(to_loc $loc($2)) (Pattern.var ~loc:(to_loc $loc($2)) (mkstr $loc($2) $2)) None] $4 }
537+
| FUN lparen lam_args? rparen arrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
538+
| FUN LIDENT arrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) [LambdaArgument.mk ~loc:(to_loc $loc($2)) (Pattern.var ~loc:(to_loc $loc($2)) (mkstr $loc($2) $2)) None] $4 }
547539

548540
attribute_argument:
549541
| STRING { mkstr $loc $1 }
@@ -583,7 +575,7 @@ when_guard:
583575
| opt_eols WHEN expr { $3 }
584576

585577
match_branch:
586-
| pattern ioption(when_guard) thickarrow expr { MatchBranch.mk ~loc:(to_loc $loc) $1 $4 $2 }
578+
| pattern ioption(when_guard) arrow expr { MatchBranch.mk ~loc:(to_loc $loc) $1 $4 $2 }
587579

588580
match_branches:
589581
| lseparated_nonempty_list(comma, match_branch) comma? { $1 }

compiler/src/parsing/wrapped_lexer.re

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ let inject_fun =
6767

6868
let is_triggering_token =
6969
fun
70-
| (THICKARROW, _, _)
7170
| (ARROW, _, _) => true
7271
| _ => false;
7372

@@ -191,7 +190,7 @@ and lex_balanced_step = (state, closing, acc, tok) => {
191190
lex_balanced(~push=DiscoverFunctions, state, RPAREN, acc),
192191
)
193192
| ((LPAREN, _, _), _) => check_lparen_fn(state, closing, acc)
194-
| ((THICKARROW, _, _), _) when ignore_fns(state) =>
193+
| ((ARROW, _, _), _) when ignore_fns(state) =>
195194
// When in a context where we're not looking for toplevel functions,
196195
// the thing that appears immediately after an arrow could be a
197196
// function, so we need to check for that

compiler/test/grainfmt/function_params.input.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ let stringTailMatcher = (toMatch, len) =>
3333
true
3434
}
3535

36-
let f: Number -> (Number, Number) -> Number = a => (b, c) => a + b + c
36+
let f: Number => (Number, Number) => Number = a => (b, c) => a + b + c
3737

3838
let namedArg: (?suffix: String) => String = (suffix="") => suffix

docs/contributor/memory_management.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export let _RESERVED_RUNTIME_SPACE: WasmI32
2121
* @param nbytes: The number of bytes to allocate
2222
* @returns The pointer to the allocated region (8-byte aligned), or -1 if the allocation failed.
2323
*/
24-
export let malloc: (nbytes: WasmI32) -> WasmI32
24+
export let malloc: (nbytes: WasmI32) => WasmI32
2525
2626
/**
2727
* Frees the given allocated pointer.
@@ -63,22 +63,22 @@ The interface provided by the `GC` module is similar (but not identical) to that
6363
* @param size: The number of bytes to allocate
6464
* @returns The pointer to the allocated region
6565
*/
66-
export let malloc = (size: WasmI32) -> WasmI32
66+
export let malloc = (size: WasmI32) => WasmI32
6767
6868
/**
6969
* Frees the given pointer. Using this pointer after it has been freed will result in undefined behavior.
7070
*
7171
* @param userPtr: The pointer to free
7272
*/
73-
export let free = (userPtr: WasmI32) -> Void
73+
export let free = (userPtr: WasmI32) => Void
7474
7575
/**
7676
* Increments the reference count of the given pointer.
7777
*
7878
* @param userPtr: The pointer whose reference count should be incremented
7979
* @returns The given pointer
8080
*/
81-
export let incRef = (userPtr: WasmI32) -> WasmI32
81+
export let incRef = (userPtr: WasmI32) => WasmI32
8282
8383
/**
8484
* Decrements the reference count of the given pointer. An error is thrown if the
@@ -87,7 +87,7 @@ export let incRef = (userPtr: WasmI32) -> WasmI32
8787
* @param userPtr: The pointer whose reference count should be decremented
8888
* @returns The given pointer
8989
*/
90-
export let decRef = (userPtr: WasmI32) -> WasmI32
90+
export let decRef = (userPtr: WasmI32) => WasmI32
9191
```
9292

9393
The reference count-managing functions are safe to use with non-pointers; if a non-pointer is passed

0 commit comments

Comments
 (0)