File tree Expand file tree Collapse file tree 6 files changed +148
-26
lines changed
parser-typechecker/src/Unison/Syntax
unison-src/transcripts/idempotent
unison-syntax/src/Unison/Syntax Expand file tree Collapse file tree 6 files changed +148
-26
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ modifierP = do
8787 where
8888 unique = do
8989 tok <- openBlockWith " unique"
90- optional (openBlockWith " [" *> importWordyId <* closeBlock) >>= \ case
90+ optional (openBlockWith " [" *> importRelativeWordyId <* closeBlock) >>= \ case
9191 Nothing -> pure (UnresolvedModifier'UniqueWithoutGuid <$ tok)
9292 Just guid -> pure (UnresolvedModifier'UniqueWithGuid (Name. toText (L. payload guid)) <$ tok)
9393 structural = do
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ file = do
5555 optional (reserved " namespace" ) >>= \ case
5656 Nothing -> pure Nothing
5757 Just _ -> do
58- namespace <- importWordyId <|> importSymbolyId
58+ namespace <- importRelativeWordyId <|> importRelativeSymbolyId
5959 void (optional semi)
6060 pure (Just namespace. payload)
6161 let maybeNamespaceVar = Name. toVar <$> maybeNamespace
@@ -401,9 +401,9 @@ stanza = watchExpression <|> unexpectedAction <|> binding
401401
402402watched :: (Monad m , Var v ) => P v m (UF. WatchKind , Text , Ann )
403403watched = P. try do
404- kind <- (fmap . fmap . fmap ) (Text. unpack . Name. toText) (optional importWordyId )
404+ kind <- (fmap . fmap . fmap ) (Text. unpack . Name. toText) (optional importRelativeWordyId )
405405 guid <- uniqueName 10
406- op <- optional (L. payload <$> P. lookAhead importSymbolyId )
406+ op <- optional (L. payload <$> P. lookAhead importRelativeSymbolyId )
407407 guard (op == Just (Name. fromSegment NameSegment. watchSegment))
408408 tok <- anyToken
409409 guard $ maybe True (`L.touches` tok) kind
Original file line number Diff line number Diff line change @@ -1355,7 +1355,7 @@ importp = do
13551355 optional $
13561356 fmap Right importWordyId
13571357 <|> fmap Left importSymbolyId
1358- suffixes <- optional (some (importWordyId <|> importSymbolyId ))
1358+ suffixes <- optional (some (importRelativeWordyId <|> importRelativeSymbolyId ))
13591359 case (prefix, suffixes) of
13601360 (Nothing , _) -> P. customFailure $ UseEmpty kw
13611361 (Just prefix@ (Left _), _) -> P. customFailure $ UseInvalidPrefixSuffix prefix suffixes
Original file line number Diff line number Diff line change 1+ ``` ucm
2+ scratch/main> builtins.merge lib.builtin
3+
4+ Done.
5+ ```
6+
7+ ``` unison :error
8+ foo : Nat
9+ foo =
10+ use Nat .+
11+ 1 + 2
12+ ```
13+
14+ ``` ucm :added-by-ucm
15+ Loading changes detected in scratch.u.
16+
17+ I got confused here:
18+
19+ 3 | use Nat .+
20+
21+
22+ I was surprised to find a '.' here.
23+ I was expecting one of these instead:
24+
25+ * bang
26+ * binding
27+ * do
28+ * false
29+ * force
30+ * handle
31+ * if
32+ * lambda
33+ * let
34+ * newline or semicolon
35+ * pattern
36+ * quote
37+ * termLink
38+ * true
39+ * tuple
40+ * typeLink
41+ ```
42+
43+ ``` unison :error
44+ namespace .foo
45+ ```
46+
47+ ``` ucm :added-by-ucm
48+ Loading changes detected in scratch.u.
49+
50+ I got confused here:
51+
52+ 1 | namespace .foo
53+
54+
55+ I was surprised to find a .foo here.
56+ ```
57+
58+ ``` unison :error
59+ unique[.foo] type Foo = Foo
60+ ```
61+
62+ ``` ucm :added-by-ucm
63+ Loading changes detected in scratch.u.
64+
65+ I got confused here:
66+
67+ 1 | unique[.foo] type Foo = Foo
68+
69+
70+ I was surprised to find a .foo here.
71+ ```
72+
73+ ``` unison :error
74+ .foo> 17
75+ ```
76+
77+ ``` ucm :added-by-ucm
78+ Loading changes detected in scratch.u.
79+
80+ This looks like the start of an expression here
81+
82+ 1 | .foo> 17
83+
84+ but at the file top-level, I expect one of the following:
85+
86+ - A binding, like .foo = 42 OR
87+ .foo : Nat
88+ .foo = 42
89+ - A watch expression, like > .foo + 1
90+ - An `ability` declaration, like unique ability Foo where ...
91+ - A `type` declaration, like structural type Optional a = None | Some a
92+ ```
93+
94+ ``` unison :error
95+ foo.> 17
96+ ```
97+
98+ ``` ucm :added-by-ucm
99+ Loading changes detected in scratch.u.
100+
101+ I got confused here:
102+
103+ 1 | foo.> 17
104+
105+
106+ I was surprised to find a foo.> here.
107+ I was expecting one of these instead:
108+
109+ * ability
110+ * bang
111+ * binding
112+ * do
113+ * false
114+ * force
115+ * handle
116+ * if
117+ * lambda
118+ * let
119+ * namespace
120+ * newline or semicolon
121+ * quote
122+ * termLink
123+ * true
124+ * tuple
125+ * type
126+ * typeLink
127+ * use
128+ ```
Original file line number Diff line number Diff line change @@ -33,27 +33,7 @@ namespace.blah = 1
3333 1 | namespace.blah = 1
3434
3535
36- I was surprised to find a = here.
37- I was expecting one of these instead:
38-
39- * ability
40- * bang
41- * binding
42- * do
43- * false
44- * force
45- * handle
46- * if
47- * lambda
48- * let
49- * newline or semicolon
50- * quote
51- * termLink
52- * true
53- * tuple
54- * type
55- * typeLink
56- * use
36+ I was surprised to find a .blah here.
5737```
5838
5939``` unison :error
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ module Unison.Syntax.Parser
2424 failureIf ,
2525 hqInfixId ,
2626 hqPrefixId ,
27+ importRelativeSymbolyId ,
28+ importRelativeWordyId ,
2729 importSymbolyId ,
2830 importWordyId ,
2931 label ,
@@ -363,12 +365,24 @@ importWordyId = queryToken \case
363365 L. WordyId (HQ'. NameOnly n) -> Just n
364366 _ -> Nothing
365367
368+ -- | Parse a wordyId as a relative Name, rejecting any hash
369+ importRelativeWordyId :: (Ord v ) => P v m (L. Token Name )
370+ importRelativeWordyId = queryToken \ case
371+ L. WordyId (HQ'. NameOnly n) | Name. isRelative n -> Just n
372+ _ -> Nothing
373+
366374-- | The `+` in: use Foo.bar + as a Name
367375importSymbolyId :: (Ord v ) => P v m (L. Token Name )
368376importSymbolyId = queryToken \ case
369377 L. SymbolyId (HQ'. NameOnly n) -> Just n
370378 _ -> Nothing
371379
380+ -- | The `+` in: use Foo.bar + as a relative Name
381+ importRelativeSymbolyId :: (Ord v ) => P v m (L. Token Name )
382+ importRelativeSymbolyId = queryToken \ case
383+ L. SymbolyId (HQ'. NameOnly n) | Name. isRelative n -> Just n
384+ _ -> Nothing
385+
372386-- | Parse a symboly ID like >>= or &&, discarding any hash
373387symbolyDefinitionName :: (Var v ) => P v m (L. Token v )
374388symbolyDefinitionName = queryToken $ \ case
You can’t perform that action at this time.
0 commit comments