mirror of
https://github.com/google/ghc-source-gen.git
synced 2024-11-22 22:27:54 +03:00
Support arithmetic sequences.
`from` : [a .. ] `fromThen` : [a, b .. ] `fromTo` : [a .. b] `fromThenTo`: [a, b .. c] These are needed before supporting list comprehensions (#64).
This commit is contained in:
parent
3aa49fff6f
commit
6bc0965232
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
dist/
|
||||
# Generated automatically by hpack:
|
||||
*.cabal
|
||||
*.yaml.lock
|
||||
|
@ -21,6 +21,10 @@ module GHC.SourceGen.Expr
|
||||
, tyApp
|
||||
, recordConE
|
||||
, recordUpd
|
||||
, from
|
||||
, fromThen
|
||||
, fromTo
|
||||
, fromThenTo
|
||||
) where
|
||||
|
||||
import GHC.Hs.Expr
|
||||
@ -187,3 +191,40 @@ recordUpd e fs =
|
||||
}
|
||||
withPlaceHolder4 = withPlaceHolder . withPlaceHolder . withPlaceHolder
|
||||
. withPlaceHolder
|
||||
|
||||
-- | An arithmetic sequence expression with a start value.
|
||||
--
|
||||
-- > [a ..]
|
||||
-- > =====
|
||||
-- > from (var "a")
|
||||
from :: HsExpr' -> HsExpr'
|
||||
from from' =
|
||||
noExt ArithSeq Nothing $ From (builtLoc from')
|
||||
|
||||
-- | An arithmetic sequence expression with a start and a step values.
|
||||
--
|
||||
-- > [a, b ..]
|
||||
-- > =====
|
||||
-- > fromThen (var "a") (var "b")
|
||||
fromThen :: HsExpr' -> HsExpr' -> HsExpr'
|
||||
fromThen from' then' =
|
||||
noExt ArithSeq Nothing $ FromThen (builtLoc from') (builtLoc then')
|
||||
|
||||
-- | An arithmetic sequence expression with a start and an end values.
|
||||
--
|
||||
-- > [a .. b]
|
||||
-- > =====
|
||||
-- > fromTo (var "a") (var "b")
|
||||
fromTo :: HsExpr' -> HsExpr' -> HsExpr'
|
||||
fromTo from' to =
|
||||
noExt ArithSeq Nothing $ FromTo (builtLoc from') (builtLoc to)
|
||||
|
||||
-- | An arithmetic sequence expression with a start, a step, and an end values.
|
||||
--
|
||||
-- > [a, b .. c]
|
||||
-- > =====
|
||||
-- > fromThenTo (var "a") (var "b") (var "c")
|
||||
fromThenTo :: HsExpr' -> HsExpr' -> HsExpr' -> HsExpr'
|
||||
fromThenTo from' then' to =
|
||||
noExt ArithSeq Nothing $
|
||||
FromThenTo (builtLoc from') (builtLoc then') (builtLoc to)
|
||||
|
@ -221,6 +221,12 @@ exprsTest dflags = testGroup "Expr"
|
||||
-- TODO: add more tests.
|
||||
[ "do (let x = 1 in x)" :~ do' [stmt $ let' [valBind "x" (int 1)] (var "x")]
|
||||
]
|
||||
, test "arithSeq"
|
||||
[ "[a .. ]" :~ from (var "a")
|
||||
, "[a, b .. ]" :~ fromThen (var "a") (var "b")
|
||||
, "[a .. b]" :~ fromTo (var "a") (var "b")
|
||||
, "[a, b .. c]" :~ fromThenTo (var "a") (var "b") (var "c")
|
||||
]
|
||||
]
|
||||
where
|
||||
test = testExprs dflags
|
||||
|
Loading…
Reference in New Issue
Block a user