Skip to content

Commit

Permalink
feat!: Remove -> token in favor of => (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake authored Nov 16, 2024
1 parent 271d7cb commit d0038d3
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 538 deletions.
3 changes: 1 addition & 2 deletions compiler/src/parsing/lexer.re
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ let rec token = lexbuf => {
| "/" => positioned(SLASH)
| "|" => positioned(PIPE)
| "-" => positioned(DASH)
| "->" => positioned(ARROW)
| "=>" => positioned(THICKARROW)
| "=>" => positioned(ARROW)
| "type" => positioned(TYPE)
| "enum" => positioned(ENUM)
| "record" => positioned(RECORD)
Expand Down
1,026 changes: 513 additions & 513 deletions compiler/src/parsing/parser.messages

Large diffs are not rendered by default.

22 changes: 7 additions & 15 deletions compiler/src/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Grain_parsing = struct end
%token <string> STRING BYTES CHAR
%token LBRACK LBRACKRCARET RBRACK LPAREN RPAREN LBRACE RBRACE LCARET RCARET
%token COMMA SEMI AS
%token THICKARROW ARROW
%token ARROW
%token EQUAL GETS
%token UNDERSCORE
%token COLON QUESTION DOT ELLIPSIS
Expand Down Expand Up @@ -99,7 +99,6 @@ module Grain_parsing = struct end
comma
eos
arrow
thickarrow
equal
const
pattern
Expand Down Expand Up @@ -192,13 +191,6 @@ comma:
arrow:
| ARROW opt_eols {}

thickarrow:
| THICKARROW opt_eols {}

either_arrow:
| arrow {}
| thickarrow {}

equal:
| EQUAL opt_eols {}

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

typ:
| FUN data_typ either_arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled $2] $4 }
| 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 }
| FUN lparen arg_typs? rparen either_arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
| FUN data_typ arrow typ { Type.arrow ~loc:(to_loc $loc) [TypeArgument.mk ~loc:(to_loc $loc($2)) Unlabeled $2] $4 }
| 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 }
| FUN lparen arg_typs? rparen arrow typ { Type.arrow ~loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
| lparen tuple_typs rparen { Type.tuple ~loc:(to_loc $loc) $2 }
| lparen typ rparen { $2 }
| LIDENT { Type.var ~loc:(to_loc $loc) $1 }
Expand Down Expand Up @@ -542,8 +534,8 @@ lam_args:
| lseparated_nonempty_list(comma, lam_arg) comma? { $1 }

lam_expr:
| FUN lparen lam_args? rparen thickarrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
| 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 }
| FUN lparen lam_args? rparen arrow expr { Expression.lambda ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) (Option.value ~default:[] $3) $6 }
| 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 }

attribute_argument:
| STRING { mkstr $loc $1 }
Expand Down Expand Up @@ -583,7 +575,7 @@ when_guard:
| opt_eols WHEN expr { $3 }

match_branch:
| pattern ioption(when_guard) thickarrow expr { MatchBranch.mk ~loc:(to_loc $loc) $1 $4 $2 }
| pattern ioption(when_guard) arrow expr { MatchBranch.mk ~loc:(to_loc $loc) $1 $4 $2 }

match_branches:
| lseparated_nonempty_list(comma, match_branch) comma? { $1 }
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/parsing/wrapped_lexer.re
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ let inject_fun =

let is_triggering_token =
fun
| (THICKARROW, _, _)
| (ARROW, _, _) => true
| _ => false;

Expand Down Expand Up @@ -191,7 +190,7 @@ and lex_balanced_step = (state, closing, acc, tok) => {
lex_balanced(~push=DiscoverFunctions, state, RPAREN, acc),
)
| ((LPAREN, _, _), _) => check_lparen_fn(state, closing, acc)
| ((THICKARROW, _, _), _) when ignore_fns(state) =>
| ((ARROW, _, _), _) when ignore_fns(state) =>
// When in a context where we're not looking for toplevel functions,
// the thing that appears immediately after an arrow could be a
// function, so we need to check for that
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/grainfmt/function_params.input.gr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ let stringTailMatcher = (toMatch, len) =>
true
}

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

let namedArg: (?suffix: String) => String = (suffix="") => suffix
10 changes: 5 additions & 5 deletions docs/contributor/memory_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export let _RESERVED_RUNTIME_SPACE: WasmI32
* @param nbytes: The number of bytes to allocate
* @returns The pointer to the allocated region (8-byte aligned), or -1 if the allocation failed.
*/
export let malloc: (nbytes: WasmI32) -> WasmI32
export let malloc: (nbytes: WasmI32) => WasmI32
/**
* Frees the given allocated pointer.
Expand Down Expand Up @@ -63,22 +63,22 @@ The interface provided by the `GC` module is similar (but not identical) to that
* @param size: The number of bytes to allocate
* @returns The pointer to the allocated region
*/
export let malloc = (size: WasmI32) -> WasmI32
export let malloc = (size: WasmI32) => WasmI32
/**
* Frees the given pointer. Using this pointer after it has been freed will result in undefined behavior.
*
* @param userPtr: The pointer to free
*/
export let free = (userPtr: WasmI32) -> Void
export let free = (userPtr: WasmI32) => Void
/**
* Increments the reference count of the given pointer.
*
* @param userPtr: The pointer whose reference count should be incremented
* @returns The given pointer
*/
export let incRef = (userPtr: WasmI32) -> WasmI32
export let incRef = (userPtr: WasmI32) => WasmI32
/**
* Decrements the reference count of the given pointer. An error is thrown if the
Expand All @@ -87,7 +87,7 @@ export let incRef = (userPtr: WasmI32) -> WasmI32
* @param userPtr: The pointer whose reference count should be decremented
* @returns The given pointer
*/
export let decRef = (userPtr: WasmI32) -> WasmI32
export let decRef = (userPtr: WasmI32) => WasmI32
```

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

0 comments on commit d0038d3

Please sign in to comment.