Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support backticked operators in sections #4119

Merged
merged 12 commits into from
Oct 12, 2017
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
+ The `LinearTypes` language extension has been revised. It implements the
rules from Bob Atkey's draft "The Syntax and Semantics of Quantitative
Type Theory" and now works with holes and case expressions.
+ Backticked operators can appear in sections, e.g. `(\`LTE\` 42)` or
`(1 \`plus\`)`.

## Library Updates

1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -107,6 +107,7 @@ Jan de Muijnck-Hughes
Jan Doms
Jan Stolarek
Jason Dagit
Jason Felice
Jason Gross
Jean-Remi Desjardins
Jeff Hemphill
38 changes: 20 additions & 18 deletions src/Idris/Parser/Expr.hs
Original file line number Diff line number Diff line change
@@ -468,27 +468,29 @@ bracketed' open syn =
lchar ')'
return $ PTrue (spanFC open (FC f start (l, c+1))) TypeOrTerm
<|> try (dependentPair TypeOrTerm [] open syn)
<|> try (do fc <- getFC; o <- operator; e <- expr syn; lchar ')'
<|> try (do fc <- getFC
opName <- operatorName
-- No prefix operators! (bit of a hack here...)
if (o == "-" || o == "!")
then fail "minus not allowed in section"
else return $ PLam fc (sMN 1000 "ARG") NoFC Placeholder
(PApp fc (PRef fc [] (sUN o)) [pexp (PRef fc [] (sMN 1000 "ARG")),
pexp e]))
<|> try (do l <- simpleExpr syn
op <- option Nothing (do o <- operator
lchar ')'
return (Just o))
fc0 <- getFC
case op of
Nothing -> bracketedExpr syn open l
Just o -> return $ PLam fc0 (sMN 1000 "ARG") NoFC Placeholder
(PApp fc0 (PRef fc0 [] (sUN o)) [pexp l,
pexp (PRef fc0 [] (sMN 1000 "ARG"))]))
guard $ opName /= sUN "-" && opName /= sUN "!"
e <- expr syn
lchar ')'
return $ PLam fc (sMN 1000 "ARG") NoFC Placeholder
(PApp fc (PRef fc [] opName) [pexp (PRef fc [] (sMN 1000 "ARG")),
pexp e]))
<|> try (simpleExpr syn >>= \l ->
try (do opName <- operatorName
lchar ')'
fc <- getFC
return $ PLam fc (sMN 1000 "ARG") NoFC Placeholder
(PApp fc (PRef fc [] opName) [pexp l,
pexp (PRef fc [] (sMN 1000 "ARG"))]))
<|> bracketedExpr syn open l)
<|> do l <- expr (allowConstr syn)
bracketedExpr (allowConstr syn) open l


where
operatorName :: IdrisParser Name
operatorName = sUN <$> operator
<|> fst <$> between (lchar '`') (lchar '`') fnName

{-| Parses the rest of a dependent pair after '(' or '(Expr **' -}
dependentPair :: PunInfo -> [(PTerm, Maybe (FC, PTerm), FC)] -> FC -> SyntaxInfo -> IdrisParser PTerm
45 changes: 23 additions & 22 deletions test/TestData.hs
Original file line number Diff line number Diff line change
@@ -52,28 +52,29 @@ testFamiliesData = [
("base", "Base",
[ ( 1, C_CG )]),
("basic", "Basic",
[ ( 1, ANY ),
( 2, ANY ),
( 3, ANY ),
( 4, ANY ),
( 5, ANY ),
( 6, ANY ),
( 7, C_CG ),
( 8, ANY ),
( 9, ANY ),
( 10, ANY ),
( 11, C_CG ),
( 12, ANY ),
( 13, ANY ),
( 14, ANY ),
( 15, ANY ),
( 16, ANY ),
( 17, ANY ),
( 18, ANY ),
( 19, ANY ),
( 20, ANY ),
( 21, C_CG ),
( 22, NODE_CG )]),
[ ( 1, ANY ),
( 2, ANY ),
( 3, ANY ),
( 4, ANY ),
( 5, ANY ),
( 6, ANY ),
( 7, C_CG ),
( 8, ANY ),
( 9, ANY ),
( 10, ANY ),
( 11, C_CG ),
( 12, ANY ),
( 13, ANY ),
( 14, ANY ),
( 15, ANY ),
( 16, ANY ),
( 17, ANY ),
( 18, ANY ),
( 19, ANY ),
( 20, ANY ),
( 21, C_CG ),
( 22, NODE_CG ),
( 23, ANY )]),
("bignum", "Bignum",
[ ( 1, ANY ),
( 2, ANY )]),
6 changes: 6 additions & 0 deletions test/basic023/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
True
True
True
True
True
True
4 changes: 4 additions & 0 deletions test/basic023/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
${IDRIS:-idris} $@ sections.idr -o sections
./sections
rm -f sections *.ibc
19 changes: 19 additions & 0 deletions test/basic023/sections.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
preInc : Nat -> Nat
preInc = (1 `plus`)

postInc : Nat -> Nat
postInc = (`plus` 1)

cons : Int -> List Int -> List Int
cons = (::)

main : IO ()
main = do
printLn $ (1 `cons`) [2] == [1,2]
printLn $ (1 ::) [2] == [1,2]
printLn $ (`cons` [2]) 1 == [1,2]
printLn $ (:: [2]) 1 == [1,2]
let x : Integer = 4
printLn $ (- x) == -4 -- prefix, not section
let io : IO Integer = pure 9
printLn $ (! io) == 9 -- prefix, not section