mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
nonExist now does the expected thing
This commit is contained in:
@@ -36,6 +36,6 @@ resource Predef = {
|
|||||||
oper toStr : (L : Type) -> L -> Str = variants {} ; -- find the "first" string
|
oper toStr : (L : Type) -> L -> Str = variants {} ; -- find the "first" string
|
||||||
oper mapStr : (L : Type) -> (Str -> Str) -> L -> L = variants {} ;
|
oper mapStr : (L : Type) -> (Str -> Str) -> L -> L = variants {} ;
|
||||||
-- map all strings in a data structure; experimental ---
|
-- map all strings in a data structure; experimental ---
|
||||||
|
oper nonExist : Str = variants {} ; -- a placeholder for non-existant morphological forms
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ oper
|
|||||||
|
|
||||||
-- Missing form.
|
-- Missing form.
|
||||||
|
|
||||||
nonExist : Str = variants {} ;
|
nonExist : Str = Predef.nonExist;
|
||||||
|
|
||||||
-- Optional string with preference on the string vs. empty.
|
-- Optional string with preference on the string vs. empty.
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ primitives = Map.fromList
|
|||||||
[(Explicit,varL,typeType),(Explicit,identW,Vr varL)] typeStr []))) Nothing)
|
[(Explicit,varL,typeType),(Explicit,identW,Vr varL)] typeStr []))) Nothing)
|
||||||
, (cMapStr , ResOper (Just (noLoc (mkProd -- (L : Type) -> (Str -> Str) -> L -> L
|
, (cMapStr , ResOper (Just (noLoc (mkProd -- (L : Type) -> (Str -> Str) -> L -> L
|
||||||
[(Explicit,varL,typeType),(Explicit,identW,mkFunType [typeStr] typeStr),(Explicit,identW,Vr varL)] (Vr varL) []))) Nothing)
|
[(Explicit,varL,typeType),(Explicit,identW,mkFunType [typeStr] typeStr),(Explicit,identW,Vr varL)] (Vr varL) []))) Nothing)
|
||||||
|
, (cNonExist , ResOper (Just (noLoc (mkProd -- Str
|
||||||
|
[] typeStr []))) Nothing)
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
fun from to = oper (mkFunType from to)
|
fun from to = oper (mkFunType from to)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import GF.Grammar.Lookup(lookupResDefLoc,allParamValues)
|
|||||||
import GF.Grammar.Predef(cPredef,cErrorType,cTok,cStr)
|
import GF.Grammar.Predef(cPredef,cErrorType,cTok,cStr)
|
||||||
import GF.Grammar.PatternMatch(matchPattern,measurePatt)
|
import GF.Grammar.PatternMatch(matchPattern,measurePatt)
|
||||||
import GF.Grammar.Lockfield(unlockRecord,lockLabel,isLockLabel,lockRecType)
|
import GF.Grammar.Lockfield(unlockRecord,lockLabel,isLockLabel,lockRecType)
|
||||||
import GF.Compile.Compute.Value hiding (Predefined(..))
|
import GF.Compile.Compute.Value hiding (Error)
|
||||||
import GF.Compile.Compute.Predef(predef,predefName,delta)
|
import GF.Compile.Compute.Predef(predef,predefName,delta)
|
||||||
import GF.Data.Str(Str,glueStr,str2strings,str,sstr,plusStr,strTok)
|
import GF.Data.Str(Str,glueStr,str2strings,str,sstr,plusStr,strTok)
|
||||||
import GF.Data.Operations(Err,err,errIn,maybeErr,combinations,mapPairsM)
|
import GF.Data.Operations(Err,err,errIn,maybeErr,combinations,mapPairsM)
|
||||||
@@ -169,6 +169,8 @@ vconcat vv@(v1,v2) =
|
|||||||
case vv of
|
case vv of
|
||||||
(VString "",_) -> v2
|
(VString "",_) -> v2
|
||||||
(_,VString "") -> v1
|
(_,VString "") -> v1
|
||||||
|
(VApp NonExist _,_) -> v1
|
||||||
|
(_,VApp NonExist _) -> v2
|
||||||
_ -> VC v1 v2
|
_ -> VC v1 v2
|
||||||
|
|
||||||
proj l v | isLockLabel l = return (VRec [])
|
proj l v | isLockLabel l = return (VRec [])
|
||||||
@@ -243,6 +245,8 @@ glue env (v1,v2) = glu v1 v2
|
|||||||
(v1,VC va vb) -> VC (glu v1 va) vb
|
(v1,VC va vb) -> VC (glu v1 va) vb
|
||||||
(VS (VV ty pvs vs) vb,v2) -> VS (VV ty pvs [glu v v2|v<-vs]) vb
|
(VS (VV ty pvs vs) vb,v2) -> VS (VV ty pvs [glu v v2|v<-vs]) vb
|
||||||
(v1,VS (VV ty pvs vs) vb) -> VS (VV ty pvs [glu v1 v|v<-vs]) vb
|
(v1,VS (VV ty pvs vs) vb) -> VS (VV ty pvs [glu v1 v|v<-vs]) vb
|
||||||
|
(v1@(VApp NonExist _),_) -> v1
|
||||||
|
(_,v2@(VApp NonExist _)) -> v2
|
||||||
-- (v1,v2) -> ok2 VGlue v1 v2
|
-- (v1,v2) -> ok2 VGlue v1 v2
|
||||||
(v1,v2) -> error . render $
|
(v1,v2) -> error . render $
|
||||||
ppL loc (hang (text "unsupported token gluing:") 4
|
ppL loc (hang (text "unsupported token gluing:") 4
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ instance Predef String where
|
|||||||
instance Predef Value where
|
instance Predef Value where
|
||||||
toValue = id
|
toValue = id
|
||||||
fromValue = return
|
fromValue = return
|
||||||
|
|
||||||
|
instance Predef Predefined where
|
||||||
|
toValue p = VApp p []
|
||||||
|
fromValue v = case v of
|
||||||
|
VApp p _ -> return p
|
||||||
|
_ -> fail $ "Expected a predefined constant, got something else"
|
||||||
|
|
||||||
{-
|
{-
|
||||||
instance (Predef a,Predef b) => Predef (a->b) where
|
instance (Predef a,Predef b) => Predef (a->b) where
|
||||||
toValue f = VAbs Explicit (varX 0) $ Bind $ err bug (toValue . f) . fromValue
|
toValue f = VAbs Explicit (varX 0) $ Bind $ err bug (toValue . f) . fromValue
|
||||||
@@ -70,22 +77,23 @@ predefList =
|
|||||||
-- cShow, cRead, cMapStr, cEqVal
|
-- cShow, cRead, cMapStr, cEqVal
|
||||||
(cError,Error),
|
(cError,Error),
|
||||||
-- Canonical values:
|
-- Canonical values:
|
||||||
(cPBool,PBool),(cPFalse,PFalse),(cPTrue,PTrue),(cInt,Int),(cInts,Ints)]
|
(cPBool,PBool),(cPFalse,PFalse),(cPTrue,PTrue),(cInt,Int),
|
||||||
|
(cInts,Ints),(cNonExist,NonExist)]
|
||||||
--- add more functions!!!
|
--- add more functions!!!
|
||||||
|
|
||||||
delta f vs =
|
delta f vs =
|
||||||
case f of
|
case f of
|
||||||
Drop -> ap2 (drop::Int->String->String)
|
Drop -> fromNonExist vs NonExist (ap2 (drop::Int->String->String))
|
||||||
Take -> ap2 (take::Int->String->String)
|
Take -> fromNonExist vs NonExist (ap2 (take::Int->String->String))
|
||||||
Tk -> ap2 tk
|
Tk -> fromNonExist vs NonExist (ap2 tk)
|
||||||
Dp -> ap2 dp
|
Dp -> fromNonExist vs NonExist (ap2 dp)
|
||||||
EqStr -> ap2 ((==)::String->String->Bool)
|
EqStr -> fromNonExist vs PFalse (ap2 ((==)::String->String->Bool))
|
||||||
Occur -> ap2 occur
|
Occur -> fromNonExist vs PFalse (ap2 occur)
|
||||||
Occurs -> ap2 occurs
|
Occurs -> fromNonExist vs PFalse (ap2 occurs)
|
||||||
ToUpper -> ap1 (map toUpper)
|
ToUpper -> fromNonExist vs NonExist (ap1 (map toUpper))
|
||||||
ToLower -> ap1 (map toLower)
|
ToLower -> fromNonExist vs NonExist (ap1 (map toLower))
|
||||||
IsUpper -> ap1 (all isUpper)
|
IsUpper -> fromNonExist vs PFalse (ap1 (all isUpper))
|
||||||
Length -> ap1 (length::String->Int)
|
Length -> fromNonExist vs (0::Int) (ap1 (length::String->Int))
|
||||||
Plus -> ap2 ((+)::Int->Int->Int)
|
Plus -> ap2 ((+)::Int->Int->Int)
|
||||||
EqInt -> ap2 ((==)::Int->Int->Bool)
|
EqInt -> ap2 ((==)::Int->Int->Bool)
|
||||||
LessInt -> ap2 ((<)::Int->Int->Bool)
|
LessInt -> ap2 ((<)::Int->Int->Bool)
|
||||||
@@ -97,6 +105,7 @@ delta f vs =
|
|||||||
Ints -> canonical
|
Ints -> canonical
|
||||||
PFalse -> canonical
|
PFalse -> canonical
|
||||||
PTrue -> canonical
|
PTrue -> canonical
|
||||||
|
NonExist-> canonical
|
||||||
where
|
where
|
||||||
canonical = delay
|
canonical = delay
|
||||||
delay = return (VApp f vs) -- wrong number of arguments
|
delay = return (VApp f vs) -- wrong number of arguments
|
||||||
@@ -109,6 +118,10 @@ delta f vs =
|
|||||||
[v1,v2] -> toValue `fmap` (f `fmap` fromValue v1 `ap` fromValue v2)
|
[v1,v2] -> toValue `fmap` (f `fmap` fromValue v1 `ap` fromValue v2)
|
||||||
_ -> delay
|
_ -> delay
|
||||||
|
|
||||||
|
fromNonExist vs a b
|
||||||
|
| null [v | v@(VApp NonExist _) <- vs] = b
|
||||||
|
| otherwise = return (toValue a)
|
||||||
|
|
||||||
-- unimpl id = bug $ "unimplemented predefined function: "++showIdent id
|
-- unimpl id = bug $ "unimplemented predefined function: "++showIdent id
|
||||||
-- problem id vs = bug $ "unexpected arguments: Predef."++showIdent id++" "++show vs
|
-- problem id vs = bug $ "unexpected arguments: Predef."++showIdent id++" "++show vs
|
||||||
|
|
||||||
|
|||||||
@@ -51,5 +51,5 @@ data Predefined = Drop | Take | Tk | Dp | EqStr | Occur | Occurs | ToUpper
|
|||||||
{- | Show | Read | ToStr | MapStr | EqVal -}
|
{- | Show | Read | ToStr | MapStr | EqVal -}
|
||||||
| Error
|
| Error
|
||||||
-- Canonical values below:
|
-- Canonical values below:
|
||||||
| PBool | PFalse | PTrue | Int | Ints
|
| PBool | PFalse | PTrue | Int | Ints | NonExist
|
||||||
deriving (Show,Eq,Ord,Ix,Bounded,Enum)
|
deriving (Show,Eq,Ord,Ix,Bounded,Enum)
|
||||||
|
|||||||
@@ -391,6 +391,10 @@ convertTerm opts sel ctype (Alts s alts)
|
|||||||
4
|
4
|
||||||
(ppPatt Unqualified 0 p)
|
(ppPatt Unqualified 0 p)
|
||||||
|
|
||||||
|
convertTerm opts sel ctype (Q (m,f))
|
||||||
|
| m == cPredef &&
|
||||||
|
f == cNonExist = return (CStr [SymNE])
|
||||||
|
|
||||||
convertTerm opts sel@(CProj l _) ctype (ExtR t1 t2@(R rs2))
|
convertTerm opts sel@(CProj l _) ctype (ExtR t1 t2@(R rs2))
|
||||||
| l `elem` map fst rs2 = convertTerm opts sel ctype t2
|
| l `elem` map fst rs2 = convertTerm opts sel ctype t2
|
||||||
| otherwise = convertTerm opts sel ctype t1
|
| otherwise = convertTerm opts sel ctype t1
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ module GF.Grammar.Predef
|
|||||||
, cString
|
, cString
|
||||||
, cVar
|
, cVar
|
||||||
, cInts
|
, cInts
|
||||||
|
, cNonExist
|
||||||
, cPBool
|
, cPBool
|
||||||
, cErrorType
|
, cErrorType
|
||||||
, cOverload
|
, cOverload
|
||||||
@@ -94,6 +95,9 @@ cOverload = identC (BS.pack "overload")
|
|||||||
cUndefinedType :: Ident
|
cUndefinedType :: Ident
|
||||||
cUndefinedType = identC (BS.pack "UndefinedType")
|
cUndefinedType = identC (BS.pack "UndefinedType")
|
||||||
|
|
||||||
|
cNonExist :: Ident
|
||||||
|
cNonExist = identC (BS.pack "nonExist")
|
||||||
|
|
||||||
isPredefCat :: Ident -> Bool
|
isPredefCat :: Ident -> Bool
|
||||||
isPredefCat c = elem c [cInt,cString,cFloat]
|
isPredefCat c = elem c [cInt,cString,cFloat]
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,8 @@ typedef enum {
|
|||||||
PGF_SYMBOL_LIT,
|
PGF_SYMBOL_LIT,
|
||||||
PGF_SYMBOL_VAR,
|
PGF_SYMBOL_VAR,
|
||||||
PGF_SYMBOL_KS,
|
PGF_SYMBOL_KS,
|
||||||
PGF_SYMBOL_KP
|
PGF_SYMBOL_KP,
|
||||||
|
PGF_SYMBOL_NE
|
||||||
} PgfSymbolTag;
|
} PgfSymbolTag;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -208,6 +209,8 @@ typedef struct PgfSymbolKP
|
|||||||
* symbol. */
|
* symbol. */
|
||||||
} PgfSymbolKP;
|
} PgfSymbolKP;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
} PgfSymbolNE;
|
||||||
|
|
||||||
typedef GuSeq PgfSequence; // -> PgfSymbol
|
typedef GuSeq PgfSequence; // -> PgfSymbol
|
||||||
typedef GuList(PgfSequence) PgfSequences;
|
typedef GuList(PgfSequence) PgfSequences;
|
||||||
|
|||||||
@@ -532,6 +532,10 @@ pgf_lzr_linearize(PgfConcr* concr, PgfCncTree ctree, size_t lin_idx, PgfLinFuncs
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PGF_SYMBOL_NE: {
|
||||||
|
// Nothing to be done here
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
gu_impossible();
|
gu_impossible();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ pgf_prev_extern_sym(PgfSymbol sym)
|
|||||||
return *((PgfSymbol*) (((PgfSymbolLit*) i.data)+1));
|
return *((PgfSymbol*) (((PgfSymbolLit*) i.data)+1));
|
||||||
case PGF_SYMBOL_VAR:
|
case PGF_SYMBOL_VAR:
|
||||||
return *((PgfSymbol*) (((PgfSymbolVar*) i.data)+1));
|
return *((PgfSymbol*) (((PgfSymbolVar*) i.data)+1));
|
||||||
|
case PGF_SYMBOL_NE:
|
||||||
|
return *((PgfSymbol*) (((PgfSymbolNE*) i.data)+1));
|
||||||
default:
|
default:
|
||||||
gu_impossible();
|
gu_impossible();
|
||||||
return gu_null_variant;
|
return gu_null_variant;
|
||||||
@@ -1410,6 +1412,10 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
|||||||
case PGF_SYMBOL_VAR:
|
case PGF_SYMBOL_VAR:
|
||||||
// XXX TODO proper support
|
// XXX TODO proper support
|
||||||
break;
|
break;
|
||||||
|
case PGF_SYMBOL_NE: {
|
||||||
|
// Nothing to be done here
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
gu_impossible();
|
gu_impossible();
|
||||||
}
|
}
|
||||||
@@ -2743,6 +2749,7 @@ pgf_parser_leftcorner_item(PgfLeftcornerFn* clo, PgfItem* item)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PGF_SYMBOL_LIT:
|
case PGF_SYMBOL_LIT:
|
||||||
|
case PGF_SYMBOL_NE:
|
||||||
// Nothing to be done here
|
// Nothing to be done here
|
||||||
break;
|
break;
|
||||||
case PGF_SYMBOL_VAR:
|
case PGF_SYMBOL_VAR:
|
||||||
|
|||||||
@@ -258,6 +258,10 @@ pgf_print_symbol(PgfSymbol sym, GuWriter *wtr, GuExn *err)
|
|||||||
gu_printf(wtr, err, "<%d,$%d>", svar->d, svar->r);
|
gu_printf(wtr, err, "<%d,$%d>", svar->d, svar->r);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PGF_SYMBOL_NE: {
|
||||||
|
gu_puts("nonExist", wtr, err);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
gu_impossible();
|
gu_impossible();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -717,6 +717,13 @@ pgf_read_symbol(PgfReader* rdr)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PGF_SYMBOL_NE: {
|
||||||
|
gu_new_variant(PGF_SYMBOL_NE,
|
||||||
|
PgfSymbolNE,
|
||||||
|
&sym, rdr->opool);
|
||||||
|
gu_return_on_exn(rdr->err, gu_null_variant);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
pgf_read_tag_error(rdr);
|
pgf_read_tag_error(rdr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ instance Binary Symbol where
|
|||||||
put (SymVar n l) = putWord8 2 >> put (n,l)
|
put (SymVar n l) = putWord8 2 >> put (n,l)
|
||||||
put (SymKS ts) = putWord8 3 >> put ts
|
put (SymKS ts) = putWord8 3 >> put ts
|
||||||
put (SymKP d vs) = putWord8 4 >> put (d,vs)
|
put (SymKP d vs) = putWord8 4 >> put (d,vs)
|
||||||
|
put SymNE = putWord8 5
|
||||||
get = do tag <- getWord8
|
get = do tag <- getWord8
|
||||||
case tag of
|
case tag of
|
||||||
0 -> liftM2 SymCat get get
|
0 -> liftM2 SymCat get get
|
||||||
@@ -159,6 +160,7 @@ instance Binary Symbol where
|
|||||||
2 -> liftM2 SymVar get get
|
2 -> liftM2 SymVar get get
|
||||||
3 -> liftM SymKS get
|
3 -> liftM SymKS get
|
||||||
4 -> liftM2 (\d vs -> SymKP d vs) get get
|
4 -> liftM2 (\d vs -> SymKP d vs) get get
|
||||||
|
5 -> return SymNE
|
||||||
_ -> decodingError
|
_ -> decodingError
|
||||||
|
|
||||||
instance Binary PArg where
|
instance Binary PArg where
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ data Symbol
|
|||||||
| SymVar {-# UNPACK #-} !Int {-# UNPACK #-} !Int
|
| SymVar {-# UNPACK #-} !Int {-# UNPACK #-} !Int
|
||||||
| SymKS [Token]
|
| SymKS [Token]
|
||||||
| SymKP [Token] [Alternative]
|
| SymKP [Token] [Alternative]
|
||||||
|
| SymNE -- non exist
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
data Production
|
data Production
|
||||||
= PApply {-# UNPACK #-} !FunId [PArg]
|
= PApply {-# UNPACK #-} !FunId [PArg]
|
||||||
|
|||||||
Reference in New Issue
Block a user