Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit eee11d1

Browse files
committed
Further context system improvements
- Make sure "external" is treated as a top-level keyword - Add struct/do to our keyword list - Treat arguments to open as a module body
1 parent 738ff64 commit eee11d1

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

editor/amulet-mode.el

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ binding, making it easier to determine what a function does."
6060

6161

6262
(defconst amulet-mode--keywords
63-
'("and" "as" "begin" "class" "deriving" "else" "end" "external" "false" "forall"
64-
"fun" "function" "if" "import" "in" "include" "instance" "lazy" "let" "match"
65-
"module" "of" "open" "private" "rec" "then" "true" "type" "val" "when" "with")
63+
'("and" "as" "begin" "class" "deriving" "do" "else" "end" "external" "false"
64+
"forall" "fun" "function" "if" "import" "in" "include" "instance" "lazy"
65+
"let" "match" "module" "of" "open" "private" "rec" "struct" "then" "true"
66+
"type" "val" "when" "with")
6667
"All Amulet keywords. These are just extracted from Lexer.x.")
6768

6869
(defconst amulet-mode--font-lock

src/Parser/Context.hs

+3
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ handleContextBlock needsSep tok@(Token tk tp te) c =
460460

461461
-- @module@ ~~> Push a module context
462462
(TcModule, _) -> pure (Result tok Done, CtxModuleHead False (getMarginAt tp c):c)
463+
-- @open@ ~~> Push an unresolved module
464+
(TcOpen, _) | isToplevel c -> pure (Result tok Done, CtxModuleBodyUnresolved (getMarginAt tp c):c)
463465
-- @class@ ~~> Push a class context
464466
(TcClass, _) -> pure (Result tok Done, CtxClassHead (getMarginAt tp c):c)
465467
-- @instance@ ~~> Push an instance context
@@ -601,6 +603,7 @@ isIfContinue _ = False
601603
isTopTok :: TokenClass -> Bool
602604
isTopTok TcClass = True
603605
isTopTok TcDeriving = True
606+
isTopTok TcExternal = True
604607
isTopTok TcInclude = True
605608
isTopTok TcInstance = True
606609
isTopTok TcLet = True

src/Parser/Context.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ _ DerivingHead | Offside -> Pop
3232
_ ModuleHead<I> | Offside -> Add =, $begin, Replace with EmptyBlock+ModuleBody
3333

3434
ModuleBody -> Pop
35-
begin ModuleBodyUnresolved | Not offside -> Push Block+ModuleBody+Bracket
35+
struct ModuleBodyUnresolved | Not offside -> Push Block+ModuleBody+Bracket
3636
_ ModuleBodyUnresolved | Not offside, Is toplevel -> Add $begin, Push Block+ModuleBody
3737
_ ModuleBodyUnresolved -> Pop
3838
= ModuleHead -> Replace with ModuleBodyUnresolved
@@ -73,6 +73,7 @@ else _ -> Push Else
7373

7474
module [Block<empty>] -> Push ModuleHead[I]
7575
module _ -> Push ModuleHead
76+
open _ | Is toplevel -> Push ModuleBodyUnresolved
7677

7778
class _ -> Push ClassHead
7879
instance _ -> Push InstHead
@@ -83,7 +84,7 @@ _ TypeHead | Not offside, Is some top-level token
8384
-> Insert $begin, Replace with Block+TypeFunBody
8485
_ TypeFunBody -> Pop
8586

86-
begin _ -> Push Block+Monad+Bracket<end>
87+
do _ -> Push Block+Monad+Bracket<end>
8788
({ _ -> Push Bracket<_>
8889

8990
[ _ -> Push List+Bracket<]>

tests/lexer/context/module.ml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module X =
2020

2121
module X = Y
2222

23+
open struct
24+
type x
25+
end
26+
2327
(* Access modifiers *)
2428
private module Y =
2529
let a = 0

tests/lexer/context/module.out

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ $sep module X =
2020

2121
$sep module X = Y
2222

23+
$sep open struct
24+
type x
25+
end
26+
2327

2428
$sep private module Y =
2529
$begin let a = 0

0 commit comments

Comments
 (0)