diff options
| author | peb <unknown> | 2005-02-24 10:46:37 +0000 |
|---|---|---|
| committer | peb <unknown> | 2005-02-24 10:46:37 +0000 |
| commit | bf436aebaa5b84bbb50e305e8f7dc9ca4ae34299 (patch) | |
| tree | 346ac1e13a90d7b2c992c69f45b3e19c22f4bfe2 /src/GF/Data/Parsers.hs | |
| parent | 0137dd5511a83ea4672619ad3dc22fe7c51ab4bf (diff) | |
"Committed_by_peb"
Diffstat (limited to 'src/GF/Data/Parsers.hs')
| -rw-r--r-- | src/GF/Data/Parsers.hs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/GF/Data/Parsers.hs b/src/GF/Data/Parsers.hs index 8804c55f3..6dbe9611a 100644 --- a/src/GF/Data/Parsers.hs +++ b/src/GF/Data/Parsers.hs @@ -5,9 +5,9 @@ -- Stability : Almost Obsolete -- Portability : Haskell 98 -- --- > CVS $Date: 2005/02/18 19:21:15 $ +-- > CVS $Date: 2005/02/24 11:46:35 $ -- > CVS $Author: peb $ --- > CVS $Revision: 1.4 $ +-- > CVS $Revision: 1.5 $ -- -- some parser combinators a la Wadler and Hutton. -- no longer used in many places in GF @@ -142,24 +142,45 @@ lits ts = literals ts jL :: String -> Parser Char String jL = pJ . lits +pParenth :: Parser Char a -> Parser Char a pParenth p = literal '(' +.. pJunk +.. p ..+ pJunk ..+ literal ')' -pCommaList p = pTList "," (pJ p) -- p,...,p -pOptCommaList p = pCommaList p ||| succeed [] -- the same or nothing -pArgList p = pParenth (pCommaList p) ||| succeed [] -- (p,...,p), poss. empty -pArgList2 p = pParenth (p ... jL "," +.. pCommaList p) *** uncurry (:) -- min.2 args +-- | p,...,p +pCommaList :: Parser Char a -> Parser Char [a] +pCommaList p = pTList "," (pJ p) + +-- | the same or nothing +pOptCommaList :: Parser Char a -> Parser Char [a] +pOptCommaList p = pCommaList p ||| succeed [] + +-- | (p,...,p), poss. empty +pArgList :: Parser Char a -> Parser Char [a] +pArgList p = pParenth (pCommaList p) ||| succeed [] + +-- | min. 2 args +pArgList2 :: Parser Char a -> Parser Char [a] +pArgList2 p = pParenth (p ... jL "," +.. pCommaList p) *** uncurry (:) + +longestOfSome :: Parser a b -> Parser a [b] longestOfSome p = (p ... longestOfMany p) *** (\ (x,y) -> x:y) +pIdent :: Parser Char String pIdent = pLetter ... longestOfMany pAlphaPlusChar *** uncurry (:) where alphaPlusChar c = isAlphaNum c || c=='_' || c=='\'' +pLetter, pDigit :: Parser Char Char pLetter = satisfy (`elem` (['A'..'Z'] ++ ['a'..'z'] ++ ['À' .. 'Û'] ++ ['à' .. 'û'])) -- no such in Char -pDigit = satisfy isDigit -pLetters = longestOfSome pLetter +pDigit = satisfy isDigit + +pLetters :: Parser Char String +pLetters = longestOfSome pLetter + +pAlphanum, pAlphaPlusChar :: Parser Char Char pAlphanum = pDigit ||| pLetter pAlphaPlusChar = pAlphanum ||| satisfy (`elem` "_'") +pQuotedString :: Parser Char String pQuotedString = literal '"' +.. pEndQuoted where pEndQuoted = literal '"' *** (const []) |
