mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Predef functions toUpper, toLower, isUpper
This commit is contained in:
@@ -26,6 +26,7 @@ import GF.Grammar.Predef
|
|||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import Text.PrettyPrint
|
import Text.PrettyPrint
|
||||||
|
import Data.Char (isUpper,toUpper,toLower)
|
||||||
|
|
||||||
-- predefined function type signatures and definitions. AR 12/3/2003.
|
-- predefined function type signatures and definitions. AR 12/3/2003.
|
||||||
|
|
||||||
@@ -67,6 +68,11 @@ primitives = Map.fromList
|
|||||||
, (cEqStr , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
, (cEqStr , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
||||||
, (cOccur , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
, (cOccur , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
||||||
, (cOccurs , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
, (cOccurs , ResOper (Just (noLoc (mkFunType [typeTok,typeTok] typePBool))) Nothing)
|
||||||
|
|
||||||
|
, (cToUpper , ResOper (Just (noLoc (mkFunType [typeTok] typeTok))) Nothing)
|
||||||
|
, (cToLower , ResOper (Just (noLoc (mkFunType [typeTok] typeTok))) Nothing)
|
||||||
|
, (cIsUpper , ResOper (Just (noLoc (mkFunType [typeTok] typePBool))) Nothing)
|
||||||
|
|
||||||
---- "read" ->
|
---- "read" ->
|
||||||
, (cRead , ResOper (Just (noLoc (mkProd -- (P : Type) -> Tok -> P
|
, (cRead , ResOper (Just (noLoc (mkProd -- (P : Type) -> Tok -> P
|
||||||
[(Explicit,varP,typePType),(Explicit,identW,typeStr)] (Vr varP) []))) Nothing)
|
[(Explicit,varP,typePType),(Explicit,identW,typeStr)] (Vr varP) []))) Nothing)
|
||||||
@@ -94,7 +100,11 @@ appPredefined t = case t of
|
|||||||
-- one-place functions
|
-- one-place functions
|
||||||
Q (mod,f) | mod == cPredef ->
|
Q (mod,f) | mod == cPredef ->
|
||||||
case x of
|
case x of
|
||||||
(K s) | f == cLength -> retb $ EInt $ length s
|
(K s) | f == cLength -> retb $ EInt $ length s
|
||||||
|
(K s) | f == cIsUpper -> retb $ if (all isUpper s) then predefTrue else predefFalse
|
||||||
|
(K s) | f == cToUpper -> retb $ K $ map toUpper s
|
||||||
|
(K s) | f == cToLower -> retb $ K $ map toLower s
|
||||||
|
|
||||||
_ -> retb t
|
_ -> retb t
|
||||||
|
|
||||||
-- two-place functions
|
-- two-place functions
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ module GF.Grammar.Predef
|
|||||||
, cLength, cDrop, cTake, cTk, cDp, cEqStr, cOccur
|
, cLength, cDrop, cTake, cTk, cDp, cEqStr, cOccur
|
||||||
, cOccurs, cEqInt, cLessInt, cPlus, cShow, cRead
|
, cOccurs, cEqInt, cLessInt, cPlus, cShow, cRead
|
||||||
, cToStr, cMapStr, cError
|
, cToStr, cMapStr, cError
|
||||||
|
, cToUpper, cToLower, cIsUpper
|
||||||
|
|
||||||
-- hacks
|
-- hacks
|
||||||
, cMeta, cAs, cChar, cChars, cSeq, cAlt, cRep
|
, cMeta, cAs, cChar, cChars, cSeq, cAlt, cRep
|
||||||
@@ -116,6 +117,15 @@ cTk = identC (BS.pack "tk")
|
|||||||
cDp :: Ident
|
cDp :: Ident
|
||||||
cDp = identC (BS.pack "dp")
|
cDp = identC (BS.pack "dp")
|
||||||
|
|
||||||
|
cToUpper :: Ident
|
||||||
|
cToUpper = identC (BS.pack "toUpper")
|
||||||
|
|
||||||
|
cToLower :: Ident
|
||||||
|
cToLower = identC (BS.pack "toLower")
|
||||||
|
|
||||||
|
cIsUpper :: Ident
|
||||||
|
cIsUpper = identC (BS.pack "isUpper")
|
||||||
|
|
||||||
cEqStr :: Ident
|
cEqStr :: Ident
|
||||||
cEqStr = identC (BS.pack "eqStr")
|
cEqStr = identC (BS.pack "eqStr")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user