mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 10:35:57 +03:00
Merge pull request #5114 from unisonweb/topic/force-syntax
This commit is contained in:
commit
53c3a16366
@ -38,6 +38,7 @@ import Unison.NameSegment qualified as NameSegment
|
||||
import Unison.Names (Names)
|
||||
import Unison.Names qualified as Names
|
||||
import Unison.NamesWithHistory qualified as Names
|
||||
import Unison.Parser.Ann qualified as Ann
|
||||
import Unison.Parser.Ann (Ann)
|
||||
import Unison.Pattern (Pattern)
|
||||
import Unison.Pattern qualified as Pattern
|
||||
@ -439,7 +440,8 @@ resolveHashQualified tok = do
|
||||
termLeaf :: forall m v. (Monad m, Var v) => TermP v m
|
||||
termLeaf =
|
||||
asum
|
||||
[ hashQualifiedPrefixTerm,
|
||||
[ force,
|
||||
hashQualifiedPrefixTerm,
|
||||
text,
|
||||
char,
|
||||
number,
|
||||
@ -991,6 +993,17 @@ bang = P.label "bang" do
|
||||
e <- termLeaf
|
||||
pure $ DD.forceTerm (ann start <> ann e) (ann start) e
|
||||
|
||||
force :: forall m v . (Monad m, Var v) => TermP v m
|
||||
force = P.label "force" $ P.try do
|
||||
-- `forkAt pool() blah` parses as `forkAt (pool ()) blah`
|
||||
-- That is, empty parens immediately (no space) following a symbol
|
||||
-- is treated as high precedence function application of `Unit`
|
||||
fn <- hashQualifiedPrefixTerm
|
||||
tok <- ann <$> openBlockWith "("
|
||||
guard (L.column (Ann.start tok) == L.column (Ann.end (ann fn)))
|
||||
close <- closeBlock
|
||||
pure $ DD.forceTerm (ann fn <> ann close) (tok <> ann close) fn
|
||||
|
||||
seqOp :: (Ord v) => P v m Pattern.SeqOp
|
||||
seqOp =
|
||||
Pattern.Snoc
|
||||
|
@ -490,7 +490,7 @@ pretty0
|
||||
(App' x (Constructor' (ConstructorReference DD.UnitRef 0)), _) | isLeaf x -> do
|
||||
px <- pretty0 (ac (if isBlock x then 0 else 9) Normal im doc) x
|
||||
pure . paren (p >= 11 || isBlock x && p >= 3) $
|
||||
fmt S.DelayForceChar (l "!") <> PP.indentNAfterNewline 1 px
|
||||
px <> fmt S.DelayForceChar (l "()")
|
||||
(Apps' f (unsnoc -> Just (args, lastArg)), _)
|
||||
| isSoftHangable lastArg -> do
|
||||
fun <- goNormal 9 f
|
||||
|
@ -183,7 +183,7 @@ woot1to2 x =
|
||||
|
||||
wootEx : Nat ->{Woot2} Nat
|
||||
wootEx a =
|
||||
_ = !Woot2.woot2
|
||||
_ = Woot2.woot2()
|
||||
blah2
|
||||
|
||||
blah = 123
|
||||
@ -198,7 +198,7 @@ After adding the rewritten form to the codebase, here's the rewritten `Woot1` to
|
||||
|
||||
wootEx : Nat ->{Woot2} Nat
|
||||
wootEx a =
|
||||
_ = !woot2
|
||||
_ = woot2()
|
||||
blah2
|
||||
|
||||
```
|
||||
|
@ -24,7 +24,7 @@ So we can see the pretty-printed output:
|
||||
|
||||
☝️
|
||||
|
||||
I added 109 definitions to the top of scratch.u
|
||||
I added 110 definitions to the top of scratch.u
|
||||
|
||||
You can edit them there, then run `update` to replace the
|
||||
definitions currently in this namespace.
|
||||
@ -73,13 +73,13 @@ structural ability Zoink where
|
||||
Abort.toDefault! : a -> '{g, Abort} a ->{g} a
|
||||
Abort.toDefault! default thunk =
|
||||
h x = Abort.toDefault! (handler_1778 default x) thunk
|
||||
handle !thunk with h
|
||||
handle thunk() with h
|
||||
|
||||
Abort.toOptional : '{g, Abort} a -> '{g} Optional a
|
||||
Abort.toOptional thunk = do toOptional! thunk
|
||||
|
||||
Abort.toOptional! : '{g, Abort} a ->{g} Optional a
|
||||
Abort.toOptional! thunk = toDefault! None do Some !thunk
|
||||
Abort.toOptional! thunk = toDefault! None do Some thunk()
|
||||
|
||||
catchAll : x -> Nat
|
||||
catchAll x = 99
|
||||
@ -87,7 +87,7 @@ catchAll x = 99
|
||||
Decode.remainder : '{Ask (Optional Bytes)} Bytes
|
||||
Decode.remainder = do match ask with
|
||||
None -> Bytes.empty
|
||||
Some b -> b Bytes.++ !Decode.remainder
|
||||
Some b -> b Bytes.++ Decode.remainder()
|
||||
|
||||
ex1 : Nat
|
||||
ex1 =
|
||||
@ -194,7 +194,7 @@ fix_2650 =
|
||||
use Nat +
|
||||
y = 12
|
||||
13 + y
|
||||
!addNumbers
|
||||
addNumbers()
|
||||
|
||||
fix_2650a : tvar -> fun -> ()
|
||||
fix_2650a tvar fun = ()
|
||||
@ -421,6 +421,16 @@ fix_525_exampleTerm quaffle =
|
||||
fix_525_exampleType : Id qualifiedName -> Id Fully.qualifiedName
|
||||
fix_525_exampleType z = Id (Dontcare () 19)
|
||||
|
||||
fnApplicationSyntax : Nat
|
||||
fnApplicationSyntax =
|
||||
use Nat +
|
||||
Environment.default = do 1 + 1
|
||||
oog = do 2 + 2
|
||||
blah : Nat -> Float -> Nat
|
||||
blah x y = x + 1
|
||||
_ = blah Environment.default() 1.0
|
||||
blah oog() (max 1.0 2.0)
|
||||
|
||||
Foo.bar.qux1 : Nat
|
||||
Foo.bar.qux1 = 42
|
||||
|
||||
@ -751,7 +761,7 @@ UUID.random = do UUID 0 (0, 0)
|
||||
|
||||
UUID.randomUUIDBytes : 'Bytes
|
||||
UUID.randomUUIDBytes = do
|
||||
(UUID a (b, _)) = !random
|
||||
(UUID a (b, _)) = random()
|
||||
encodeNat64be a Bytes.++ encodeNat64be b
|
||||
|
||||
(|>) : a -> (a ->{e} b) ->{e} b
|
||||
|
@ -544,6 +544,14 @@ fix_4384e =
|
||||
id x = x
|
||||
{{ {{ docExampleBlock 0 (id id id id id id id id id id id id id id id id id id id id id (x -> 0) }} }}
|
||||
|
||||
fnApplicationSyntax =
|
||||
Environment.default = do 1 + 1
|
||||
oog = do 2 + 2
|
||||
blah : Nat -> Float -> Nat
|
||||
blah x y = x + 1
|
||||
_ = blah Environment.default() 1.0
|
||||
blah oog() (Float.max 1.0 2.0)
|
||||
|
||||
fix_4727 = {{ `` 0xs900dc0ffee `` }}
|
||||
|
||||
fix_4729a = {{
|
||||
|
@ -67,11 +67,11 @@ ping _ = !pong + 3
|
||||
ping : 'Nat
|
||||
ping _ =
|
||||
use Nat +
|
||||
!pong + 3
|
||||
pong() + 3
|
||||
|
||||
pong : 'Nat
|
||||
pong _ =
|
||||
use Nat +
|
||||
!ping + 2
|
||||
ping() + 2
|
||||
|
||||
```
|
||||
|
@ -70,6 +70,6 @@ ping _ = 3
|
||||
pong : 'Nat
|
||||
pong _ =
|
||||
use Nat +
|
||||
!ping + 2
|
||||
ping() + 2
|
||||
|
||||
```
|
||||
|
@ -65,6 +65,6 @@ ping = 3
|
||||
pong : 'Nat
|
||||
pong _ =
|
||||
use Nat +
|
||||
!#4t465jk908.1 + 2
|
||||
#4t465jk908.1() + 2
|
||||
|
||||
```
|
||||
|
@ -74,16 +74,16 @@ clang _ = !pong + 3
|
||||
clang : 'Nat
|
||||
clang _ =
|
||||
use Nat +
|
||||
!pong + 3
|
||||
pong() + 3
|
||||
|
||||
ping : 'Nat
|
||||
ping _ =
|
||||
use Nat +
|
||||
!clang + 1
|
||||
clang() + 1
|
||||
|
||||
pong : 'Nat
|
||||
pong _ =
|
||||
use Nat +
|
||||
!ping + 2
|
||||
ping() + 2
|
||||
|
||||
```
|
||||
|
@ -65,7 +65,7 @@ inner.ping _ = !pong + 3
|
||||
inner.ping : 'Nat
|
||||
inner.ping _ =
|
||||
use Nat +
|
||||
!pong + 1
|
||||
pong() + 1
|
||||
|
||||
```
|
||||
The bug here is that `inner.ping` still refers to `pong` by name. But if we properly identified the nameless (in the
|
||||
|
@ -486,6 +486,6 @@ pong _ = 4 Nat.+ !ping
|
||||
pong : 'Nat
|
||||
pong _ =
|
||||
use Nat +
|
||||
4 + !#l9uq1dpl5v.1
|
||||
4 + #l9uq1dpl5v.1()
|
||||
|
||||
```
|
||||
|
@ -142,7 +142,7 @@ provide a action =
|
||||
h = cases
|
||||
{ ask -> resume } -> handle resume a with h
|
||||
{ r } -> r
|
||||
handle !action with h
|
||||
handle action() with h
|
||||
|
||||
Optional.doc = {{ A Doc before a type }}
|
||||
structural type Optional a = More Text | Some | Other a | None Nat
|
||||
|
@ -39,6 +39,7 @@ module Unison.Syntax.Parser
|
||||
run,
|
||||
semi,
|
||||
Unison.Syntax.Parser.seq,
|
||||
Unison.Syntax.Parser.seq',
|
||||
sepBy,
|
||||
sepBy1,
|
||||
string,
|
||||
|
Loading…
Reference in New Issue
Block a user