diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-04 14:53:40 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-04 14:53:40 +0100 |
commit | 369cf0bf5c356542aa92d4179dd3780dc48c13f4 (patch) | |
tree | 1e0a417aa19c270599a178102398599feb95adce | |
parent | 47964d03c92a208641dd31d2ee3fbf4786987b04 (diff) |
fix section desugaring
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 13 | ||||
-rw-r--r-- | testdata/language-features/section/section01.lc (renamed from testdata/language-features/section/section01.wip.lc) | 2 | ||||
-rw-r--r-- | testdata/language-features/section/section01.out | 12 |
4 files changed, 18 insertions, 11 deletions
@@ -3,7 +3,7 @@ all: | |||
3 | cabal install --constraint="indentation -trifecta" | 3 | cabal install --constraint="indentation -trifecta" |
4 | 4 | ||
5 | repl: | 5 | repl: |
6 | cd test && ghci -Wall -fno-warn-name-shadowing -fno-warn-unused-matches -fno-warn-missing-signatures -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns -fno-warn-type-defaults -i../src runTests.hs | 6 | cd test && ghci -Wall -fno-warn-name-shadowing -fno-warn-unused-matches -fno-warn-missing-signatures -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns -fno-warn-type-defaults -i../src -i../dist/build/autogen runTests.hs |
7 | 7 | ||
8 | coverage: | 8 | coverage: |
9 | ./run-test-suite.sh --coverage | 9 | ./run-test-suite.sh --coverage |
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index c8b78b0e..b2c0fef4 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -142,8 +142,7 @@ pattern SLabelEnd a = SBuiltin "labelend" `SAppV` a | |||
142 | 142 | ||
143 | pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s) | 143 | pattern SBuiltin s <- SGlobal (_, s) where SBuiltin s = SGlobal (debugSI $ "builtin " ++ s, s) |
144 | 144 | ||
145 | pattern LeftSection op e = SBuiltin "^leftSection" `SAppV` SGlobal op `SAppV` e | 145 | pattern Section e = SBuiltin "^section" `SAppV` e |
146 | pattern RightSection e op = SBuiltin "^rightSection" `SAppV` e `SAppV` SGlobal op | ||
147 | 146 | ||
148 | sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b | 147 | sApp v a b = SApp (sourceInfo a <> sourceInfo b) v a b |
149 | sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b | 148 | sBind v x a b = SBind (sourceInfo a <> sourceInfo b) v x a b |
@@ -416,12 +415,8 @@ parseTerm prec = withRange setSI $ case prec of | |||
416 | mkValues = foldr (\x xs -> SBuiltin "Tuple2" `SAppV` x `SAppV` xs) | 415 | mkValues = foldr (\x xs -> SBuiltin "Tuple2" `SAppV` x `SAppV` xs) |
417 | (SBuiltin "Tuple0") | 416 | (SBuiltin "Tuple0") |
418 | 417 | ||
419 | mkLeftSection op e = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` SVar (mempty, ".ls") 0 `SAppV` up1 e | 418 | mkTuple _ [Section e] = e |
420 | mkRightSection e op = SLam Visible (Wildcard SType) $ SGlobal op `SAppV` up1 e `SAppV` SVar (mempty, ".rs") 0 | ||
421 | |||
422 | mkTuple _ [x] = x | 419 | mkTuple _ [x] = x |
423 | mkTuple _ [LeftSection op x] = mkLeftSection op x | ||
424 | mkTuple _ [RightSection x op] = mkRightSection x op | ||
425 | mkTuple (Namespace level _) xs = foldl SAppV (SBuiltin (tuple ++ show (length xs))) xs | 420 | mkTuple (Namespace level _) xs = foldl SAppV (SBuiltin (tuple ++ show (length xs))) xs |
426 | where tuple = case level of | 421 | where tuple = case level of |
427 | Just TypeLevel -> "'Tuple" | 422 | Just TypeLevel -> "'Tuple" |
@@ -442,10 +437,10 @@ parseTerm prec = withRange setSI $ case prec of | |||
442 | calculatePrecs :: DesugarInfo -> [Either SIName SExp] -> P SExp | 437 | calculatePrecs :: DesugarInfo -> [Either SIName SExp] -> P SExp |
443 | calculatePrecs dcls = either fail return . f where | 438 | calculatePrecs dcls = either fail return . f where |
444 | f [] = error "impossible" | 439 | f [] = error "impossible" |
445 | f (Right t: xs) = either (\(op, xs) -> RightSection (calcPrec' t xs) op) (calcPrec' t) <$> cont xs | 440 | f (Right t: xs) = either (\(op, xs) -> Section $ SLamV $ SGlobal op `SAppV` up1 (calcPrec' t xs) `SAppV` SVar (mempty, ".rs") 0) (calcPrec' t) <$> cont xs |
446 | f xs@(Left op@(_, "-"): _) = f $ Right (mkLit $ LInt 0): xs | 441 | f xs@(Left op@(_, "-"): _) = f $ Right (mkLit $ LInt 0): xs |
447 | f (Left op: xs) = g op xs >>= either (const $ Left "TODO: better error message @476") | 442 | f (Left op: xs) = g op xs >>= either (const $ Left "TODO: better error message @476") |
448 | (\((op, e): oe) -> return $ LeftSection op $ calcPrec' e oe) | 443 | (\((op, e): oe) -> return $ Section $ SLamV $ SGlobal op `SAppV` SVar (mempty, ".ls") 0 `SAppV` up1 (calcPrec' e oe)) |
449 | g op (Right t: xs) = (second ((op, t):) +++ ((op, t):)) <$> cont xs | 444 | g op (Right t: xs) = (second ((op, t):) +++ ((op, t):)) <$> cont xs |
450 | g op [] = return $ Left (op, []) | 445 | g op [] = return $ Left (op, []) |
451 | g op _ = Left "two operator is not allowed next to each-other" | 446 | g op _ = Left "two operator is not allowed next to each-other" |
diff --git a/testdata/language-features/section/section01.wip.lc b/testdata/language-features/section/section01.lc index e235aaba..99c83a29 100644 --- a/testdata/language-features/section/section01.wip.lc +++ b/testdata/language-features/section/section01.lc | |||
@@ -2,4 +2,4 @@ _ !@! _ = () | |||
2 | 2 | ||
3 | value1 x = (x !@!) | 3 | value1 x = (x !@!) |
4 | 4 | ||
5 | value2 x = (!@! x) \ No newline at end of file | 5 | value2 x = (!@! x) |
diff --git a/testdata/language-features/section/section01.out b/testdata/language-features/section/section01.out new file mode 100644 index 00000000..4b6e540f --- /dev/null +++ b/testdata/language-features/section/section01.out | |||
@@ -0,0 +1,12 @@ | |||
1 | main is not found | ||
2 | tooltips: | ||
3 | testdata/language-features/section/section01.lc 1:3-1:6 {a} -> {b} -> a -> b->Tuple0 | ||
4 | testdata/language-features/section/section01.lc 1:11-1:13 Tuple0 | ||
5 | testdata/language-features/section/section01.lc 3:1-3:7 {a} -> {b} -> a -> b->Tuple0 | ||
6 | testdata/language-features/section/section01.lc 3:13-3:14 V5 | ||
7 | testdata/language-features/section/section01.lc 3:13-3:18 V0->Tuple0 | ||
8 | testdata/language-features/section/section01.lc 3:15-3:18 {a} -> {b} -> a -> b->Tuple0 | ||
9 | testdata/language-features/section/section01.lc 5:1-5:7 {a} -> {b} -> a -> b->Tuple0 | ||
10 | testdata/language-features/section/section01.lc 5:13-5:16 {a} -> {b} -> a -> b->Tuple0 | ||
11 | testdata/language-features/section/section01.lc 5:13-5:18 Tuple0 | ||
12 | testdata/language-features/section/section01.lc 5:17-5:18 V4 | ||