mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-08-19 10:46:22 -06:00
added the filter construction
This commit is contained in:
@@ -973,6 +973,16 @@ value2termM flat xs (VReset ctl mb_cv v mb_qid) = do
|
|||||||
_ -> evalError (pp "The term must be a record")
|
_ -> evalError (pp "The term must be a record")
|
||||||
select n (t:ts) = select (n-1) ts
|
select n (t:ts) = select (n-1) ts
|
||||||
_ -> evalError (pp "[select: .. | ..] requires an integer constant")
|
_ -> evalError (pp "[select: .. | ..] requires an integer constant")
|
||||||
|
| ctl == cFilter =
|
||||||
|
let filter [] = mzero
|
||||||
|
filter (t:ts) =
|
||||||
|
case t of
|
||||||
|
R rs -> case (lookup (ident2label cp1) rs, lookup (ident2label cp2) rs) of
|
||||||
|
(Just (_,t), Just (_,Q q))
|
||||||
|
| q == (cPredef,cTrue) -> pure t `mplus` filter ts
|
||||||
|
_ -> filter ts
|
||||||
|
_ -> evalError (pp "The term must be a record")
|
||||||
|
in filter ts
|
||||||
| ctl == cDefault =
|
| ctl == cDefault =
|
||||||
case (ts,mb_cv) of
|
case (ts,mb_cv) of
|
||||||
([] ,Nothing) -> mzero
|
([] ,Nothing) -> mzero
|
||||||
|
|||||||
@@ -487,6 +487,19 @@ tcRho scope c (Reset ctl mb_ct t qid) mb_ty
|
|||||||
Nothing -> evalError (pp "[select: .. | ..] requires an integer argument")
|
Nothing -> evalError (pp "[select: .. | ..] requires an integer argument")
|
||||||
(t,_) <- tcRho scope c1 t (Just rec_ty)
|
(t,_) <- tcRho scope c1 t (Just rec_ty)
|
||||||
return (Reset ctl mb_ct t qid,ty)
|
return (Reset ctl mb_ct t qid,ty)
|
||||||
|
| ctl == cFilter = do
|
||||||
|
ty <- case mb_ty of
|
||||||
|
Just ty -> return ty
|
||||||
|
Nothing -> do i <- newResiduation scope
|
||||||
|
return (VMeta i [])
|
||||||
|
let rec_ty = VRecType [ (ident2label cp1, True, ty)
|
||||||
|
, (ident2label cp2, True, VApp poison (cPredef,cBool) [])
|
||||||
|
] False
|
||||||
|
case mb_ct of
|
||||||
|
Just ct -> evalError (pp "[filter | ..] cannot take an argument")
|
||||||
|
Nothing -> return ()
|
||||||
|
(t,_) <- tcRho scope c t (Just rec_ty)
|
||||||
|
return (Reset ctl mb_ct t qid,ty)
|
||||||
| ctl == cDefault = do
|
| ctl == cDefault = do
|
||||||
let (c1,c2) = split c
|
let (c1,c2) = split c
|
||||||
(t,ty) <- tcRho scope c1 t mb_ty
|
(t,ty) <- tcRho scope c1 t mb_ty
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ cFloat = identS "Float"
|
|||||||
cString = identS "String"
|
cString = identS "String"
|
||||||
cInts = identS "Ints"
|
cInts = identS "Ints"
|
||||||
cPBool = identS "PBool"
|
cPBool = identS "PBool"
|
||||||
|
cBool = identS "Bool"
|
||||||
cErrorType = identS "Error"
|
cErrorType = identS "Error"
|
||||||
cOverload = identS "overload"
|
cOverload = identS "overload"
|
||||||
cNonExist = identS "nonExist"
|
cNonExist = identS "nonExist"
|
||||||
@@ -40,6 +41,8 @@ isPredefCat c = elem c [cInt,cString,cFloat]
|
|||||||
|
|
||||||
cPTrue = identS "PTrue"
|
cPTrue = identS "PTrue"
|
||||||
cPFalse = identS "PFalse"
|
cPFalse = identS "PFalse"
|
||||||
|
cTrue = identS "True"
|
||||||
|
cFalse = identS "False"
|
||||||
cLength = identS "length"
|
cLength = identS "length"
|
||||||
cDrop = identS "drop"
|
cDrop = identS "drop"
|
||||||
cTake = identS "take"
|
cTake = identS "take"
|
||||||
@@ -66,6 +69,7 @@ cConcat = identS "concat"
|
|||||||
cConcat' = identS "concat'"
|
cConcat' = identS "concat'"
|
||||||
cOne = identS "one"
|
cOne = identS "one"
|
||||||
cSelect = identS "select"
|
cSelect = identS "select"
|
||||||
|
cFilter = identS "filter"
|
||||||
cDefault = identS "default"
|
cDefault = identS "default"
|
||||||
cList = identS "list"
|
cList = identS "list"
|
||||||
cLen = identS "len"
|
cLen = identS "len"
|
||||||
|
|||||||
Reference in New Issue
Block a user