Encode (empty) → 0.7
raw patch · 29 files changed
+5693/−0 lines, 29 filesdep +Cabaldep +basebuild-type:Customsetup-changed
Dependencies added: Cabal, base
Files
- Encode.cabal +70/−0
- Encode.hs +111/−0
- Encode/Arabic.hs +48/−0
- Encode/Arabic/ArabTeX.hs +1152/−0
- Encode/Arabic/ArabTeX/ZDMG.hs +774/−0
- Encode/Arabic/Buckwalter.hs +108/−0
- Encode/Arabic/Byte.hs +564/−0
- Encode/Extend.hs +211/−0
- Encode/Mapper.hs +548/−0
- Encode/Unicode.hs +48/−0
- Encode/Unicode/UTF8.hs +89/−0
- FunParsing.hs +52/−0
- FunParsing/OrdMap.hs +140/−0
- FunParsing/OrdSet.hs +129/−0
- FunParsing/Parsers.hs +70/−0
- FunParsing/Parsers/AmbExTrie.hs +92/−0
- FunParsing/Parsers/AmbTrie.hs +79/−0
- FunParsing/Parsers/ExTrie.hs +94/−0
- FunParsing/Parsers/PairTrie.hs +113/−0
- FunParsing/Parsers/Parser.hs +170/−0
- FunParsing/Parsers/Standard.hs +77/−0
- FunParsing/Parsers/Stream.hs +88/−0
- FunParsing/Parsers/Trie.hs +85/−0
- INSTALL +47/−0
- LICENSE +339/−0
- LicenseBSD +9/−0
- LicenseGPL +339/−0
- Setup.hs +2/−0
- Version.hs +45/−0
+ Encode.cabal view
@@ -0,0 +1,70 @@+name: Encode+version: 0.7+license: GPL+license-file: LICENSE+extra-source-files: INSTALL, LicenseBSD, LicenseGPL+copyright: 2007+author: Otakar Smrz+maintainer: otakar.smrz mff.cuni.cz+homepage: http://ufal.mff.cuni.cz/~smrz/+package-url: http://ufal.mff.cuni.cz/~smrz/Encode/Encode-0.7.tar.gz+category: Various+build-depends: Cabal, base+synopsis: Encoding character data+description: The "Encode" library is being proposed as a Haskell+ analogy to the /Encode/ extension in Perl,+ <http://search.cpan.org/dist/Encode/>.+ .+ Like its counterpart, "Encode" should provide a unified+ interface for converting strings from different encodings+ into a common representation, and vice versa. The+ representation should be isomorphic to the Unicode+ character set, and the encodings might be both standard+ and user-defined. For this purpose, the "Encode" module+ defines the 'Encode.UPoint' type and the+ 'Encode.Encoding' type class.+ .+ The "FunParsing" library is an edited excerpt from the+ /Functional Parsing/ library developed by Peter+ Ljunglöf in his licenciate thesis /Pure Functional+ Parsing – an advanced tutorial/, Göteborg+ University and Chalmers University of Technology, April+ 2002, <http://www.cs.chalmers.se/~peb/software.html>.+ .+ The "Version" library is just a simple support for+ working with the CVS\/SVN revision keyword.+ .+ This software is published under the /GNU General Public+ License/. Only the "Encode".hs and "Version".hs files are+ instead subject to the /Revised BSD License/. Note the+ copyright and license details in the headers of the+ files, and see "LICENSE", "LicenseBSD" and "LicenseGPL"+ distributed with this package.+ .+ "Encode" "FunParsing" "Version"+exposed-modules: Encode,+ Encode.Arabic,+ Encode.Arabic.ArabTeX,+ Encode.Arabic.ArabTeX.ZDMG,+ Encode.Arabic.Buckwalter,+ Encode.Arabic.Byte,+ Encode.Extend,+ Encode.Mapper,+ Encode.Unicode,+ Encode.Unicode.UTF8,+ FunParsing,+ FunParsing.OrdMap,+ FunParsing.OrdSet,+ FunParsing.Parsers,+ FunParsing.Parsers.AmbExTrie,+ FunParsing.Parsers.AmbTrie,+ FunParsing.Parsers.ExTrie,+ FunParsing.Parsers.PairTrie,+ FunParsing.Parsers.Parser,+ FunParsing.Parsers.Standard,+ FunParsing.Parsers.Stream,+ FunParsing.Parsers.Trie,+ Version+extensions: MultiParamTypeClasses,+ FunctionalDependencies,+ ExistentialQuantification
+ Encode.hs view
@@ -0,0 +1,111 @@+-- --------------------------------------------------------------------------+-- $Revision: 15 $ $Date: 2006-03-07 13:05:15 +0100 (Tue, 07 Mar 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode+-- Copyright : Otakar Smrz 2005-2006+-- License : BSD-style+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- The Haskell analogy to the /Encode/ module in Perl:+-- <http://search.cpan.org/dist/Encode/>+--+-- "Encode.Arabic" "Encode.Mapper" "Encode.Unicode"+++module Encode (++ -- * Classes++ Encoding,++ -- * Types++ UPoint,++ -- * Methods++ encode, decode++ ) where+++import Version++version = revised "$Revision: 15 $"+++-- | The datatype introduced for the internal representation of Unicode code+-- points is currently defined as @newtype 'UPoint' = UPoint Int@. The+-- shift to code points @UPoint@ from characters @Char@ is intentional, as+-- Unicode support in Haskell is not yet fully implemented, and code points+-- are, anyway, different entities. Since the 'UPoint' type is an instance+-- of the @Enum@ class, the type's constructor and destructor functions are+-- available as 'toEnum' and 'fromEnum', respectively.+--+-- The 'UPoint' datatype should be the transfer point on the way from one+-- encoding into another. It should not be the terminal stop, though. The+-- 'encode' method should be used systematically, and not @show@, even if+-- it might temporarily produce somehow appealing results.++newtype UPoint = UPoint Int++ deriving (Eq, Ord)+++-- | Encodings are represented as distinct datatypes of the 'Encoding' class,+-- which defines two essential methods:+--+-- ['encode'] turning a list of 'internal code points' into a @String@, and+--+-- ['decode'] converting the lists in the opposite direction.+--+-- Developing a new encoding means to write a new module with a structure+-- similar to this:+--+-- @+-- module /MyEncModule/ (/MyEncType/ (..)) where+-- / /+-- import "Encode"+-- / /+-- data /MyEncType/ = /MyEncName | MyEncAlias deriving (Enum, Show)/+-- / /+-- instance 'Encoding' /MyEncType/ where+-- / /+-- 'encode' /enc data/ = /show data/ /-- your choices .../+-- / /+-- 'decode' /enc data/ = /map (toEnum . fromEnum) data/+-- @+--+-- "Encode.Unicode.UTF8" is one concrete implementation that realizes+-- and illustrates this template. "Encode.Arabic.Buckwalter" implements+-- symmetric recoding using finite maps, and "Encode.Arabic.ArabTeX"+-- makes use of monadic parsing and the "FunParsing" library.++class Encoding e where++ encode :: e -> [UPoint] -> [Char]+ decode :: e -> [Char] -> [UPoint]++ encode _ = map (toEnum . fromEnum)+ decode _ = map (toEnum . fromEnum)+++instance Show UPoint where++ showsPrec p (UPoint x)+ | x == 38 = showsPrec p "&"+ | x >= 32 && x <= 255 = showsPrec p (toEnum x :: Char)+ | otherwise = showsPrec p ("&#" ++ showsPrec p x ";")+++instance Enum UPoint where++ fromEnum (UPoint x) = x++ toEnum = UPoint
+ Encode/Arabic.hs view
@@ -0,0 +1,48 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Arabic+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- The Haskell version of /Encode::Arabic/ originally written in Perl:+-- <http://search.cpan.org/dist/Encode-Arabic/>+--+-- "Encode.Arabic.ArabTeX"+-- "Encode.Arabic.ArabTeX.ZDMG"+-- "Encode.Arabic.Buckwalter"+++module Encode.Arabic (++ -- * Modules++ module Encode.Arabic.ArabTeX,+ module Encode.Arabic.ArabTeX.ZDMG,+ module Encode.Arabic.Buckwalter,+ module Encode.Arabic.Byte,++ module Encode.Unicode++ ) where+++import Encode++import Encode.Arabic.ArabTeX+import Encode.Arabic.ArabTeX.ZDMG+import Encode.Arabic.Buckwalter+import Encode.Arabic.Byte++import Encode.Unicode++import Version++version = revised "$Revision: 130 $"
+ Encode/Arabic/ArabTeX.hs view
@@ -0,0 +1,1152 @@+-- --------------------------------------------------------------------------+-- $Revision: 190 $ $Date: 2007-01-27 14:47:15 +0100 (Sat, 27 Jan 2007) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Arabic.ArabTeX+-- Copyright : Otakar Smrz 2005-2007+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- /Encode::Arabic::ArabTeX/ in Perl:+-- <http://search.cpan.org/dist/Encode-Arabic/lib/Encode/Arabic/ArabTeX.pm>+--+-- "Encode.Extend"+-- "Encode.Mapper"+++module Encode.Arabic.ArabTeX (++ -- * Types++ ArabTeX (..),++ -- * Functions++ tokens, events++ ) where+++import Encode++import Encode.Mapper+import Encode.Extend++import FunParsing.OrdMap++import Version++version = revised "$Revision: 190 $"+++data ArabTeX = ArabTeX | Lagally | TeX++ deriving (Enum, Show)+++instance Encoding ArabTeX where++ encode _ = error "Encode.Arabic.ArabTeX: 'encode' not implemented"++ decode _ = concat . parseFull decoderParsing .+ concat . parseLongest decoderMapping+++encoder :: Mapper UPoint [[[Char]]]++encoder = error "Encode.Arabic.ArabTeX: 'encoder' not implemented"+++tokens :: String -> [String]++tokens = concat . parseLongest decoderMapping+++events :: String -> [[String]]++events = parseLongest decoderMapping+++-- --------------------------------------------------------------------------+-- Extend and ExtEnv Definitions+-- --------------------------------------------------------------------------+++data Mode = NonePlus | Novocalize | Vocalize | Fullvocalize++ deriving (Eq, Ord)+++data Env i = Env { envQuote :: Bool, envMode :: Mode,+ envWasla :: Bool, envVerb :: Bool, envEarly :: [i] }+++setQuote q (Env _ m w v e) = Env q m w v e++setMode m (Env q _ w v e) = Env q m w v e++setWasla w (Env q m _ v e) = Env q m w v e++setVerb v (Env q m w _ e) = Env q m w v e++setEarly e (Env q m w v _) = Env q m w v e+++instance ExtEnv Env where++ initEnv = Env False Vocalize False False []+++-- --------------------------------------------------------------------------+-- Parsing Definitions+-- --------------------------------------------------------------------------+++type Parsing = Extend Env [Char] ([UPoint] -> [UPoint])++type Environ = Env [Char]++--(4010490 reductions, 10407991 cells, 1 garbage collection)+--(3184454 reductions, 7137461 cells, 1 garbage collection)+--(3184377 reductions, 7137402 cells, 1 garbage collection)++--(6312 reductions, 13922 cells)+-- ??(830524 reductions, 3279470 cells)++--type Parsing = Extend [Char] [UPoint]++--(4085807 reductions, 10541087 cells, 1 garbage collection)+--(3259698 reductions, 7270510 cells, 1 garbage collection)++--(12760 reductions, 28250 cells)+--(6443 reductions, 14160 cells)+-- ??(830651 reductions, 3279696 cells)+++vowelControl :: OrdMap m+ => [Char] -> [Char] -> [m [Char] [UPoint]] -> Environ -> [[UPoint]]++vowelControl c x l e = case c of++ "W" -> case sukun ? x of++ Just s -> if envQuote e then theWasla else [[]]+ Nothing -> if envQuote e then [ j ++ n | j <- justAlif,+ n <- noChange ]+ else case envMode e of++ Fullvocalize -> if envWasla e+ then [ j ++ drop 1 n | j <- theWasla,+ n <- noChange ]+ else [ j ++ n | j <- justAlif,+ n <- noChange ]++ Vocalize -> if envWasla e+ then [ j ++ drop 1 n | j <- justAlif,+ n <- noChange ]+ else [ j ++ n | j <- justAlif,+ n <- noChange ]++ _ -> [ j ++ f | j <- justAlif, f <- filterIt ]++ "|" -> case sukun ? x of++ Just s -> if envQuote e then noChange else [[]]+ Nothing -> if envQuote e then filterIt else noChange++ "'A" -> case sukun ? x of++ Just s -> if envQuote e then noChange else [[]]+ Nothing -> if envQuote e then filterIt else noChange++ _ -> case sukun ? x of++ Just s -> if envMode e > Vocalize && not (envQuote e) ||+ not (envMode e > Vocalize) && envQuote e+ then noChange+ else [[]]++ Nothing -> if envMode e > Novocalize && not (envQuote e) ||+ not (envMode e > Novocalize) && envQuote e+ then noChange+ else filterIt++ where theWasla = lookupList "W" [wasla]+ justAlif = lookupList "W" [silent]+ noChange = lookupList x l+ filterIt = [ filter (flip all ([0x064B .. 0x0650] +++ [0x0656, 0x0657, 0x0670])+ . ((/=) . fromEnum)) s+ | s <- lookupList x l ]+++shaddaControl :: (OrdMap m, Ord s) => s -> [m s [a]] -> Environ -> [[a]]++shaddaControl x l e = if envMode e > NonePlus then lookupList x l else [[]]+++infixr 7 `plus` -- infixr 9 .+ -- infixr 5 ++++plus :: (a -> b) -> (c -> a) -> c -> b+plus = (.)+--plus :: [a] -> [a] -> [a]+--plus = (++)+++decoderParsing :: Extend Env [Char] [UPoint]++decoderParsing = (fmap (foldr ($) []) . again) $+--decoderParsing = (fmap (flip ($) [] . foldr (.) id) . again) $+--decoderParsing = (fmap concat . again) $+--decoderParsing = (fmap (foldr (++) []) . again) $++ parseHyphen++ <|> parseHamza+ <|> parseDefArticle++ <|> parseDoubleCons+ <|> parseSingleCons+ <|> parseInitVowel++ <|> parseWhite+ <|> parsePunct++ <|> parseDigit++ <|> parseQuote+ <|> parseControl++ <|> parseAnything++ <|> returnError+++returnError :: Parsing+returnError = do x <- inspectIList+ sat (const True)+ return (error (show x))+++parseAnything :: Parsing+parseAnything = do x <- sat (const True)+ return ((++) (map (toEnum . fromEnum) x))+++parseNothing :: Parsing+parseNothing = return id+++parseQuote = do lower ["\\\""] []+ processControl "\""++ {-+ do i <- inspectInps+ case i of+ "\\\"" : s -> processControl "\"" s+ _ -> zero+ parseNothing+ -}+++parseControl =+ do i <- inspectIList+ case i of+ [] -> zero+ (c : s) -> case c of+ '\\' : t : r -> do returnIList s+ processControl (t : r)+ "\\" -> fail "Single \\"+ _ -> zero+++processControl :: [Char] -> Parsing+processControl t =+ do e <- inspectEList+ let envList = case e of++ [] -> error "Empty environment"+ (q : r) -> case t of++ "{" -> q : q : r+ "}" -> case r of+ [] -> error "Minus group"+ _ -> r++ "\"" -> setQuote True q : r+ "cap" -> setQuote True q : r++ "fullvocalize" -> setMode Fullvocalize q : r+ "full" -> setMode Fullvocalize q : r+ "vocalize" -> setMode Vocalize q : r+ "nosukuun" -> setMode Vocalize q : r+ "novocalize" -> setMode Novocalize q : r+ "novowels" -> setMode Novocalize q : r+ "none" -> setMode Novocalize q : r+ "noshadda" -> setMode NonePlus q : r+ "noneplus" -> setMode NonePlus q : r++ "setverb" -> setVerb True q : r+ "setarab" -> setVerb False q : r++ _ -> error "Weird control sequence"++ returnEList envList+ parseNothing+++parseHamza =+ do h <- oneof [hamza]+ e <- inspectEnv+ let combineWithCarrier = case envVerb e of+ True -> parseVerbHamza h+ False -> parseArabHamza h++ ; do lower [h] []+ b <- combineWithCarrier+ lower [] [b, b]+ <|>+ do lower ["-", h] []+ b <- combineWithCarrier+ lower [] [b, "-", b]+ <|>+ do b <- combineWithCarrier+ lower [] [b]++ parseNothing+++parseVerbHamza :: [Char] -> Extend Env [Char] [Char]+parseVerbHamza h =+ do i <- inspectIList+ case i of+ x : y -> returnIList ((h ++ x) : y)+ _ -> returnIList [h]+ oneof [bound]+++parseArabHamza :: [Char] -> Extend Env [Char] [Char]+parseArabHamza h =+ do e <- inspectEnv+ b <- prospectCarrier+ let carryHamza = case envEarly e of++ [] -> case b of++ "'y" -> "'i"+ "'i" -> "'i"+ "'A" -> "'A"+ _ -> "'a"++ "i" : _ -> "'y"+ "_i" : _ -> "'y"+ "e" : _ -> "'y"++ "I" : _ -> caseofMultiI b+ "_I" : _ -> caseofMultiI b+ "E" : _ -> caseofMultiI b+ "^I" : _ -> caseofMultiI b++ ["", "y"] -> caseofMultiI b++ "u" : _ -> caseofVowelU b+ "_u" : _ -> caseofVowelU b+ "o" : _ -> caseofVowelU b++ "U" : _ -> caseofMultiU b+ "_U" : _ -> caseofMultiU b+ "O" : _ -> caseofMultiU b+ "^U" : _ -> caseofMultiU b++ "a" : _ -> caseofVowelA b+ "_a" : _ -> caseofVowelA b++ "A" : _ -> caseofMultiA b+ "^A" : _ -> caseofMultiA b++ ["", "'A"] -> caseofMultiA b++ "" : _ -> case b of++ "'i" -> "'i"+ "'a" -> "'a"+ "'y" -> "'y"+ "'w" -> "'w"+ "'A" -> "'A"+ _ -> "'|"++ _ -> error "Other context for carrier"++ case carryHamza of++ "'A" -> lower ["A"] []+ _ -> return []++ return carryHamza+++ where prospectCarrier = do parseQuote+ b <- lookaheadCarrier+ lower [] ["\\\""]+ resetEnv setQuote False+ return b+ <|> lookaheadCarrier++ caseofMultiI b = case b of+ "'i" -> "'|"+ "'|" -> "'|"+ _ -> "'y"++ caseofMultiU b = case b of+ "'|" -> "'|"+ "'y" -> "'y"+ "'i" -> "'y"+ "'a" -> "'w"+ _ -> "'w"++ caseofMultiA b = case b of+ "'y" -> "'y"+ "'w" -> "'w"+ _ -> "'|"++ caseofVowelU b = case b of+ "'y" -> "'y"+ _ -> "'w"++ caseofVowelA b = case b of+ "'y" -> "'y"+ "'w" -> "'w"+ "'i" -> "'i"+ "'A" -> "'A"+ _ -> "'a"++ lookaheadCarrier =++ do v <- oneof' '-' [multi, other] <|>+ oneof [multi, other]+ let carryHamza = case v of++ "I" -> "'y"+ "_I" -> "'y"+ "^I" -> "'y"+ "E" -> "'y"++ "U" -> "'w"+ "_U" -> "'w"+ "^U" -> "'w"+ "O" -> "'w"++ "A" -> "'A"++ _ -> "'a"++ lower [] [v]+ return carryHamza++ <|>+ do v <- oneof [vowel, nuuns] <|> return ""+ c <- oneof [sunny, moony, taaaa, invis, silent]+ let carryHamza = case v of++ "i" -> "'y"+ "iN" -> "'y"+ "_i" -> "'y"+ "e" -> "'y"++ "u" -> "'w"+ "uN" -> "'w"+ "_u" -> "'w"+ "o" -> "'w"++ "a" -> "'a"+ "aN" -> "'a"+ "_a" -> "'a"++ _ -> "'|"++ case v of "" -> lower [] [c]+ _ -> lower [] [v, c]++ return carryHamza++ <|>+ do v <- oneof [vowel, nuuns] <|> return ""+ let carryHamza = case v of++ "i" -> "'i"+ "iN" -> "'i"+ "_i" -> "'i"+ "e" -> "'i"++ _ -> "'|"++ case v of "" -> lower [] []+ _ -> lower [] [v]++ return carryHamza+++parseInitVowel =+ do v <- oneof [vowel, multi, nuuns, other] <|> (parseQuote+ >> oneof [vowel, multi, nuuns, other] <|> return "")+ -- x <- upper ["W"] [silent] -- depends on 'vowelControl'+ y <- upperWith (vowelControl "W")+ [v] [vowel, multi, nuuns, other]+ completeSyllable ["W", v] y+++parseSyllVowel :: [Char] -> ([UPoint] -> [UPoint]) -> Parsing+--parseSyllVowel :: [Char] -> [UPoint] -> Parsing+parseSyllVowel c x =+ do v <- parseQuote <|> parseNothing+ >> oneof' '-' [vowel, multi, nuuns, other] <|>+ oneof [vowel, multi, nuuns, other] <|> return ""+ y <- upperWith (vowelControl c)+ [v] [vowel, multi, nuuns, other, sukun]+ completeSyllable [c, v] (x `plus` y)+++completeSyllable :: [[Char]] -> ([UPoint] -> [UPoint]) -> Parsing+completeSyllable l u =+ do resetEnv setQuote False+ resetEnv setWasla True+ resetEnv setEarly (reverse l)+ return u+++parseSingleCons =+ do c <- oneof [consonant, taaaa, invis, silent]+ x <- upper [c] [consonant, taaaa, invis, silent]+ parseSyllVowel c x+++parseDoubleCons =+ do c <- oneof [consonant, taaaa, invis, silent]+ lower [c] []+ x <- upper [c] [consonant, taaaa, invis, silent]+ y <- upperWith shaddaControl+ ["*"] [shadda]+ parseSyllVowel c (x `plus` y)+++parseHyphen =+ do lower ["-"] []+ resetEnv setEarly []+ parseNothing+++parseDefArticle =+ do c <- oneof [consonant] -- [sunny]+ lower ["-", c] [c, c]+ upper ["l"] [sunny]++ {-+ do c <- oneof [consonant]+ lower ["-", c]+ x <- upper ["l", c] [consonant]+ y <- upper ["*"] [shadda]+ return (x ++ y)+ -}++ {-+ anyof [+ do lower [cl, cl]+ do do lower [sl] <+> lower []+ upper [cr, sr]+ <+>+ do lower [vl]+ upper [cr, dr, vr]++ | (cl,cr) <- sunny ++ moony, (vl,vr) <- short,+ (sl,sr) <- sukun, (dl,dr) <- sadda ]+ -}+++parseDigit =+ do d <- oneof [digit]+ upper [d] [digit]+++parseWhite =+ do w <- oneof [white]+ resetEnv setEarly []+ upper [w] [white]+++parsePunct =+ do p <- oneof [punct]+ resetEnv setWasla False+ upper [p] [punct]+++-- --------------------------------------------------------------------------+-- Mapping Definitions+-- --------------------------------------------------------------------------+++type Mapping = Mapper Char (Quit Char [[Char]])+++pairs :: (OrdMap m, Ord s) => [m s a] -> [(s, a)]+pairs l = concat [ assocs i | i <- l ]++elems :: (OrdMap m, Ord s) => [m s a] -> [s]+elems l = (map fst . concat) [ assocs i | i <- l ]++quote :: OrdMap m => [m [Char] a] -> [[Char]]+quote = map ("\"" ++) . elems+++decoderMapping :: Mapper Char (Quit Char [[Char]])++decoderMapping = defineMapping+ ( pairs [ sunny, moony, invis, empty, taaaa, silent,+ vowel, multi, nuuns, other, sukun, shadda,+ -- white,+ digit, punct ] )+ <+> rules++ `others` (\ s -> (Just . return) ([], [[s]]))++-- <+> "" |.| error "Illegal symbol"+++defineMapping :: [([Char], [a])] -> Mapping++defineMapping = foldr (listing . mapping) zero++ where listing = (<+>)+ mapping (encoded, _) = symbols encoded++ symbols = fmap (((,) []) . (: [])) . syms+++whites :: Mapper Char (Quit Char Char)++whites = (fmap ((,) []) . anySymbol) [' ', '\r', '\v', '\f']+ -- [' ', '\n', '\r', '\t', '\v', '\f']+++rules :: Mapping++rules =++ "aN_A" |-| "aNY" |:| [] |+|+ "iN_A" |-| "iNY" |:| [] |+|+ "uN_A" |-| "uNY" |:| [] |+|+ "_A" |-| "Y" |:| []++ |+| ruleVerbalSilentAlif+ |+| ruleInternalTaaaa+ |+| ruleInternalYaaaa++ |+| ruleLiWithArticle+ |+| ruleDefArticle+ |+| ruleIndefArticle++ |+| ruleMultiVowel+ |+| ruleHyphenedVowel++ |+| ruleWhitePlusControl+ |+| ruleIgnoreCapControl+ |+| ruleControlSequence++ |+| rulePunctuation+++rulePunctuation =++ "-" |.| ["-"] |+|+ "\"" |.| ["\\\""] |+|+ "\\\"" |.| ["\""]+++ruleVerbalSilentAlif =++ "aWA" |-| "awW" |:| [] |+|+ "aW" |-| "awW" |:| [] |+|+ "UA" |-| "UW" |:| [] |+|+ "uW" |-| "UW" |:| []+++ruleWhitePlusControl =++ "{" |.| ["\\{"] |+|+ "}" |.| ["\\}"] |+|++ "\\{" |.| ["{"] |+|+ "\\}" |.| ["}"] |+|++ "\\\\" |.| ["\\\\"] |+|+ "\\" |.| ["\\"]++ <+> sym '\\' <.> some whites <-> [" "]++ <+> some whites <-> [" "]+++ruleIgnoreCapControl =++ do syms "\\cap"+ many whites+ return ([], [])++ |+| anyof [++ "l" ++ v ++ "-a" ++ c ++ "-" ++ "\\cap " |-|+ "l" ++ v ++ "-a" ++ c ++ "-" ++ "\\cap " |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" ++ "\\cap " |-|+ "l" ++ v ++ "-a" ++ c ++ "-" |:| []++ | c <- elems [sunny, moony],+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]+++ |+| anyof [++ "l" ++ "-" ++ c ++ "\\cap " |-|+ "l" ++ "-" ++ c ++ "\\cap " |:| [] |+|++ "l" ++ "-" ++ c ++ "\\cap " |-|+ "l" ++ "-" ++ c |:| [] |+|++ c ++ "-" ++ "\\cap " |-|+ c ++ "-" ++ "\\cap " |:| [] |+|++ c ++ "-" ++ "\\cap " |-|+ c ++ "-" |:| []++ | c <- elems [sunny, moony] ]+++ruleControlSequence =++ do x <- sym '\\' <:>+ some (anySymbol (['A'..'Z'] ++ ['a'..'z']))+ many whites+ return ([], [x])++ {-+ fmap (:[]) (fmap (++) ( sym '\\'+ <:> some (anySymbol (['A'..'Z'] ++ ['a'..'z'])) )+ <*> many white <-> "")+ -}+++ruleLiWithArticle =++ anyof [+ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ c ++ "-" ++ c |:| []++ | c <- elems [sunny, moony], c /= "l",+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]++ |+| anyof [++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" |-|+ "l" ++ v ++ c ++ "-" |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| []++ | c <- elems [sunny, moony], c == "l",+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]++ {-+ anyof [ case c of++ "l" ->++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" |-|+ "l" ++ v ++ "|-" ++ c ++ "-" |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| []++ _ ->++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ c ++ "-" ++ c |:| []++ | c <- elems [sunny, moony],+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]+ -}+++ruleDefArticle =++ anyof [+ "l" ++ "-" ++ c ++ c |-|+ "-" ++ c |:| [c]++ | c <- elems [sunny, moony] ]++ {-+ foldr (\ c -> (|+|) (++ "l" ++ "-" ++ c ++ c |-|+ "-" ++ c |:| [c]++ ) ) zero (elems [sunny, moony])+ -}+++ruleIndefArticle =++ anyof [+ c ++ m ++ "aNY" |-| m ++ "aNY" |:| [c] |+|+ c ++ m ++ "aNU" |-| m ++ "aNU" |:| [c] |+|+ c ++ m ++ "aNA" |-| m ++ "aNA" |:| [c] |+|+ c ++ m ++ "aN" |-| m ++ "aNA" |:| [c]++ | c <- elems [sunny, moony], m <- ["", "-", "\"", "-\""] ]++ |+| anyof [++ v ++ "''" ++ m ++ "aN" |-|+ m ++ "aN" |:| [v, "'", "'"] |+|++ v ++ "'" ++ m ++ "aN" |-|+ m ++ "aN" |:| [v, "'"]++ | v <- ["A", "a"], m <- ["", "-", "\"", "-\""] ]+++ruleMultiVowel =++ "iy" |-| "I" |:| [] |+|+ "Iy" |-| "yy" |:| ["i"] |+|++ "uw" |-| "U" |:| [] |+|+ "Uw" |-| "ww" |:| ["u"] |+|++ "ii" |-| "I" |:| [] |+|+ "uu" |-| "U" |:| [] |+|++ "aa" |-| "A" |:| []++ |+| anyof [++ "iy" ++ v |-| "y" ++ v |:| ["i"] |+|+ "uw" ++ v |-| "w" ++ v |:| ["u"]++ | v <- elems [vowel, multi, nuuns, other] +++ quote [vowel, multi, nuuns, other, sukun] ]+++ruleHyphenedVowel =++ anyof [+ "-" ++ v |.| ["-" ++ v] |+|++ -- "-\"" ++ v |.| ["\\\"", "-" ++ v] |+|++ "-\"" ++ v |-| "\"-" ++ v |:| [] |+|++ -- "-" ++ v |-| v |:| [] |+|++ "iy-" ++ v |-| "y-" ++ v |:| ["i"] |+|+ "uw-" ++ v |-| "w-" ++ v |:| ["u"] |+|++ "W-" ++ v |-| "W" |:| [v]++ | v <- elems [vowel, multi, nuuns, other] ]++ |+| anyof [++ "iy-" ++ v |-| "y-" ++ v |:| ["i"] |+|+ "uw-" ++ v |-| "w-" ++ v |:| ["u"] |+|++ "W-" ++ v |-| "W" |:| [v]++ | v <- quote [vowel, multi, nuuns, other, sukun] ]++ |+| anyof [++ "-" ++ v ++ c |-| v ++ c |:| ["-"] |+|+ "-\"" ++ v ++ c |-| "\"" ++ v ++ c |:| ["-"] |+|++ "iy-" ++ v ++ c |-| "-" ++ v ++ c |:| ["I"] |+|+ "uw-" ++ v ++ c |-| "-" ++ v ++ c |:| ["U"] |+|++ "W-" ++ v ++ c |-| v ++ c |:| ["W", "-"]++ | c <- elems [sunny, moony, invis],+ v <- elems [vowel, multi, nuuns, other] +++ quote [vowel, multi, nuuns, other, sukun] ]++ |+| anyof [++ "iy-" ++ v ++ c |-| "-" ++ v ++ c |:| ["I"] |+|+ "uw-" ++ v ++ c |-| "-" ++ v ++ c |:| ["U"] |+|++ "W-" ++ v ++ c |-| v ++ c |:| ["W", "-"]++ | c <- elems [sunny, moony, invis],+ v <- quote [vowel, multi, nuuns, other, sukun] ]+++ruleInternalTaaaa =++ anyof [+ "T" ++ v |-| "t" ++ v |:| [] |+|+ "H" ++ v |-| "t" ++ v |:| []++ | v <- elems [multi, other] ++ quote [multi, other] ]++ |+| anyof [++ "T" ++ v ++ c |-| "t" ++ v ++ c |:| [] |+|+ "H" ++ v ++ c |-| "t" ++ v ++ c |:| []++ | c <- elems [sunny, moony, invis, taaaa],+ v <- elems [vowel, nuuns] +++ quote [vowel, nuuns, sukun] ]+++ruleInternalYaaaa =++ anyof [+ "Y" ++ c |-| "A" ++ c |:| []++ | c <- elems [sunny, moony, invis] ]+++-- --------------------------------------------------------------------------+-- LowerUp Definitions+-- --------------------------------------------------------------------------+++type LowerUp = Map [Char] [UPoint]+++unionMap :: (OrdMap m, Ord s, Ord a) => [m s a] -> m s a++unionMap = unionMapWith (\ x y -> if compare x y == EQ+ then error "Inconsistent mapping in the Maps"+ else y)+++define :: [([Char], [Int])] -> LowerUp++define l = makeMapWith const [ (x, map toEnum y) | (x, y) <- l ]+++consonant :: LowerUp+consonant = unionMap [sunny, moony, bound]+++sunny = define [+ ( "t", [ 0x062A ] ),+ ( "_t", [ 0x062B ] ),+ ( "d", [ 0x062F ] ),+ ( "_d", [ 0x0630 ] ),+ ( "r", [ 0x0631 ] ),+ ( "z", [ 0x0632 ] ),+ ( "s", [ 0x0633 ] ),+ ( "^s", [ 0x0634 ] ),+ ( ".s", [ 0x0635 ] ),+ ( ".d", [ 0x0636 ] ),+ ( ".t", [ 0x0637 ] ),+ ( ".z", [ 0x0638 ] ),+ ( "l", [ 0x0644 ] ),+ ( "n", [ 0x0646 ] )+ ]+++invis = define [+ ( "|", [ ] )+ ]+++empty = define [+ ( "", [ 0x0627 ] )+ ]+++sukun = define [+ ( "", [ 0x0652 ] ),+ ( "+", [ 0x0652 ] )+ ]+++shadda = define [+ ( "*", [ 0x0651 ] )+ ]+++silent = define [+ ( "A", [ 0x0627 ] ),+ ( "W", [ 0x0627 ] )+ ]+++wasla = define [+ ( "W", [ 0x0671 ] )+ ]+++taaaa = define [+ ( "T", [ 0x0629 ] ),+ ( "H", [ 0x0629 ] )+ ]+++bound = define [+ ( "'A", [ 0x0622 ] ),+ ( "'a", [ 0x0623 ] ),+ ( "'i", [ 0x0625 ] ),+ ( "'w", [ 0x0624 ] ),+ ( "'y", [ 0x0626 ] ),+ ( "'|", [ 0x0621 ] )+ ]+++hamza = define [+ ( "'", [ 0x0621 ] )+ ]+++moony = define [+ ( "'", [ 0x0621 ] ),+ ( "b", [ 0x0628 ] ),+ ( "^g", [ 0x062C ] ),+ ( ".h", [ 0x062D ] ),+ ( "_h", [ 0x062E ] ),+ ( "`", [ 0x0639 ] ),+ ( ".g", [ 0x063A ] ),+ ( "f", [ 0x0641 ] ),+ ( "q", [ 0x0642 ] ),+ ( "k", [ 0x0643 ] ),+ ( "m", [ 0x0645 ] ),+ ( "h", [ 0x0647 ] ),+ ( "w", [ 0x0648 ] ),+ ( "y", [ 0x064A ] ),++ ( "B", [ 0x0640 ] ),++ ( "p", [ 0x067E ] ),+ ( "v", [ 0x06A4 ] ),+ ( "g", [ 0x06AF ] ),++ ( "c", [ 0x0681 ] ),+ ( "^c", [ 0x0686 ] ),+ ( ",c", [ 0x0685 ] ),+ ( "^z", [ 0x0698 ] ),+ ( "^n", [ 0x06AD ] ),+ ( "^l", [ 0x06B5 ] ),+ ( ".r", [ 0x0695 ] )+ ]+++vowel = define [+ ( "a", [ 0x064E ] ),+ ( "i", [ 0x0650 ] ),+ ( "u", [ 0x064F ] ),++ ( "e", [ 0x0650 ] ),+ ( "o", [ 0x064F ] ),++ ( "_a", [ 0x0670 ] ),+ ( "_i", [ 0x0656 ] ),+ ( "_u", [ 0x0657 ] )+ ]+++multi = define [+ ( "A", [ 0x064E, 0x0627 ] ),+ ( "I", [ 0x0650, 0x064A ] ),+ ( "U", [ 0x064F, 0x0648 ] ),+ ( "Y", [ 0x064E, 0x0649 ] ),++ ( "E", [ 0x0650, 0x064A ] ),+ ( "O", [ 0x064F, 0x0648 ] ),++ ( "_I", [ 0x0650, 0x0627 ] ),+ ( "_U", [ 0x064F, 0x0648 ] ),++ ( "uNY", [ 0x064C, 0x0649 ] ),+ ( "uNU", [ 0x064C, 0x0648 ] ),+ ( "uNA", [ 0x064C, 0x0627 ] ),++ ( "iNY", [ 0x064D, 0x0649 ] ),+ ( "iNU", [ 0x064D, 0x0648 ] ),+ ( "iNA", [ 0x064D, 0x0627 ] ),++ ( "aNY", [ 0x064B, 0x0649 ] ),+ ( "aNU", [ 0x064B, 0x0648 ] ),+ ( "aNA", [ 0x064B, 0x0627 ] )+ ]+++nuuns = define [+ ( "aN", [ 0x064B ] ),+ ( "iN", [ 0x064D ] ),+ ( "uN", [ 0x064C ] )+ ]+++other = define [+ ( "_aY", [ 0x0670, 0x0649 ] ),+ ( "_aU", [ 0x0670, 0x0648 ] ),+ ( "_aI", [ 0x0670, 0x064A ] ),++ ( "^A", [ 0x064F, 0x0627, 0x0653 ] ),+ ( "^I", [ 0x0650, 0x064A, 0x0653 ] ),+ ( "^U", [ 0x064F, 0x0648, 0x0653 ] )+ ]+++digit = define [+ ( "0", [ 0x0660 ] ),+ ( "1", [ 0x0661 ] ),+ ( "2", [ 0x0662 ] ),+ ( "3", [ 0x0663 ] ),+ ( "4", [ 0x0664 ] ),+ ( "5", [ 0x0665 ] ),+ ( "6", [ 0x0666 ] ),+ ( "7", [ 0x0667 ] ),+ ( "8", [ 0x0668 ] ),+ ( "9", [ 0x0669 ] )+ ]+++white = define [+ ( " ", [ 0x0020 ] ),+ ( "\n", [ 0x000A ] ),+ ( "\r", [ 0x000D ] ),+ ( "\t", [ 0x0009 ] ),+ ( "\v", [ 0x000B ] ),+ ( "\f", [ 0x000C ] )+ ]+++punct = define [+ -- ( ".", [ 0x002E ] ),+ -- ( ":", [ 0x003A ] ),+ -- ( "!", [ 0x0021 ] ),++ ( ",", [ 0x060C ] ),+ ( ";", [ 0x061B ] ),+ ( "?", [ 0x061F ] )+ ]
+ Encode/Arabic/ArabTeX/ZDMG.hs view
@@ -0,0 +1,774 @@+-- --------------------------------------------------------------------------+-- $Revision: 190 $ $Date: 2007-01-27 14:47:15 +0100 (Sat, 27 Jan 2007) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Arabic.ArabTeX.ZDMG+-- Copyright : Otakar Smrz 2005-2007+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- /Encode::Arabic::ArabTeX::ZDMG/ in Perl:+-- <http://search.cpan.org/dist/Encode-Arabic/lib/Encode/Arabic/ArabTeX/ZDMG.pm>+--+-- "Encode.Extend"+-- "Encode.Mapper"+++module Encode.Arabic.ArabTeX.ZDMG (++ -- * Types++ ZDMG (..)++ -- * Functions++ ) where+++import Encode++import Encode.Mapper+import Encode.Extend++import FunParsing.OrdMap++import Version++version = revised "$Revision: 190 $"+++data ZDMG = ZDMG | ArabTeX_ZDMG++ deriving (Enum, Show)+++instance Encoding ZDMG where++ encode _ = error "Encode.Arabic.ArabTeX.ZDMG: 'encode' not implemented"++ decode _ = concat . parseFull decoderParsing .+ concat . parseLongest decoderMapping+++encoder :: Mapper UPoint [[[Char]]]++encoder = error "Encode.Arabic.ArabTeX.ZDMG: 'encoder' not implemented"+++-- --------------------------------------------------------------------------+-- Extend and ExtEnv Definitions+-- --------------------------------------------------------------------------+++data Mode = NonePlus | Novocalize | Vocalize | Fullvocalize++ deriving (Eq, Ord)+++data Env i = Env { envQuote :: Bool, envMode :: Mode,+ envWasla :: Bool, envVerb :: Bool, envCap :: Bool }+++setQuote q (Env _ m w v c) = Env q m w v c++setMode m (Env q _ w v c) = Env q m w v c++setWasla w (Env q m _ v c) = Env q m w v c++setVerb v (Env q m w _ c) = Env q m w v c++setCap c (Env q m w v _) = Env q m w v c+++instance ExtEnv Env where++ initEnv = Env False Vocalize False False False+++-- --------------------------------------------------------------------------+-- Parsing Definitions+-- --------------------------------------------------------------------------+++type Parsing = Extend Env [Char] ([UPoint] -> [UPoint])++type Environ = Env [Char]+++consControl :: OrdMap m+ => [Char] -> [m [Char] [UPoint]] -> Environ -> [[UPoint]]++consControl x l e = if envCap e then [ capFirst n | n <- noChange ]+ else noChange+ where noChange = lookupList x l+ capFirst [] = []+ capFirst (x:xs) = (toEnum . flip (-) 0x0020 . fromEnum) x : xs+++vowelControl :: OrdMap m+ => [Char] -> [Char] -> [m [Char] [UPoint]] -> Environ -> [[UPoint]]++vowelControl c x l e = if envCap e then consControl x l e+ else case c of++ "W" -> case sukun ? x of++ Just s -> if envQuote e then theWasla else [[]]+ Nothing -> if envQuote e then [ j ++ n | j <- justAlif,+ n <- noChange ]+ else case envMode e of++ Fullvocalize -> if envWasla e+ then [ j ++ drop 1 n | j <- theWasla,+ n <- noChange ]+ else [ n | n <- noChange ]++ Vocalize -> if envWasla e+ then [ j ++ drop 1 n | j <- justAlif,+ n <- noChange ]+ else [ n | n <- noChange ]++ _ -> [ j ++ f | j <- justAlif, f <- filterIt ]++ "|" -> case sukun ? x of++ Just s -> if envQuote e then noChange else [[]]+ Nothing -> if envQuote e then filterIt else noChange++ _ -> case sukun ? x of++ Just s -> if envMode e > Vocalize && not (envQuote e) ||+ not (envMode e > Vocalize) && envQuote e+ then noChange+ else [[]]++ Nothing -> if envMode e > Novocalize && not (envQuote e) ||+ not (envMode e > Novocalize) && envQuote e+ then noChange+ else filterIt++ where theWasla = lookupList "W" [wasla]+ justAlif = lookupList "W" [wasla] --[silent]+ noChange = lookupList x l+ filterIt = [ filter (flip all ([0x064B .. 0x0650] +++ [0x0656, 0x0657, 0x0670])+ . ((/=) . fromEnum)) s+ | s <- lookupList x l ]+++shaddaControl :: (OrdMap m, Ord s) => s -> [m s [a]] -> Environ -> [[a]]++shaddaControl x l e = if envMode e > NonePlus then lookupList x l else [[]]+++infixr 7 `plus` -- infixr 9 .+ -- infixr 5 ++++plus :: (a -> b) -> (c -> a) -> c -> b+plus = (.)+++decoderParsing :: Extend Env [Char] [UPoint]++decoderParsing = (fmap (foldr ($) []) . again) $++ parseHyphen++ <|> parseDoubleCons+ <|> parseSingleCons+ <|> parseInitVowel++ <|> parseWhite+ <|> parsePunct++ <|> parseDigit++ <|> parseCap+ <|> parseControl++ <|> parseAnything++ <|> returnError+++returnError :: Parsing+returnError = do x <- inspectIList+ sat (const True)+ return (error (show x))+++parseAnything :: Parsing+parseAnything = do x <- sat (const True)+ return ((++) (map (toEnum . fromEnum) x))+++parseNothing :: Parsing+parseNothing = return id+++parseCap =+ do lower ["\\cap"] []+ processControl "cap"+++parseControl =+ do i <- inspectIList+ case i of+ [] -> zero+ (c : s) -> case c of+ '\\' : t : r -> do returnIList s+ processControl (t : r)+ "\\" -> fail "Single \\"+ _ -> zero+++processControl :: [Char] -> Parsing+processControl t =+ do e <- inspectEList+ let envList = case e of++ [] -> error "Empty environment"+ (q : r) -> case t of++ "{" -> q : q : r+ "}" -> case r of+ [] -> error "Minus group"+ _ -> r++ "\"" -> setQuote True q : r+ "cap" -> setCap True q : r++ "fullvocalize" -> setMode Fullvocalize q : r+ "full" -> setMode Fullvocalize q : r+ "vocalize" -> setMode Vocalize q : r+ "nosukuun" -> setMode Vocalize q : r+ "novocalize" -> setMode Novocalize q : r+ "novowels" -> setMode Novocalize q : r+ "none" -> setMode Novocalize q : r+ "noshadda" -> setMode NonePlus q : r+ "noneplus" -> setMode NonePlus q : r++ "setverb" -> setVerb True q : r+ "setarab" -> setVerb False q : r++ _ -> error "Weird control sequence"++ returnEList envList+ parseNothing+++parseInitVowel =+ do v <- oneof [vowel]+ -- x <- upper ["W"] [silent] -- depends on 'vowelControl'+ y <- upperWith (vowelControl "W")+ [v] [vowel]+ completeSyllable y+++parseSyllVowel :: [Char] -> ([UPoint] -> [UPoint]) -> Parsing+parseSyllVowel c x =+ do v <- oneof [vowel] <|> return ""+ y <- upperWith (vowelControl c)+ [v] [vowel, sukun]+ completeSyllable (x `plus` y)+++completeSyllable :: ([UPoint] -> [UPoint]) -> Parsing+completeSyllable x =+ do resetEnv setQuote False+ resetEnv setWasla True+ resetEnv setCap False+ return x+++parseSingleCons =+ do c <- oneof [consonant, extra, invis]+ x <- upperWith consControl+ [c] [consonant, extra, invis]+ resetEnv setCap False+ parseSyllVowel c x+ <|>+ do c <- oneof [minor]+ x <- upper [c] [minor]+ parseSyllVowel c x+++parseDoubleCons =+ do c <- oneof [consonant, extra, invis]+ lower [c] []+ x <- upperWith consControl+ [c] [consonant, extra, invis]+ resetEnv setCap False+ y <- upperWith shaddaControl+ [c] [consonant, extra, invis]+ -- ["*"] [shadda]+ parseSyllVowel c (x `plus` y)+ <|>+ do c <- oneof [minor]+ lower [c] []+ x <- upper [c] [minor]+ y <- upperWith shaddaControl+ [c] [minor]+ -- ["*"] [shadda]+ parseSyllVowel c (x `plus` y)+++parseHyphen =+ do lower ["-"] []+ upper ["-"] [hyphen]+++parseDigit =+ do d <- oneof [digit]+ upper [d] [digit]+++parseWhite =+ do w <- oneof [white]+ upper [w] [white]+++parsePunct =+ do p <- oneof [punct]+ resetEnv setWasla False+ upper [p] [punct]+++-- --------------------------------------------------------------------------+-- Mapping Definitions+-- --------------------------------------------------------------------------+++type Mapping = Mapper Char (Quit Char [[Char]])+++pairs :: (OrdMap m, Ord s) => [m s a] -> [(s, a)]+pairs l = concat [ assocs i | i <- l ]++elems :: (OrdMap m, Ord s) => [m s a] -> [s]+elems l = (map fst . concat) [ assocs i | i <- l ]++quote :: OrdMap m => [m [Char] a] -> [[Char]]+quote = map ("\"" ++) . elems+++decoderMapping :: Mapper Char (Quit Char [[Char]])++decoderMapping = defineMapping+ ( pairs [ sunny, moony, minor, extra, invis, empty,+ -- digit, punct, white,+ vowel ] )+ <+> rules++ `others` (\ s -> (Just . return) ([], [[s]]))++-- <+> "" |.| error "Illegal symbol"+++defineMapping :: [([Char], [a])] -> Mapping++defineMapping = foldr (listing . mapping) zero++ where listing = (<+>)+ mapping (encoded, _) = symbols encoded++ symbols = fmap (((,) []) . (: [])) . syms+++whites :: Mapper Char (Quit Char Char)++whites = (fmap ((,) []) . anySymbol) [' ', '\r', '\v', '\f']+ -- [' ', '\n', '\r', '\t', '\v', '\f']+++rules :: Mapping++rules =++ "N_A" |-| "NY" |:| [] |+|+ "_A" |-| "Y" |:| []++ |+| ruleVerbalSilentAlif+ |+| ruleInternalTaaaa++-- |+| ruleLiWithArticle+ |+| ruleDefArticle+ |+| ruleIndefArticle++ |+| ruleMultiVowel+ |+| ruleHyphenedVowel++ |+| ruleWhitePlusControl+ |+| ruleIgnoreCapControl+ |+| ruleControlSequence++ |+| rulePunctuation+++rulePunctuation =++ "-" |.| ["-"] |+|+ "\"" |.| ["\\\""] |+|+ "\\\"" |.| ["\""]+++ruleVerbalSilentAlif =++ "aWA" |-| "aw" |:| [] |+|+ "aW" |-| "aw" |:| [] |+|+ "UA" |-| "U" |:| [] |+|+ "uW" |-| "U" |:| []+++ruleWhitePlusControl =++ "{" |.| ["\\{"] |+|+ "}" |.| ["\\}"] |+|++ "\\{" |.| ["{"] |+|+ "\\}" |.| ["}"] |+|++ "\\\\" |.| ["\\\\"] |+|+ "\\" |.| ["\\"]++ <+> sym '\\' <.> some whites <-> [" "]++ <+> some whites <-> [" "]+++ruleIgnoreCapControl =++ anyof [+ "l" ++ "-" ++ c ++ "\\cap " |-|+ "l" ++ "-" ++ c ++ "\\cap " |:| [] |+|++ "l" ++ "-" ++ c ++ "\\cap " ++ c |-|+ "-\\cap " ++ c |:| [c] |+|++ c ++ "-" ++ "\\cap " |-|+ c ++ "-" ++ "\\cap " |:| [] |+|++ c ++ "-" ++ "\\cap " ++ c |-|+ "-" ++ "\\cap " ++ c |:| [c] |+|++ "l" ++ "-\\cap " ++ c ++ "\\cap " |-|+ "l" ++ "-\\cap " ++ c ++ "\\cap " |:| [] |+|++ "l" ++ "-\\cap " ++ c ++ "\\cap " ++ c |-|+ "-\\cap " ++ c |:| ["\\cap", c] |+|++ "l" ++ "-\\cap " ++ c ++ c |-|+ "-\\cap " ++ c |:| [c]++ | c <- elems [sunny, moony] ]+++ruleControlSequence =++ do x <- sym '\\' <:>+ some (anySymbol (['A'..'Z'] ++ ['a'..'z']))+ many whites+ return ([], [x])+++ruleLiWithArticle =++ anyof [+ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ c ++ "-" ++ c |:| []++ | c <- elems [sunny, moony], c /= "l",+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]++ |+| anyof [++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ "-" |-|+ "l" ++ v ++ c ++ "-" |:| [] |+|++ "l" ++ v ++ "-a" ++ c ++ c |-|+ "l" ++ v ++ "|-" ++ c ++ c |:| []++ | c <- elems [sunny, moony], c == "l",+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]+++ruleDefArticle =++ anyof [+ "l" ++ "-" ++ c ++ c |-|+ "-" ++ c |:| [c]++ | c <- elems [sunny, moony] ]++ {-+ foldr (\ c -> (|+|) (++ "l" ++ "-" ++ c ++ c |-|+ "-" ++ c |:| [c]++ ) ) zero (elems [sunny, moony])+ -}+++ruleIndefArticle =++ "NA" |-| "N" |:| [] |+|+ "NU" |-| "N" |:| [] |+|+ "NY" |-| "N" |:| []+++ruleMultiVowel =++ -- "iy" |-| "I" |:| [] |+|+ -- "uw" |-| "U" |:| [] |+|++ "ii" |-| "I" |:| [] |+|+ "uu" |-| "U" |:| [] |+|+ "aa" |-| "A" |:| []++ -- -- |+| anyof [+ --+ -- "iy" ++ v |-| "y" ++ v |:| ["i"] |+|+ -- "uw" ++ v |-| "w" ++ v |:| ["u"]+ --+ -- | v <- elems [vowel] ++ quote [vowel, sukun] ]+++ruleHyphenedVowel =++ anyof [+ "-" ++ v |-| v |:| [] |+|++ -- "iy-" ++ v |-| "y-" ++ v |:| ["i"] |+|+ -- "uw-" ++ v |-| "w-" ++ v |:| ["u"] |+|++ "W-" ++ v |-| "W" |:| [v]++ | v <- elems [vowel] ++ quote [vowel] ]++ |+| anyof [++ "-" ++ v ++ c |-| v ++ c |:| ["-"] |+|++ -- "iy-" ++ v ++ c |-| "-" ++ v ++ c |:| ["I"] |+|+ -- "uw-" ++ v ++ c |-| "-" ++ v ++ c |:| ["U"] |+|++ "W-" ++ v ++ c |-| v ++ c |:| ["W", "-"]++ | c <- elems [sunny, moony, invis],+ v <- elems [vowel] ++ quote [vowel] ]+++ruleInternalTaaaa =++ anyof [+ "H" ++ v |-| "H" |:| []++ | v <- elems [vowel] ++ quote [vowel, sukun] ]++ |+| anyof [++ "T" ++ v ++ c |-| "t" ++ v ++ c |:| [] |+|+ "H" ++ v ++ c |-| "t" ++ v ++ c |:| []++ | c <- elems [sunny, moony, minor, invis],+ v <- elems [vowel, sukun] ++ quote [vowel, sukun] ]+++-- --------------------------------------------------------------------------+-- LowerUp Definitions+-- --------------------------------------------------------------------------+++type LowerUp = Map [Char] [UPoint]+++unionMap :: (OrdMap m, Ord s, Ord a) => [m s a] -> m s a++unionMap = unionMapWith (\ x y -> if compare x y == EQ+ then error "Inconsistent mapping in the Maps"+ else y)+++define :: [([Char], [Int])] -> LowerUp++define l = makeMapWith const [ (x, map toEnum y) | (x, y) <- l ]+++consonant :: LowerUp+consonant = unionMap [sunny, moony]+++sunny = define [+ ( "t", [ 0x0074 ] ),+ ( "_t", [ 0x0074, 0x0331 ] ),+ ( "d", [ 0x0064 ] ),+ ( "_d", [ 0x0064, 0x0331 ] ),+ ( "r", [ 0x0072 ] ),+ ( "z", [ 0x007A ] ),+ ( "s", [ 0x0073 ] ),+ ( "^s", [ 0x0073, 0x030C ] ),+ ( ".s", [ 0x0073, 0x0323 ] ),+ ( ".d", [ 0x0064, 0x0323 ] ),+ ( ".t", [ 0x0074, 0x0323 ] ),+ ( ".z", [ 0x007A, 0x0323 ] ),+ ( "l", [ 0x006C ] ),+ ( "n", [ 0x006E ] )+ ]+++invis = define [+ ( "|", [ ] )+ ]+++empty = define [+ ( "", [ ] )+ ]+++hyphen = define [+ ( "-", [ 0x002D ] )+ ]+++sukun = define [+ ( "", [ ] ),+ ( "+", [ ] )+ ]+++shadda = define [+ ( "*", [ ] )+ ]+++wasla = define [+ ( "W", [ 0x02BC ] )+ ]+++extra = define [+ ( "T", [ 0x0074 ] ),+ ( "H", [ 0x0068 ] ),+ ( "N", [ 0x006E ] ),+ ( "W", [ ] )+ ]++{-+hamza = define [+ ( "'A", [ 0x0622 ] ),+ ( "'a", [ 0x0623 ] ),+ ( "'i", [ 0x0625 ] ),+ ( "'w", [ 0x0624 ] ),+ ( "'y", [ 0x0626 ] ),+ ( "'|", [ 0x0621 ] )+ ]+-}+++minor = define [+ ( "'", [ 0x02BE ] ), -- [ 0x02BC ]+ ( "`", [ 0x02BF ] ) -- [ 0x02BB ]+ ]+++moony = define [+ ( "b", [ 0x0062 ] ),+ ( "^g", [ 0x0067, 0x030C ] ),+ ( ".h", [ 0x0068, 0x0323 ] ),+ ( "_h", [ 0x0068, 0x032E ] ),+ ( ".g", [ 0x0067, 0x0307 ] ),+ ( "f", [ 0x0066 ] ),+ ( "q", [ 0x0071 ] ),+ ( "k", [ 0x006B ] ),+ ( "m", [ 0x006D ] ),+ ( "h", [ 0x0068 ] ),+ ( "w", [ 0x0077 ] ),+ ( "y", [ 0x0079 ] ),++ ( "p", [ 0x0070 ] ),+ ( "v", [ 0x0076 ] ),+ ( "g", [ 0x0067 ] ),++ ( "c", [ 0x0063 ] ),+ ( "^c", [ 0x0063, 0x030C ] ),+ ( ",c", [ 0x0063, 0x0301 ] ),+ ( "^z", [ 0x007A, 0x030C ] ),+ ( "^n", [ 0x006E, 0x0303 ] ),+ ( "^l", [ 0x006C, 0x0303 ] ),+ ( ".r", [ 0x0072, 0x0307 ] )+ ]+++vowel = define [+ ( "a", [ 0x0061 ] ),+ ( "_a", [ 0x0061, 0x0304 ] ),+ ( "_aA", [ 0x0061, 0x0304 ] ),+ ( "_aY", [ 0x0061, 0x0304 ] ),+ ( "_aU", [ 0x0061, 0x0304 ] ),+ ( "_aI", [ 0x0061, 0x0304 ] ),+ ( "A", [ 0x0061, 0x0304 ] ),+ ( "^A", [ 0x0061, 0x0304 ] ),+ ( "e", [ 0x0065 ] ),+ ( "E", [ 0x0065, 0x0304 ] ),+ ( "i", [ 0x0069 ] ),+ ( "_i", [ 0x0069, 0x0304 ] ),+ ( "I", [ 0x0069, 0x0304 ] ),+ ( "^I", [ 0x0069, 0x0304 ] ),+ ( "_I", [ 0x0069 ] ),+ ( "o", [ 0x006F ] ),+ ( "O", [ 0x006F, 0x0304 ] ),+ ( "u", [ 0x0075 ] ),+ ( "_u", [ 0x0075, 0x0304 ] ),+ ( "U", [ 0x0075, 0x0304 ] ),+ ( "^U", [ 0x0075, 0x0304 ] ),+ ( "_U", [ 0x0075 ] ),+ ( "Y", [ 0x0061, 0x0304 ] )+ ]+++digit = define [+ ( "0", [ 0x0030 ] ),+ ( "1", [ 0x0031 ] ),+ ( "2", [ 0x0032 ] ),+ ( "3", [ 0x0033 ] ),+ ( "4", [ 0x0034 ] ),+ ( "5", [ 0x0035 ] ),+ ( "6", [ 0x0036 ] ),+ ( "7", [ 0x0037 ] ),+ ( "8", [ 0x0038 ] ),+ ( "9", [ 0x0039 ] )+ ]+++white = define [+ ( " ", [ 0x0020 ] ),+ ( "\n", [ 0x000A ] ),+ ( "\r", [ 0x000D ] ),+ ( "\t", [ 0x0009 ] ),+ ( "\v", [ 0x000B ] ),+ ( "\f", [ 0x000C ] )+ ]+++punct = define [+ ( ".", [ 0x002E ] ),+ ( ":", [ 0x003A ] ),+ ( "!", [ 0x0021 ] ),++ ( ",", [ 0x002C ] ),+ ( ";", [ 0x003B ] ),+ ( "?", [ 0x003F ] )+ ]
+ Encode/Arabic/Buckwalter.hs view
@@ -0,0 +1,108 @@+-- --------------------------------------------------------------------------+-- $Revision: 150 $ $Date: 2006-11-30 16:21:39 +0100 (Thu, 30 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Arabic.Buckwalter+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Tim Buckwalter's notation is a one-to-one transliteration of the Arabic+-- script for Modern Standard Arabic, using lower ASCII characters to encode+-- the graphemes of the original script. This system has been very popular in+-- Natural Language Processing, however, there are limits to its+-- applicability due to numerous non-alphabetic codes involved.+--+-- /Encode::Arabic::Buckwalter/ in Perl:+-- <http://search.cpan.org/dist/Encode-Arabic/lib/Encode/Arabic/Buckwalter.pm>+++module Encode.Arabic.Buckwalter (++ -- * Types++ Buckwalter (..)++ ) where+++import Encode++import FunParsing.OrdMap++--import Data.Map (Map)+--import qualified Data.Map as Map++import Version++version = revised "$Revision: 150 $"+++data Buckwalter = Buckwalter | Tim++ deriving (Enum, Show)+++instance Encoding Buckwalter where++ encode _ = recode (recoder decoded encoded)++ decode _ = recode (recoder encoded decoded)+++--makeMapWith f = Map.fromListWith f+--lookupWith f m x = Map.findWithDefault (f x) x m+++recode :: (Eq a, Enum a, Enum b, Ord a, OrdMap m) => m a b -> [a] -> [b]++recode xry xs = [ lookupWith ((toEnum . fromEnum) x) xry x | x <- xs ]+--recode xry xs = [ lookupWith (toEnum . fromEnum) xry x | x <- xs ]+++recoder :: Ord a => [a] -> [b] -> Map a b++recoder xs ys = makeMapWith const (zip xs ys)+++decoded :: [UPoint]++decoded = map toEnum ( []++ ++ [0x0640]+ ++ [0x0623, 0x0624, 0x0625]+ ++ [0x060C, 0x061B, 0x061F]+ ++ [0x0621, 0x0622] ++ [0x0626 .. 0x063A] ++ [0x0641 .. 0x064A]+ ++ [0x067E, 0x0686, 0x06A4, 0x06AF]+ ++ [0x0660 .. 0x0669]+ ++ [0x0671]+ ++ [0x0651]+ ++ [0x064B .. 0x0650] ++ [0x0670]+ ++ [0x0652]++ )+++encoded :: [Char]++encoded = map id ( []++ ++ "_"+ ++ "OWI"+ -- ">&<"+ ++ ",;?"+ ++ "'|" ++ "}AbptvjHxd*rzs$SDTZEg" ++ "fqklmnhwYy"+ ++ "PJVG"+ ++ ['0' .. '9']+ ++ "{"+ -- "A"+ ++ "~"+ ++ "FNKaui" ++ "`"+ ++ "o"++ )
+ Encode/Arabic/Byte.hs view
@@ -0,0 +1,564 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Arabic.Byte+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- /Encode::Byte/ in Perl:+-- <http://search.cpan.org/dist/Encode/Byte/Byte.pm>+--+-- <http://search.cpan.org/dist/Encode/lib/Encode/Supported.pod>+--+-- <http://129.69.218.213/arabtex/doc/arabdoc.pdf>+++module Encode.Arabic.Byte (++ -- * Types++ WinArabic (..),++ ISOArabic (..),++ MacArabic (..), MacFarsi (..),++ DOSArabic (..), DOSFarsi (..),++ ASMO449 (..),++ ISIRI3342 (..)++ ) where+++import Encode++import FunParsing.OrdMap++--import Data.Map (Map)+--import qualified Data.Map as Map++import Version++version = revised "$Revision: 130 $"+++data WinArabic = WinArabic | CP1256 | Windows_1256++ deriving (Enum, Show)++instance Encoding WinArabic where++ encode _ = recode (recoder winArabic nonUPoint)+ decode _ = recode (recoder nonUPoint winArabic)+++data ISOArabic = ISOArabic | ISO_8859_6++ deriving (Enum, Show)++instance Encoding ISOArabic where++ encode _ = recode (recoder isoArabic nonUPoint)+ decode _ = recode (recoder nonUPoint isoArabic)+++data MacArabic = MacArabic++ deriving (Enum, Show)++instance Encoding MacArabic where++ encode _ = recode (recoder macArabic nonUPoint)+ decode _ = recode (recoder nonUPoint macArabic)+++data MacFarsi = MacFarsi++ deriving (Enum, Show)++instance Encoding MacFarsi where++ encode _ = recode (recoder macFarsi nonUPoint)+ decode _ = recode (recoder nonUPoint macFarsi)+++data DOSArabic = DOSArabic | CP864++ deriving (Enum, Show)++instance Encoding DOSArabic where++ encode _ = recode (recoder dosArabic nonUPoint)+ decode _ = recode (recoder nonUPoint dosArabic)+++data DOSFarsi = DOSFarsi | CP1006++ deriving (Enum, Show)++instance Encoding DOSFarsi where++ encode _ = recode (recoder dosFarsi nonUPoint)+ decode _ = recode (recoder nonUPoint dosFarsi)+++data ASMO449 = ASMO449++ deriving (Enum, Show)++instance Encoding ASMO449 where++ encode _ = foldr shadda []++ where shadda x (y:ys) | fromEnum x == 0x0651 && f > 0x6A && f < 0x71++ = toEnum (f + 0x08) : ys++ where f = fromEnum y++ shadda x ys = recode (recoder asmo449 lowerCode) [x] ++ ys++ decode _ = foldr shadda []++ where shadda x ys | f > 0x72 && f < 0x79++ = recode (recoder lowerCode asmo449)+ (map toEnum [0x71, f - 0x08]) ++ ys++ where f = fromEnum x++ shadda x ys = recode (recoder lowerCode asmo449) [x] ++ ys+++data ISIRI3342 = ISIRI3342++ deriving (Enum, Show)++instance Encoding ISIRI3342 where++ encode _ = recode (recoder isiri3342 upperCode)+ decode _ = recode (recoder upperCode isiri3342)+++--makeMapWith f = Map.fromListWith f+--lookupWith f m x = Map.findWithDefault (f x) x m+++recode :: (Eq a, Enum a, Enum b, Ord a, OrdMap m) => m a b -> [a] -> [b]++recode xry xs = [ lookupWith ((toEnum . fromEnum) x) xry x | x <- xs ]+--recode xry xs = [ lookupWith (toEnum . fromEnum) xry x | x <- xs ]+++recoder :: Ord a => [a] -> [b] -> Map a b++recoder xs ys = makeMapWith const (zip xs ys)+++nonUPoint :: [Char]++nonUPoint = map toEnum [0x20 .. 0xFF]+++lowerCode :: [Char]++lowerCode = map toEnum [0x20 .. 0x7F]+++upperCode :: [Char]++upperCode = map toEnum [0xA0 .. 0xFF]+++winArabic :: [UPoint]++winArabic = map toEnum++ [0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,+ 0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,+ 0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,+ 0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,+ 0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,+ 0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,+ 0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,+ 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,+ 0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,+ 0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,+ 0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,+ 0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,+ 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,+ 0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,+ 0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2]+++isoArabic :: [UPoint]++isoArabic = map toEnum++ [0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,+ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,+ 0x00A0, 0xFFFD, 0xFFFD, 0xFFFD, 0x00A4, 0xFFFD, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x060C, 0x00AD, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0x061B, 0xFFFD, 0xFFFD, 0xFFFD, 0x061F,+ 0xFFFD, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,+ 0x0638, 0x0639, 0x063A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,+ 0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,+ 0x0650, 0x0651, 0x0652, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD]+++macArabic :: [UPoint]++macArabic = map toEnum++ [0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x0025, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x002C, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0xFFFD, 0x003B, 0xFFFD, 0xFFFD, 0xFFFD, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0xFFFD, 0xFFFD, 0xFFFD, 0x007E, 0xFFFD,+ 0x00C4, 0x00A0, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,+ 0x00E0, 0x00E2, 0x00E4, 0x06BA, 0x00AB, 0x00E7, 0x00E9, 0x00E8,+ 0x00EA, 0x00EB, 0x00ED, 0x2026, 0x00EE, 0x00EF, 0x00F1, 0x00F3,+ 0x00BB, 0x00F4, 0x00F6, 0x00F7, 0x00FA, 0x00F9, 0x00FB, 0x00FC,+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x066A, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x060C, 0x002D, 0x002E, 0x002F,+ 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667,+ 0x0668, 0x0669, 0x003A, 0x061B, 0x003C, 0x003D, 0x003E, 0x061F,+ 0x274A, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,+ 0x0638, 0x0639, 0x063A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,+ 0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,+ 0x0650, 0x0651, 0x0652, 0x067E, 0x0679, 0x0686, 0x06D5, 0x06A4,+ 0x06AF, 0x0688, 0x0691, 0x007B, 0x007C, 0x007D, 0x0698, 0x06D2]+++macFarsi :: [UPoint]++macFarsi = map toEnum++ [0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x0025, 0xFFFD, 0xFFFD,+ 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0x002C, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0xFFFD, 0x003B, 0xFFFD, 0xFFFD, 0xFFFD, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0xFFFD, 0xFFFD, 0xFFFD, 0x007E, 0xFFFD,+ 0x00C4, 0x00A0, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,+ 0x00E0, 0x00E2, 0x00E4, 0x06BA, 0x00AB, 0x00E7, 0x00E9, 0x00E8,+ 0x00EA, 0x00EB, 0x00ED, 0x2026, 0x00EE, 0x00EF, 0x00F1, 0x00F3,+ 0x00BB, 0x00F4, 0x00F6, 0x00F7, 0x00FA, 0x00F9, 0x00FB, 0x00FC,+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x066A, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x060C, 0x002D, 0x002E, 0x002F,+ 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,+ 0x06F8, 0x06F9, 0x003A, 0x061B, 0x003C, 0x003D, 0x003E, 0x061F,+ 0x274A, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,+ 0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,+ 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,+ 0x0638, 0x0639, 0x063A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,+ 0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,+ 0x0650, 0x0651, 0x0652, 0x067E, 0x0679, 0x0686, 0x06D5, 0x06A4,+ 0x06AF, 0x0688, 0x0691, 0x007B, 0x007C, 0x007D, 0x0698, 0x06D2]+++dosArabic :: [UPoint]++dosArabic = map toEnum++ [0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x066A, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,+ 0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C,+ 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518,+ 0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB,+ 0x00BB, 0xFEF7, 0xFEF8, 0xFFFD, 0xFFFD, 0xFEFB, 0xFEFC, 0xFFFD,+ 0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0xFFFD, 0xFFFD,+ 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5,+ 0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667,+ 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F,+ 0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D,+ 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9,+ 0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1,+ 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9,+ 0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB,+ 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1,+ 0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0,+ 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0xFFFD]+++dosFarsi :: [UPoint]++dosFarsi = map toEnum++ [0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,+ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,+ 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,+ 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,+ 0x00A0, 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6,+ 0x06F7, 0x06F8, 0x06F9, 0x060C, 0x061B, 0x00AD, 0x061F, 0xFE81,+ 0xFE8D, 0xFFFD, 0xFE8E, 0xFE8F, 0xFE91, 0xFB56, 0xFB58, 0xFE93,+ 0xFE95, 0xFE97, 0xFB66, 0xFB68, 0xFE99, 0xFE9B, 0xFE9D, 0xFE9F,+ 0xFB7A, 0xFB7C, 0xFEA1, 0xFEA3, 0xFEA5, 0xFEA7, 0xFEA9, 0xFB84,+ 0xFEAB, 0xFEAD, 0xFB8C, 0xFEAF, 0xFB8A, 0xFEB1, 0xFEB3, 0xFEB5,+ 0xFEB7, 0xFEB9, 0xFEBB, 0xFEBD, 0xFEBF, 0xFEC1, 0xFEC5, 0xFEC9,+ 0xFECA, 0xFECB, 0xFECC, 0xFECD, 0xFECE, 0xFECF, 0xFED0, 0xFED1,+ 0xFED3, 0xFED5, 0xFED7, 0xFED9, 0xFEDB, 0xFB92, 0xFB94, 0xFEDD,+ 0xFEDF, 0xFEE0, 0xFEE1, 0xFEE3, 0xFB9E, 0xFEE5, 0xFEE7, 0xFE85,+ 0xFEED, 0xFBA6, 0xFBA8, 0xFBA9, 0xFBAA, 0xFE80, 0xFE89, 0xFE8A,+ 0xFE8B, 0xFEF1, 0xFEF2, 0xFEF3, 0xFBB0, 0xFBAE, 0xFE7C, 0xFE7D]+++asmo449 :: [UPoint]++asmo449 = map toEnum $++ [0x0020 .. 0x002B] ++ [0x060C] ++ [0x002D .. 0x002F] ++++ [0x0660 .. 0x0669] ++ [0x003A] ++ [0x061B] ++ [0x009C .. 0x009E] ++++ [0x061F] ++ [0x0627] ++ [0x0621 .. 0x063A] ++ [0x005B .. 0x005F] ++++ [0x0640 .. 0x0652] ++ [0xFFFD] {- NOT UCS -} ++ [0xFC5E, 0xFC5F] ++++ [0xFCF2 .. 0xFCF4] ++ [0xFFFD, 0xFFFD] ++ [0x007B .. 0x007F]+++isiri3342 :: [UPoint]++isiri3342 = map toEnum++ [0x0020, 0xFFFD, 0xFFFD, 0x0021, 0x0024, 0x066A, 0x0026, 0x0027,+ 0x0028, 0x0029, 0x002A, 0x002B, 0x060C, 0x002D, 0x002E, 0x002F,+ 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,+ 0x06F8, 0x06F9, 0x003A, 0x061B, 0x003C, 0x003D, 0x003E, 0x061F,+ 0x0622, 0x0627, 0x0621, 0x0628, 0x067E, 0x062A, 0x062B, 0x062C,+ 0x0686, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0698,+ 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x063A,+ 0x0641, 0x0642, 0x06A9, 0x06AF, 0x0644, 0x0645, 0x0646, 0x0648,+ 0x0647, 0x06CC, 0x005B, 0x005D, 0x007B, 0x007D, 0xFFFD, 0xFFFD,+ 0xFFFD, 0x0640, 0x007C, 0x005C, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,+ 0x064E, 0x0650, 0x064F, 0x064B, 0x064D, 0x064C, 0x0651, 0x0652,+ 0x0623, 0x0625, 0x0624, 0x0626, 0x0629, 0x0643, 0x064A, 0x0649]+++{-++allUPoint :: [UPoint]++allUPoint = map toEnum ( []++ ++ [0x0640]+ ++ [0x0623, 0x0624, 0x0625]+ ++ [0x060C, 0x061B, 0x061F]+ ++ [0x0621, 0x0622] ++ [0x0626 .. 0x063A] ++ [0x0641 .. 0x064A]+ ++ [0x067E, 0x0686, 0x06A4, 0x06AF]+ ++ [0x0660 .. 0x0669]+ ++ [0x0671]+ ++ [0x0651]+ ++ [0x064B .. 0x0650] ++ [0x0670]+ ++ [0x0652]++ )++winArabic :: [Char]++winArabic = map toEnum ( []++ ++ [0xDC]+ ++ [0xC3, 0xC4, 0xC5]+ ++ [0xA1, 0xBA, 0xBF]+ ++ [0xC1, 0xC2] ++ [0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC,+ 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3,+ 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB]+ ++ [0xDD, 0xDE, 0xDF, 0xE1, 0xE3, 0xE4, 0xE5,+ 0xE6, 0xEC, 0xED]+ ++ [0x81, 0x8D, 0x3F, 0x90]+ ++ [0x30 .. 0x39]+ ++ [0x3F]+ ++ [0xF8]+ ++ [0xF0, 0xF1, 0xF2, 0xF3, 0xF5, 0xF6] ++ [0x3F]+ ++ [0xFA]++ )+++isoArabic :: [Char]++isoArabic = map toEnum ( []++ ++ [0xE0]+ ++ [0xC3, 0xC4, 0xC5]+ ++ [0xAC, 0xBB, 0xBF]+ ++ [0xC1, 0xC2] ++ [0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC,+ 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3,+ 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA]+ ++ [0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,+ 0xE8, 0xE9, 0xEA]+ ++ [0x3F, 0x3F, 0x3F, 0x3F]+ ++ [0x30 .. 0x39]+ ++ [0x3F]+ ++ [0xF1]+ ++ [0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0] ++ [0x3F]+ ++ [0xF2]++ )+++-- Buckwalter+ ++ "_"+ ++ "OWI"+ -- ">&<"+ ++ ",;?"+ ++ "'|" ++ "}AbptvjHxd*rzs$SDTZEg" ++ "fqklmnhwYy"+ ++ "PJVG"+ ++ ['0' .. '9']+ ++ "{"+ -- "A"+ ++ "~"+ ++ "FNKaui" ++ "`"+ ++ "o"+++-- MacArabic+ ++ [0xE0]+ ++ [0xC3, 0xC4, 0xC5]+ ++ [0xAC, 0xBB, 0xBF]+ ++ [0xC1, 0xC2] ++ [0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC,+ 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3,+ 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA]+ ++ [0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,+ 0xE8, 0xE9, 0xEA]+ ++ [0xF3, 0xF5, 0xF7, 0xF8]+ ++ [0xB0 .. 0xB9]+ ++ [0x3F]+ ++ [0xF1]+ ++ [0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0] ++ [0x3F]+ ++ [0xF2]+++-- MacFarsi+ ++ [0xE0]+ ++ [0xC3, 0xC4, 0xC5]+ ++ [0xAC, 0xBB, 0xBF]+ ++ [0xC1, 0xC2] ++ [0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC,+ 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3,+ 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA]+ ++ [0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,+ 0xE8, 0xE9, 0xEA]+ ++ [0xF3, 0xF5, 0xF7, 0xF8]+ ++ [0x30 .. 0x39]+ ++ [0x3F]+ ++ [0xF1]+ ++ [0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0] ++ [0x3F]+ ++ [0xF2]+++-- cp864+ ++ [0xE0]+ ++ [0x3F, 0x3F, 0x3F]+ ++ [0xAC, 0xBB, 0xBF]+ ++ [0x3F, 0x3F] ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F]+ ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F]+ ++ [0x3F, 0x3F, 0x3F, 0x3F]+ ++ [0xB0 .. 0xB9]+ ++ [0x3F]+ ++ [0xF1]+ ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F] ++ [0x3F]+ ++ [0x3F]+++-- cp1006+ ++ [0x3F]+ ++ [0x3F, 0x3F, 0x3F]+ ++ [0xAB, 0xAC, 0xAE]+ ++ [0x3F, 0x3F] ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F]+ ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,+ 0x3F, 0x3F, 0x3F]+ ++ [0x3F, 0x3F, 0x3F, 0x3F]+ ++ [0x30 .. 0x39]+ ++ [0x3F]+ ++ [0x3F]+ ++ [0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F] ++ [0x3F]+ ++ [0x3F]++-}
+ Encode/Extend.hs view
@@ -0,0 +1,211 @@+-- --------------------------------------------------------------------------+-- $Revision: 189 $ $Date: 2007-01-27 03:33:19 +0100 (Sat, 27 Jan 2007) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Extend+-- Copyright : Otakar Smrz 2005-2007+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- "Encode.Arabic.ArabTeX"+-- "Encode.Arabic.ArabTeX.ZDMG"+++module Encode.Extend (++ -- * Modules++ module FunParsing.Parsers.Parser,++ -- * Classes++ ExtEnv,++ -- * Types++ Extend (..),++ -- * Methods++ initEnv,++ -- * Functions++ inspectIList, returnIList,+ inspectEList, returnEList,++ inspectEnv, resetEnv,++ oneof, lower, upper, upperWith, oneof',++ -- * Operators++ (<|>),++ -- * Extensions++ again, lookupList++ ) where+++import FunParsing.OrdMap+import FunParsing.Parsers.Parser++import Control.Monad++import Version++version = revised "$Revision: 189 $"+++class ExtEnv e where++ initEnv :: e i+++newtype Extend e s a = Ext (InE s e -> [(InE s e, a)])++type InE i e = ([i], [e i])+++inspectIList :: Extend e s [s]+inspectIList = Ext (\ (i, e) -> [((i, e), i)])++returnIList :: [s] -> Extend e s [s]+returnIList i = Ext (\ (_, e) -> [((i, e), i)])++inspectEList :: Extend e s [e s]+inspectEList = Ext (\ (i, e) -> [((i, e), e)])++returnEList :: [e s] -> Extend e s [e s]+returnEList e = Ext (\ (i, _) -> [((i, e), e)])++inspectEnv :: Extend e s (e s)+inspectEnv = Ext (\ (i, e) -> [((i, e), head e)])++resetEnv :: (a -> e s -> e s) -> a -> Extend e s (e s)+resetEnv f v = Ext (\ (i, e : q) -> [((i, f v e : q), f v e)])+++infixr 2 <|>++(<|>) :: Extend e s a -> Extend e s a -> Extend e s a+{-+(<|>) p q = Ext (\ cs -> case r cs of [] -> []; (x:xs) -> [x])+ where Ext r = p <+> q+-}+(<|>) p q = Ext (\ cs -> let Ext pp = p+ r = pp cs+ Ext qq = q+ in case r of [] -> qq cs+ (s : _) -> [s])+{-+(<|>) p q = Ext (\ cs -> let Ext pp = p+ r = pp cs+ -- r = parse p cs -- wrong type+ Ext qq = q+ in case r of [] -> qq cs+ _ -> r)+-}++again :: Extend e s a -> Extend e s [a]+again p = ps where ps = p <:> ps <|> return []+++lookupList :: (OrdMap m, Ord s) => s -> [m s a] -> [a]+lookupList x l = concat [ maybe [] (: []) (i ? x) | i <- l ]+++oneof' :: (Ord [s], Symbol m [s], Eq s, Monad m) => s -> [Map [s] a] -> m [s]+oneof' p l = do y <- sat (\ (x : s) -> if x == p+ then any (\ i -> maybe False (const True) (i ? s)) l+ else False)+ return (tail y)++oneof :: (Ord s, Symbol m s) => [Map s a] -> m s+oneof l = sat (\ s -> any (\ i -> maybe False (const True) (i ? s)) l)++lower :: (Ord s) => [s] -> [s] -> Extend e s [s]+lower s c = Ext (\ inp -> [ ((c ++ i, e), r) | ((i, e), r) <- f inp ])+ where Ext f = syms s++upper :: (OrdMap m, Ord s) => [s] -> [m s [c]] -> Extend e d ([c] -> [c])+upper s l = foldM (\ f -> fmap ((.) f) . anyof . map (return . (++))) id+ [ lookupList x l | x <- s ]+{-+upper :: (Ord s, Monad m, Functor m, Monoid m)+ => [s] -> [Map s [UPoint]] -> m [UPoint]+upper s l = (fmap concat . sequence . map (anyof . map return))+ [ lookupList x l | x <- s ]+-}++upperWith :: (s -> m -> e d -> [[c]]) -> [s] -> m -> Extend e d ([c] -> [c])+upperWith f s l =+ do e <- inspectEnv+ foldM (\ f -> fmap ((.) f) . anyof . map (return . (++))) id+ [ f x l e | x <- s ]+++--------------------------------------------------+-- the standard parser from section 3.2+++instance Monoid (Extend e s) where+ zero = Ext (\ inp -> [])+ Ext p <+> Ext q = Ext (\ inp -> p inp ++ q inp)+++instance Monad (Extend e s) where+ return a = Ext (\ inp -> [(inp, a)])+ Ext p >>= k = Ext (\ inp -> concat [ q inp' | (inp', a) <- p inp,+ let Ext q = k a ])+++instance Functor (Extend e s) where+ fmap f p = do a <- p; return (f a)+{--+ fmap f (Ext p) = Ext (\inp -> [ (inp', f a) | (inp', a) <- p inp ])+--}+++instance Sequence (Extend e s)+{--+ Ext p <*> Ext q = Ext (\inp -> [ (inp'', f a) | (inp', f) <- p inp, (inp'', a) <- q inp' ])+--}+++instance Eq s => Symbol (Extend e s) s where+ sat p = Ext sat'+ where sat' ((s:inp), e) | p s = [((inp, e), s)]+ sat' _ = []+++instance Eq s => SymbolCont (Extend e s) s where+ satCont p fut = Ext sat'+ where sat' ((s:inp), e) | p s = let Ext p = fut s in p (inp, e)+ sat' _ = []+++instance ExtEnv e => Parser (Extend e s) s where+ parse = parse' initEnv+ parseFull = parseFull' initEnv+++instance Lookahead (Extend e s) s where+ lookahead f = Ext (\ (inp, e) -> let Ext p = f inp in p (inp, e))+++parse' :: ExtEnv e => e s -> Extend e s a -> [s] -> [([s], a)]++parse' e (Ext p) i = [ (x, y) | ((x, _), y) <- p (i, [e]) ]+++parseFull' :: ExtEnv e => e s -> Extend e s a -> [s] -> [a]++parseFull' e (Ext p) i = [ y | (([], _), y) <- p (i, [e]) ]
+ Encode/Mapper.hs view
@@ -0,0 +1,548 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Mapper+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- The Haskell version of /Encode::Mapper/ originally written in Perl:+-- <http://search.cpan.org/dist/Encode-Mapper/>+--+-- "Encode.Arabic.ArabTeX"+-- "Encode.Arabic.ArabTeX.ZDMG"+++module Encode.Mapper (++ -- * Modules++ module FunParsing.Parsers.Parser,++ -- * Types++ Mapper, Quit,++ -- * Functions++ parseLongest, parseLongestWith,++ parseLongestCheck, parseLongestCheckWith,++ parseLongestWide, parseLongestWideWith,+ parseWide, unParseWide, initPW, lastPW,++ parseLongestDeep, parseLongestDeepWith,+ parseDeep, unParseDeep, initPD, lastPD,++ -- * Operators++ (|:|), (|-|), (|.|), (|+|),++ others,++ -- * Extensions++ some, anySymbol, (<->), (<.>)++ ) where+++import FunParsing.OrdMap+--import Data.Map (Map)+--import qualified Data.Map as Map++import FunParsing.Parsers.Parser++import Version++version = revised "$Revision: 130 $"++{-+(?) x y = Map.lookup y x++mergeWith f = Map.unionWith f++emptyMap = Map.empty++mapMap = Map.map++(|->) x y = Map.insert x y Map.empty+-}+++data (OrdMap m) => Next m s a = Only (m s a)+ | Else (m s a) (s -> Maybe a)+++perhaps :: Maybe a -> Maybe a -> Maybe a+perhaps x y = case x of Nothing -> y+ _ -> x++infixr 2 `perhaps`+++others :: Ord s => Mapper s a -> (s -> Maybe (Mapper s a)) -> Mapper s a++others (FMap p m) f = others (unfoldWith p m) f+others (Node q n) f = Node q (others' n f)+ where+ others' (Only m) f = Else (mapMapWithKey othersPerhaps m) f+ others' (Else m e) f = Else (mapMapWithKey othersPerhaps m)+ (\ s -> e s `perhaps` f s)++ othersPerhaps k q = let r = unfoldTrie q in case r of++ Node [] _ -> let s = f k in case s of++ Just t -> r <+> t+ Nothing -> r++ _ -> r+ {-+ others' (Only m) f = Else m f+ others' (Else m e) f = Else m (\ s -> e s `perhaps` f s)+ -}++infixl 2 `others`+++instance OrdMap m => OrdMap (Next m) where++ emptyMap = Only emptyMap++ (|->) s a = Only (s |-> a)++ isEmptyMap (Only m) = isEmptyMap m+ isEmptyMap (Else _ _) = False++ (?) (Only m) s = (?) m s+ (?) (Else m f) s = (?) m s `perhaps` f s++ mergeWith f (Only x) (Only y) = Only (mergeWith f x y)+ mergeWith f (Only x) (Else y r) = Else (mergeWith f x y) r+ mergeWith f (Else x l) (Only y) = Else (mergeWith f x y) l+ mergeWith f (Else x l) (Else y r) = Else (mergeWith f x y) (\ s ->++ case l s of Nothing -> r s+ Just p -> case r s of Nothing -> Just p+ Just q -> Just (f p q))++ assocs (Only m) = assocs m+ assocs (Else m _) = assocs m++ ordMap xs = Only (ordMap xs)++ mapMap f (Only m) = Only (mapMap f m)+ mapMap f (Else m e) = Else (mapMap f m) (fmap f . e)+++{-+ mergeWith join (Map xss _) (Map yss _) = Map xyss (makeTree xyss)+ where xyss = merge xss yss+ merge [] yss = yss+ merge xss [] = xss+ merge xss@(x@(s,x'):xss') yss@(y@(t,y'):yss')+ = case compare s t of+ LT -> x : merge xss' yss+ GT -> y : merge xss yss'+ EQ -> (s, join x' y') : merge xss' yss'+-}+++data Mapper s a = Node [a] (Next Map s (Mapper s a))+ -- (Map s (Mapper s a))+ | forall b .+ FMap (b -> a) (Mapper s b)+++type Quit s a = ([s], a)++returnQuit :: [s] -> a -> Quit s a+returnQuit s a = (s, a)++justQuit :: Quit s a -> a+justQuit (s, a) = a++skipQuit :: Quit s a -> [s]+skipQuit (s, a) = s+++infix 4 |-|+infix 3 |:|, |.|+infixl 2 |+|++(|:|) :: InputSymbol s => (a -> Mapper s (Quit s a)) -> a -> Mapper s (Quit s a)+(|:|) x y = x y++(|-|) :: InputSymbol s => [s] -> [s] -> a -> Mapper s (Quit s a)+(|-|) x y z = if True --length x > length y || length y == 0+ then syms x >> Node [returnQuit y z] emptyMap+ else error "Length requirement violated"++(|.|) :: InputSymbol s => [s] -> a -> Mapper s (Quit s a)+(|.|) x y = x |-| [] |:| y++(|+|) :: InputSymbol s => Mapper s a -> Mapper s a -> Mapper s a+(|+|) = (<+>)+++anySymbol :: (Monoid m, Symbol m a) => [a] -> m a+anySymbol = anyof . map sym++some :: (Monoid m, Sequence m) => m a -> m [a]+some p = p <:> many p+++infixl 5 <->, <.>++(<->) :: (Monoid m, Sequence m) => m a -> b -> m ([c], b)+(<->) x y = x <.> return ([], y)++(<.>) :: (Monoid m, Sequence m) => m a -> m b -> m b+(<.>) = (*>)++--------------------------------------------------+-- the ambiguous extended trie from section 4.3.4+++unfoldWith :: Ord s => (a -> b) -> Mapper s a -> Mapper s b+unfoldWith f (Node as pmap) = Node (map f as) (mapMap (FMap f) pmap)+unfoldWith f (FMap g p) = unfoldWith (f . g) p+++unfoldTrie :: Ord s => Mapper s a -> Mapper s a+unfoldTrie node@(Node as pmap) = node+unfoldTrie (FMap g p) = unfoldWith g p+++instance Ord s => Monoid (Mapper s) where+ zero = Node [] emptyMap++ FMap f p <+> q = unfoldWith f p <+> q+ p <+> FMap f q = p <+> unfoldWith f q+ Node as pmap <+> Node bs qmap = Node (as ++ bs) (mergeWith (<+>) pmap qmap)++{-+ (<+>) p q = Node (as ++ bs) (mergeWith (<+>) pmap qmap)+ where Node as pmap = unfoldTrie p+ Node bs qmap = unfoldTrie q+-}+++instance Ord s => Monad (Mapper s) where+ return a = Node [a] emptyMap++ FMap f p >>= k = unfoldWith f p >>= k+ Node as pmap >>= k = foldr (<+>) (Node [] (mapMap (>>= k) pmap)) (map k as)++{-+ t >>= k = foldr (<+>) (Node [] (mapMap (>>= k) pmap)) (map k as)+ where Node as pmap = unfoldTrie t+-}+++instance Ord s => Functor (Mapper s) where+ fmap = FMap+++instance Ord s => Sequence (Mapper s)+++instance InputSymbol s => Symbol (Mapper s) s where+ sym s = Node [] (s |-> return s)+ sat p = anyof (map sym (filter p symbols))+++instance Ord s => Parser (Mapper s) s where++ -- parse = error "Mapper: parse is not implemented"+ --+ -- parse implemented by Otakar Smrz++ parse p inp = parse' p inp id+ parseFull p inp = parseFull' p inp id++parse' :: Ord s => Mapper s a -> [s] -> (a -> b) -> [([s], b)]+parse' (FMap f p) inp k = parse' p inp (k . f)+parse' (Node [] pmap) [] k = []+parse' (Node [] pmap) (s:inp) k = case pmap ? s of+ Just p -> parse' p inp k+ Nothing -> []+parse' (Node xs pmap) inp k = foldr ( (:) . (,) inp . k )+ (parse' (Node [] pmap) inp k) xs++parseFull' :: Ord s => Mapper s a -> [s] -> (a -> b) -> [b]+parseFull' (FMap f p) inp k = parseFull' p inp (k . f)+parseFull' (Node xs _) [] k = map k xs+parseFull' (Node _ pmap) (s:inp) k = case pmap ? s of+ Just p -> parseFull' p inp k+ Nothing -> []+++data ParseWide s a = PW Int+ ([a] -> [a])+ (Mapper s (Quit s a))+ [ParseWide s a]+++initPW :: Ord s => Mapper s (Quit s a) -> ([a] -> [a]) -> ParseWide s a++initPW m h = PW 0 h m []+++lastPW :: Ord s => [ParseWide s a] -> ParseWide s a -> [ParseWide s a]++lastPW [] p = [p]+lastPW w _ = w++--lastPW w p = [ PW l h f c (lastPW' s p) | (PW l h f c s) <- w ]+--lastPW' [] p = [error "Try w or what?"]+--lastPW' w p = [ PW l h f c (lastPW' s p) | (PW l h f c s) <- w ]+++parseWide :: Ord s => Mapper s (Quit s a) -> [ParseWide s a] -> [s]+ -> [ParseWide s a]++parseWide m = foldl (\ w y -> concat [ parsePW m p y | p <- w ])+++parsePW :: Ord s => Mapper s (Quit s a) -> ParseWide s a -> s+ -> [ParseWide s a]++parsePW m (PW l h c s) y = let Node r k = unfoldTrie c+ n = l + 1++ in case k ? y of++ Just q -> let qc = unfoldTrie q++ in case qc of++ Node [] _ -> case r of++ [] -> case s of++ [] -> [ PW n h qc [] ]+ zs -> [ PW n h qc+ ( concat [ parsePW m z y | z <- zs ] ) ]++ xs -> case l of++ 0 -> [ PW n h qc+ [ initPW m (justQuit x :) | x <- xs ] ]+ _ -> [ PW n h qc+ ( concat [ parseWide m+ [initPW m (justQuit x :)]+ (skipQuit x ++ [y]) |+ x <- xs ] ) ]++ _ -> [ PW n h qc [] ]++ Nothing -> case l of++ 0 -> case r of++ [] -> [ PW l h c s ]+ xs -> [ initPW m (h . (justQuit x :)) | x <- xs ]++ _ -> case r of++ [] -> [ PW rn (h . rh) rc rs |+ PW rn rh rc rs <- parseWide m+ (lastPW s (initPW m id))+ [y] ]+ xs -> concat [ parseWide m+ [initPW m (h . (justQuit x :))]+ (skipQuit x ++ [y]) |+ x <- xs ]+++unParseWide :: Ord s => Mapper s (Quit s a) -> [ParseWide s a] -> [[[a]]]++unParseWide m = concat . map (unParsePW m)+++unParsePW :: Ord s => Mapper s (Quit s a) -> ParseWide s a -> [[[a]]]++unParsePW m (PW l h c s) = let Node r k = unfoldTrie c++ in case r of++ [] -> case s of++ [] -> [[ h [] ]]+ zs -> [ h u : v | (u : v) <- unParseWide m zs ]+-- zs -> [ h u : v | z <- zs, (u:v) <- unParsePW m z ]++ xs -> case l of++ 0 -> [[ h [] ]]++ _ -> concat [ case skipQuit x of++ [] -> [[ h [justQuit x] ]]+ is -> [ h [justQuit x] : u |+ u <- unParseWide m+ (parseWide m [initPW m id] is) ]++ | x <- xs ]+++parseLongestWide :: Ord s => Mapper s (Quit s a) -> [s] -> [a]++parseLongestWide = parseLongestWideWith (head . map concat)+++parseLongestWideWith :: Ord s => ([[[a]]] -> [b]) -> Mapper s (Quit s a) -> [s] -> [b]++parseLongestWideWith f m i = f (unParseWide m (parseWide m [initPW m id] i))+++data ParseDeep s a = PD Int+ ([a] -> [a])+ (Mapper s (Quit s a))+ [s]+ [ParseDeep s a]+++initPD :: Ord s => Mapper s (Quit s a) -> ([a] -> [a]) -> ParseDeep s a++initPD m h = PD 0 h m [] []+++lastPD :: Ord s => [ParseDeep s a] -> ParseDeep s a -> [ParseDeep s a]++lastPD [] p = [p]+lastPD w _ = w+ -- [ PD l h f c i (lastPD s p) | (PD l h f c i s) <- w ]+++parseDeep :: Ord s => Mapper s (Quit s a) -> [ParseDeep s a] -> [s] -> [ParseDeep s a]++parseDeep m = foldl (\ w y -> concat [ parsePD m p y | p <- w ])+++parsePD :: Ord s => Mapper s (Quit s a) -> ParseDeep s a -> s -> [ParseDeep s a]++parsePD m (PD l h c i s) y = let Node r k = unfoldTrie c+ n = l + 1+ in case k ? y of++ Just q -> let qc = unfoldTrie q++ in case qc of++ Node [] _ -> case r of++ [] -> case s of++ [] -> [ PD n h qc [] [] ]+ zs -> [ PD n h qc (y : i) zs ]++ xs -> case l of++ 0 -> [ PD n h qc []+ [ initPD m (justQuit x :) | x <- xs ] ]+ _ -> [ PD n h qc [y]+ ( concat [ parseDeep m+ [initPD m (justQuit x :)]+ (skipQuit x) |+ x <- xs ] ) ]++ _ -> [ PD n h qc [] [] ]++ Nothing -> case l of++ 0 -> case r of++ [] -> [ PD l h c i s ]+ xs -> [ initPD m (h . (justQuit x :)) | x <- xs ]++ _ -> case r of++ [] -> [ PD rn (h . rh) rc ri rs |+ PD rn rh rc ri rs <- parseDeep m+ (lastPD s (initPD m id))+ (reverse (y : i)) ]+ xs -> concat [ parseDeep m+ [initPD m (h . (justQuit x :))]+ (skipQuit x ++ [y]) |+ x <- xs ]+++unParseDeep :: Ord s => Mapper s (Quit s a) -> [ParseDeep s a] -> [[[a]]]++unParseDeep m = concat . map (unParsePD m)+++unParsePD :: Ord s => Mapper s (Quit s a) -> ParseDeep s a -> [[[a]]]++unParsePD m (PD l h c i s) = let Node r k = unfoldTrie c++ in case r of++ [] -> case s of++ [] -> [[ h [] ]]+ zs -> [ h u : v | (u : v) <- unParseDeep m+ (parseDeep m zs (reverse i)) ]++ xs -> case l of++ 0 -> [[ h [] ]]++ _ -> concat [ case skipQuit x of++ [] -> [[ h [justQuit x] ]]+ is -> [ h [justQuit x] : u |+ u <- unParseDeep m+ (parseDeep m [initPD m id] is) ]++ | x <- xs ]+++parseLongestDeep :: Ord s => Mapper s (Quit s a) -> [s] -> [a]++parseLongestDeep = parseLongestDeepWith (head . map concat)+++parseLongestDeepWith :: Ord s => ([[[a]]] -> [b]) -> Mapper s (Quit s a) -> [s] -> [b]++parseLongestDeepWith f m i = f (unParseDeep m (parseDeep m [initPD m id] i))++++--parseLongest :: Ord s => Mapper s a -> [s] -> [a]+parseLongest :: (Ord s, Eq a, Show a) => Mapper s (Quit s a) -> [s] -> [a]++parseLongest = parseLongestCheck+--parseLongest = parseLongestWide+++--parseLongestWith :: Ord s => ([[[a]]] -> [a]) -> Mapper s a -> [s] -> [a]+parseLongestWith :: (Ord s, Eq b, Show b) => ([[[a]]] -> [b]) -> Mapper s (Quit s a) -> [s] -> [b]++parseLongestWith = parseLongestCheckWith+--parseLongestWith = parseLongestWideWith+++parseLongestCheck :: (Ord s, Eq a, Show a) => Mapper s (Quit s a) -> [s] -> [a]++parseLongestCheck = parseLongestCheckWith (head . map concat)+++parseLongestCheckWith :: (Ord s, Eq b, Show b) => ([[[a]]] -> [b]) -> Mapper s (Quit s a) -> [s] -> [b]++parseLongestCheckWith f m i = let wide = parseLongestWideWith f m i+ deep = parseLongestDeepWith f m i+ in if wide == deep+ then wide+ else error ("\n\t" ++ show wide +++ "\n\t" ++ show deep)
+ Encode/Unicode.hs view
@@ -0,0 +1,48 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Unicode+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- The Haskell analogy to the /Encode::Unicode/ module in Perl:+-- <http://search.cpan.org/dist/Encode/>+--+-- "Encode.Unicode.UTF8"+++module Encode.Unicode (++ -- * Modules++ module Encode.Unicode.UTF8,++ -- * Types++ Unicode (..)++ ) where+++import Encode++import Encode.Unicode.UTF8++import Version++version = revised "$Revision: 130 $"+++data Unicode = Unicode | UCS++ deriving (Enum, Show)+++instance Encoding Unicode
+ Encode/Unicode/UTF8.hs view
@@ -0,0 +1,89 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Encode.Unicode.UTF8+-- Copyright : Otakar Smrz 2005-2006+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Modified version of John Meacham's <http://repetae.net/repos/jhc/UTF8.hs>+++module Encode.Unicode.UTF8 (++ -- * Types++ UTF8 (..)++ ) where+++import Encode++import Data.Bits++import Version++version = revised "$Revision: 130 $"+++data UTF8 = UTF8 | UTF++ deriving (Enum, Show)+++instance Encoding UTF8 where++ encode _ = map toEnum . integerUTF . map fromEnum++ decode _ = map toEnum . integerUCS . map fromEnum+++-- http://repetae.net/john/repos/jhc/UTF8.hs+-- rewritten by Otakar Smrz+--+-- toUTF :: String -> [Word8]+-- toUTF = map fromIntegral . integerUTF . map fromEnum+--+-- fromUTF :: [Word8] -> String+-- fromUTF = map toEnum . integerUCS . map fromIntegral+++integerUTF :: [Int] -> [Int]+integerUTF [] = []+integerUTF (x:xs)+ | x <= 0x007F = x : integerUTF xs+ | x <= 0x07FF = (0xC0 .|. ((x `shift` (-6)) .&. 0x1F))+ : (0x80 .|. (x .&. 0x3F))+ : integerUTF xs+ | otherwise = (0xE0 .|. ((x `shift` (-12)) .&. 0x0F))+ : (0x80 .|. ((x `shift` (-6)) .&. 0x3F))+ : (0x80 .|. (x .&. 0x3F))+ : integerUTF xs+++integerUCS :: [Int] -> [Int]+integerUCS [] = []+integerUCS (x:xs)+ | x <= 0x7F = x : integerUCS xs+ | x <= 0xBF = error ("integerUCS: illegal character byte " ++ show x)+ | x <= 0xDF = doubleByte x xs+ | x <= 0xEF = tripleByte x xs+ | otherwise = error ("integerUCS: illegal character byte " ++ show x)++doubleByte x1 (x2:xs) = (((x1 .&. 0x1F) `shift` 6)+ .|. (x2 .&. 0x3F))+ : integerUCS xs+doubleByte x _ = error ("integerUCS: illegal 2-byte sequence " ++ show x)++tripleByte x1 (x2:x3:xs) = (((x1 .&. 0x0F) `shift` 12)+ .|. ((x2 .&. 0x3F) `shift` 6)+ .|. (x3 .&. 0x3F))+ : integerUCS xs+tripleByte x _ = error ("integerUCS: illegal 3-byte sequence " ++ show x)
+ FunParsing.hs view
@@ -0,0 +1,52 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- This library is an edited excerpt from the /Functional Parsing/ library+-- developed by Peter Ljunglöf in his licenciate thesis /Pure Functional+-- Parsing – an advanced tutorial/, Göteborg University and+-- Chalmers University of Technology, April 2002:+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software.html>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+--+--+-- Copyright (C) 2005-2006 Otakar Smrz (C) 2002 Peter Ljunglof+--+-- This program is free software; you can redistribute it and\/or modify+-- it under the terms of the GNU General Public License as published by+-- the Free Software Foundation; either version 2 of the License, or+-- (at your option) any later version.+--+-- This program is distributed in the hope that it will be useful,+-- but WITHOUT ANY WARRANTY; without even the implied warranty of+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+-- GNU General Public License for more details.+--+-- You should have received a copy of the GNU General Public License along+-- with this program; if not, write to the Free Software Foundation, Inc.,+-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.+--+--+-- "FunParsing.OrdMap" "FunParsing.OrdSet" "FunParsing.Parsers"+++module FunParsing where+++import Version++version = revised "$Revision: 135 $"
+ FunParsing/OrdMap.hs view
@@ -0,0 +1,140 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.OrdMap+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapter 1 and Appendix A of /Pure Functional Parsing – an advanced+-- tutorial/ by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+++--------------------------------------------------+-- The class of ordered finite maps+-- as described in section 2.2.2++-- and an example implementation,+-- derived from the implementation in appendix A.2+++module FunParsing.OrdMap (OrdMap(..), Map, makeMapWith, mapMapWithKey) where++import Data.List (intersperse)+++--------------------------------------------------+-- the class of ordered finite maps++class OrdMap m where+ emptyMap :: Ord s => m s a+ (|->) :: Ord s => s -> a -> m s a+ isEmptyMap :: Ord s => m s a -> Bool+ (?) :: Ord s => m s a -> s -> Maybe a+ lookupWith :: Ord s => a -> m s a -> s -> a+ mergeWith :: Ord s => (a -> a -> a) -> m s a -> m s a -> m s a+ unionMapWith :: Ord s => (a -> a -> a) -> [m s a] -> m s a+ assocs :: Ord s => m s a -> [(s,a)]+ ordMap :: Ord s => [(s,a)] -> m s a+ mapMap :: Ord s => (a -> b) -> m s a -> m s b++ lookupWith z m s = case m ? s of+ Just a -> a+ Nothing -> z++ unionMapWith join = union+ where union [] = emptyMap+ union [xs] = xs+ union xyss = mergeWith join (union xss) (union yss)+ where (xss, yss) = split xyss+ split (x:y:xyss) = let (xs, ys) = split xyss in (x:xs, y:ys)+ split xs = (xs, [])+++makeMapWith :: (Ord s, OrdMap m) => (a -> a -> a) -> [(s,a)] -> m s a++makeMapWith join [] = emptyMap+makeMapWith join [(s,a)] = s |-> a+makeMapWith join xyss = mergeWith join (makeMapWith join xss)+ (makeMapWith join yss)+ where (xss, yss) = split xyss+ split (x:y:xys) = let (xs, ys) = split xys in (x:xs, y:ys)+ split xs = (xs, [])++--------------------------------------------------+-- finite maps as ordered associaiton lists,+-- paired with binary search trees++data Map s a = Map [(s,a)] (TreeMap s a)++instance (Eq s, Eq a) => Eq (Map s a) where+ Map xs _ == Map ys _ = xs == ys++instance (Show s, Show a) => Show (Map s a) where+ show (Map ass _) = "{" ++ concat (intersperse "," (map show' ass)) ++ "}"+ where show' (s,a) = show s ++ "|->" ++ show a++instance OrdMap Map where+ emptyMap = Map [] (makeTree [])+ s |-> a = Map [(s,a)] (makeTree [(s,a)])++ isEmptyMap (Map ass _) = null ass++ Map _ tree ? s = lookupTree s tree++ mergeWith join (Map xss _) (Map yss _) = Map xyss (makeTree xyss)+ where xyss = merge xss yss+ merge [] yss = yss+ merge xss [] = xss+ merge xss@(x@(s,x'):xss') yss@(y@(t,y'):yss')+ = case compare s t of+ LT -> x : merge xss' yss+ GT -> y : merge xss yss'+ EQ -> (s, join x' y') : merge xss' yss'++ assocs (Map xss _) = xss+ ordMap xss = Map xss (makeTree xss)++ mapMap f (Map ass atree) = Map [ (s,f a) | (s,a) <- ass ] (mapTree f atree)++mapMapWithKey f (Map ass atree) = Map [ (s,f s a) | (s,a) <- ass ]+ (mapTreeWithKey f atree)++--------------------------------------------------+-- binary search trees+-- for logarithmic lookup time++data TreeMap s a = Nil | Node (TreeMap s a) s a (TreeMap s a)++makeTree ass = tree+ where+ (tree,[]) = sl2bst (length ass) ass+ sl2bst 0 ass = (Nil, ass)+ sl2bst 1 ((s,a):ass) = (Node Nil s a Nil, ass)+ sl2bst n ass = (Node ltree s a rtree, css)+ where llen = (n-1) `div` 2+ rlen = n - 1 - llen+ (ltree, (s,a):bss) = sl2bst llen ass+ (rtree, css) = sl2bst rlen bss++lookupTree s Nil = Nothing+lookupTree s (Node left s' a right)+ = case compare s s' of+ LT -> lookupTree s left+ GT -> lookupTree s right+ EQ -> Just a++mapTree f Nil = Nil+mapTree f (Node l s a r) = Node (mapTree f l) s (f a) (mapTree f r)++mapTreeWithKey f Nil = Nil+mapTreeWithKey f (Node l s a r) = Node (mapTreeWithKey f l) s (f s a)+ (mapTreeWithKey f r)
+ FunParsing/OrdSet.hs view
@@ -0,0 +1,129 @@+-- --------------------------------------------------------------------------+-- $Revision: 130 $ $Date: 2006-11-09 16:22:20 +0100 (Thu, 09 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.OrdSet+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapter 1 and Appendix A of /Pure Functional Parsing – an advanced+-- tutorial/ by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+++--------------------------------------------------+-- The class of ordered sets+-- as described in section 2.2.1++-- and an example implementation,+-- derived from the implementation in appendix A.1+++module FunParsing.OrdSet (OrdSet(..), Set) where++import Data.List (intersperse)+++--------------------------------------------------+-- the class of ordered sets++class OrdSet m where+ emptySet :: Ord a => m a+ unitSet :: Ord a => a -> m a+ isEmpty :: Ord a => m a -> Bool+ elemSet :: Ord a => a -> m a -> Bool+ (<++>) :: Ord a => m a -> m a -> m a+ (<\\>) :: Ord a => m a -> m a -> m a+ plusMinus :: Ord a => m a -> m a -> (m a, m a)+ union :: Ord a => [m a] -> m a+ makeSet :: Ord a => [a] -> m a+ elems :: Ord a => m a -> [a]+ ordSet :: Ord a => [a] -> m a+ limit :: Ord a => (a -> m a) -> m a -> m a++ xs <++> ys = fst (plusMinus xs ys)+ xs <\\> ys = snd (plusMinus xs ys)+ plusMinus xs ys = (xs <++> ys, xs <\\> ys)++ union [] = emptySet+ union [xs] = xs+ union xyss = union xss <++> union yss+ where (xss, yss) = split xyss+ split (x:y:xyss) = let (xs, ys) = split xyss in (x:xs, y:ys)+ split xs = (xs, [])++ makeSet xs = union (map unitSet xs)++ limit more start = limit' (start, start)+ where limit' (old, new)+ | isEmpty new' = old+ | otherwise = limit' (plusMinus new' old)+ where new' = union (map more (elems new))+++--------------------------------------------------+-- sets as ordered lists,+-- paired with a binary tree++data Set a = Set [a] (TreeSet a)++instance Eq a => Eq (Set a) where+ Set xs _ == Set ys _ = xs == ys++instance Ord a => Ord (Set a) where+ compare (Set xs _) (Set ys _) = compare xs ys++instance Show a => Show (Set a) where+ show (Set xs _) = "{" ++ concat (intersperse "," (map show xs)) ++ "}"++instance OrdSet Set where+ emptySet = Set [] (makeTree [])+ unitSet a = Set [a] (makeTree [a])++ isEmpty (Set xs _) = null xs+ elemSet a (Set _ xt) = elemTree a xt++ plusMinus (Set xs _) (Set ys _) = (Set ps (makeTree ps), Set ms (makeTree ms))+ where (ps, ms) = plm xs ys+ plm [] ys = (ys, [])+ plm xs [] = (xs, xs)+ plm xs@(x:xs') ys@(y:ys') = case compare x y of+ LT -> let (ps, ms) = plm xs' ys in (x:ps, x:ms)+ GT -> let (ps, ms) = plm xs ys' in (y:ps, ms)+ EQ -> let (ps, ms) = plm xs' ys' in (x:ps, ms)++ elems (Set xs _) = xs+ ordSet xs = Set xs (makeTree xs)+++--------------------------------------------------+-- binary search trees+-- for logarithmic lookup time++data TreeSet a = Nil | Node (TreeSet a) a (TreeSet a)++makeTree xs = tree+ where (tree,[]) = sl2bst (length xs) xs+ sl2bst 0 xs = (Nil, xs)+ sl2bst 1 (a:xs) = (Node Nil a Nil, xs)+ sl2bst n xs = (Node ltree a rtree, zs)+ where llen = (n-1) `div` 2+ rlen = n - 1 - llen+ (ltree, a:ys) = sl2bst llen xs+ (rtree, zs) = sl2bst rlen ys++elemTree a Nil = False+elemTree a (Node ltree x rtree)+ = case compare a x of+ LT -> elemTree a ltree+ GT -> elemTree a rtree+ EQ -> True++
+ FunParsing/Parsers.hs view
@@ -0,0 +1,70 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+--+-- With this limited distribution, you can create only some of the parsers+-- described in the thesis. These include in particular:+--+-- ['Standard' @s@]+-- "FunParsing.Parsers.Standard",+-- the standard parser, sec. 3.2+--+-- ['Stream' @s@]+-- "FunParsing.Parsers.Stream",+-- the stream processor parser, sec. 3.5.2+--+-- ['Trie' @s@]+-- "FunParsing.Parsers.Trie",+-- the trie parser, sec. 4.2.1+--+-- ['AmbTrie' @s@]+-- "FunParsing.Parsers.AmbTrie",+-- the ambiguous trie parser, sec. 4.2.2+--+-- ['ExTrie' @s@]+-- "FunParsing.Parsers.ExTrie",+-- the extended trie parser, sec. 4.3.3+--+-- ['AmbExTrie' @s@]+-- "FunParsing.Parsers.AmbExTrie",+-- the ambiguous extended trie parser, sec. 4.3.4+--+-- ['PairTrie' 'Standard' @s@]+-- "FunParsing.Parsers.PairTrie", together with+-- "FunParsing.Parsers.Standard",+-- the paired trie parser, sec. 4.4+--+-- "FunParsing.OrdMap" "FunParsing.Parsers.Parser"+++module FunParsing.Parsers where+++import FunParsing.Parsers.Standard+import FunParsing.Parsers.Stream+import FunParsing.Parsers.Trie+import FunParsing.Parsers.AmbTrie+import FunParsing.Parsers.ExTrie+import FunParsing.Parsers.AmbExTrie+import FunParsing.Parsers.PairTrie++import Version++version = revised "$Revision: 135 $"
+ FunParsing/Parsers/AmbExTrie.hs view
@@ -0,0 +1,92 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.AmbExTrie+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the ambiguous extended trie from section 4.3.4+++module FunParsing.Parsers.AmbExTrie (AmbExTrie (..), unfold) where++import FunParsing.OrdMap+import FunParsing.Parsers.Parser+++data AmbExTrie s a = [a] :&: Map s (AmbExTrie s a) |+ forall b . FMap (b -> a) (AmbExTrie s b)+++unfold :: Ord s => (a -> b) -> AmbExTrie s a -> AmbExTrie s b+unfold f (as :&: pmap) = map f as :&: mapMap (FMap f) pmap+unfold f (FMap g p) = FMap (f . g) p+++instance Ord s => Monoid (AmbExTrie s) where+ zero = [] :&: emptyMap++ FMap f p <+> q = unfold f p <+> q+ p <+> FMap f q = p <+> unfold f q+ (as:&:pmap) <+> (bs:&:qmap) = (as++bs) :&: mergeWith (<+>) pmap qmap+++instance Ord s => Monad (AmbExTrie s) where+ return a = [a] :&: emptyMap++ FMap f p >>= k = unfold f p >>= k+ (as:&:pmap) >>= k = foldr (<+>) ([]:&:mapMap (>>=k) pmap) (map k as)+++instance Ord s => Functor (AmbExTrie s) where+ fmap = FMap+++instance Ord s => Sequence (AmbExTrie s)+++instance InputSymbol s => Symbol (AmbExTrie s) s where+ sym s = [] :&: (s |-> return s)+ sat p = anyof (map sym (filter p symbols))+++instance Ord s => Parser (AmbExTrie s) s where++ -- parse = error "AmbExTrie: parse is not implemented"+ --+ -- parse implemented by Otakar Smrz++ parse p inp = parse' p inp id+ parseFull p inp = parseFull' p inp id++parse' :: Ord s => AmbExTrie s a -> [s] -> (a -> b) -> [([s], b)]+parse' (FMap f p) inp k = parse' p inp (k . f)+parse' ([] :&: pmap) [] k = []+parse' ([] :&: pmap) (s:inp) k = case pmap ? s of+ Just p -> parse' p inp k+ Nothing -> []+parse' (xs :&: pmap) inp k = foldr ( (:) . (,) inp . k )+ (parse' ([] :&: pmap) inp k) xs++parseFull' :: Ord s => AmbExTrie s a -> [s] -> (a -> b) -> [b]+parseFull' (FMap f p) inp k = parseFull' p inp (k . f)+parseFull' (xs :&: _) [] k = map k xs+parseFull' (_ :&: pmap) (s:inp) k = case pmap ? s of+ Just p -> parseFull' p inp k+ Nothing -> []
+ FunParsing/Parsers/AmbTrie.hs view
@@ -0,0 +1,79 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.AmbTrie+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the ambiguous trie from section 4.2.2+++module FunParsing.Parsers.AmbTrie (AmbTrie (..)) where++import FunParsing.OrdMap+import FunParsing.Parsers.Parser+++data AmbTrie s a = [a] :&: Map s (AmbTrie s a)+++instance Ord s => Monoid (AmbTrie s) where+ zero = [] :&: emptyMap++ (as:&:pmap) <+> (bs:&:qmap) = (as++bs) :&: mergeWith (<+>) pmap qmap+++instance Ord s => Monad (AmbTrie s) where+ return a = [a] :&: emptyMap++ (as:&:pmap) >>= k = foldr (<+>) ([]:&:mapMap (>>=k) pmap) (map k as)+++instance Ord s => Functor (AmbTrie s) where+ fmap f p = do a <- p ; return (f a)+{--+ fmap f (as :&: pmap) = map f as :&: mapMap (fmap f) pmap+--}+++instance Ord s => Sequence (AmbTrie s)+++instance InputSymbol s => Symbol (AmbTrie s) s where+ sym s = [] :&: (s |-> return s)+ sat p = anyof (map sym (filter p symbols))+++instance Ord s => Parser (AmbTrie s) s where++ -- parse = error "AmbTrie: parse is not implemented"+ --+ -- parse implemented by Otakar Smrz++ parse ([] :&: pmap) [] = []+ parse ([] :&: pmap) (s:inp) = case pmap ? s of+ Just p -> parse p inp+ Nothing -> []+ parse (xs :&: pmap) inp = foldr ((:) . (,) inp)+ (parse ([] :&: pmap) inp) xs++ parseFull (xs :&: _) [] = xs+ parseFull (_ :&: pmap) (s:inp) = case pmap ? s of+ Just p -> parseFull p inp+ Nothing -> []
+ FunParsing/Parsers/ExTrie.hs view
@@ -0,0 +1,94 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.ExTrie+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the extended trie from section 4.3.3+++module FunParsing.Parsers.ExTrie (ExTrie) where++import FunParsing.OrdMap+import FunParsing.Parsers.Parser+++data ExTrie s a = Shift (Map s (ExTrie s a)) |+ a ::: ExTrie s a |+ forall b . FMap (b -> a) (ExTrie s b)+++unfold :: Ord s => (a -> b) -> ExTrie s a -> ExTrie s b+unfold f (Shift pmap) = Shift (mapMap (FMap f) pmap)+unfold f (a ::: p) = f a ::: FMap f p+unfold f (FMap g p) = FMap (f . g) p+++instance Ord s => Monoid (ExTrie s) where+ zero = Shift emptyMap++ (a ::: p) <+> q = a ::: (p <+> q)+ p <+> (b ::: q) = b ::: (p <+> q)+ FMap f p <+> q = unfold f p <+> q+ p <+> FMap f q = p <+> unfold f q+ Shift pmap <+> Shift qmap = Shift (mergeWith (<+>) pmap qmap)+++instance Ord s => Monad (ExTrie s) where+ return a = a ::: zero++ (a ::: p) >>= k = k a <+> (p >>= k)+ FMap f p >>= k = unfold f p >>= k+ Shift pmap >>= k = Shift (mapMap (>>=k) pmap)+++instance Ord s => Functor (ExTrie s) where+ fmap = FMap+++instance Ord s => Sequence (ExTrie s)+++instance InputSymbol s => Symbol (ExTrie s) s where+ sym s = Shift (s |-> return s)+ sat p = anyof (map sym (filter p symbols))+++instance Ord s => Parser (ExTrie s) s where+ parse p inp = parse' p inp id+ parseFull p inp = parseFull' p inp id+++parse' :: Ord s => ExTrie s a -> [s] -> (a -> b) -> [([s], b)]+parse' (FMap f p) inp k = parse' p inp (k . f)+parse' (a ::: p) inp k = (inp, k a) : parse' p inp k+parse' _ [] k = []+parse' (Shift pmap) (s:inp) k = case pmap ? s of+ Just p -> parse' p inp k+ Nothing -> []++parseFull' :: Ord s => ExTrie s a -> [s] -> (a -> b) -> [b]+parseFull' (FMap f p) inp k = parseFull' p inp (k . f)+parseFull' (a ::: p) [] k = k a : parseFull' p [] k+parseFull' (a ::: p) inp k = parseFull' p inp k+parseFull' _ [] k = []+parseFull' (Shift pmap) (s:inp) k = case pmap ? s of+ Just p -> parseFull' p inp k+ Nothing -> []
+ FunParsing/Parsers/PairTrie.hs view
@@ -0,0 +1,113 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.PairTrie+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the pairing trie parser from section 4.4+++module FunParsing.Parsers.PairTrie (PairTrie, ParserTrie) where++import FunParsing.OrdMap+import FunParsing.Parsers.Parser+++--------------------------------------------------+-- section 4.4.2: pairing a trie with a parser++data PairTrie m s a = ParserTrie s (m a) :&: m a+++makeParser :: (Ord s, Monoid m, Lookahead m s) => ParserTrie s (m a) -> m a+makeParser ptrie = lookahead (anyof . parseFull ptrie)+++instance (Ord s, Monoid m, Lookahead m s) => Monoid (PairTrie m s) where+ zero = zero :&: zero++ (ptrie :&: _) <+> (qtrie :&: _) = pqtrie :&: makeParser pqtrie+ where pqtrie = ptrie <+> qtrie+++instance (Ord s, Monad m) => Monad (PairTrie m s) where+ return a = (p ::: zero) :&: p+ where p = return a++ (>>=) = error "PairTrie: (>>=) is not implemented"+++instance (Ord s, Functor m) => Functor (PairTrie m s) where+ fmap f (trie :&: p) = fmap (fmap f) trie :&: fmap f p+++instance (Ord s, Monoid m, Sequence m, Lookahead m s) => Sequence (PairTrie m s) where+ (ptrie :&: _) <*> ~(qtrie :&: q) = pqtrie :&: makeParser pqtrie+ where pqtrie = mapPQ ptrie+ mapPQ (Shift pmap') = Shift (mapMap mapPQ pmap')+ mapPQ (p' ::: ptrie') = mapPQ ptrie' <+> fmap (p'<*>) qtrie+ mapPQ (Found p' ptrie') = Found (p' <*> q) (mapPQ ptrie')+++instance (InputSymbol s, Monoid m, Symbol m s, Lookahead m s) => Symbol (PairTrie m s) s where+ sym s = Found p ptrie :&: p+ where p = sym s+ ptrie = Shift (s |-> Found skip (skip ::: zero))++ sat p = anyof (map sym (filter p symbols))+++instance (Ord s, Parser m s) => Parser (PairTrie m s) s where+ parse = error "PairTrie: parse is not implemented"+ parseFull (_ :&: p) = parseFull p+++--------------------------------------------------+-- section 4.4.1: a trie of parsers++data ParserTrie s a = Shift (Map s (ParserTrie s a)) |+ a ::: ParserTrie s a |+ Found a (ParserTrie s a)++instance Ord s => Monoid (ParserTrie s) where+ zero = Shift emptyMap++ Found p ptrie <+> qtrie = ptrie <+> qtrie+ ptrie <+> Found q qtrie = ptrie <+> qtrie+ (p ::: ptrie) <+> qtrie = p ::: (ptrie <+> qtrie)+ ptrie <+> (q ::: qtrie) = q ::: (ptrie <+> qtrie)+ Shift ptries <+> Shift qtries = Shift (mergeWith (<+>) ptries qtries)+++instance Ord s => Functor (ParserTrie s) where+ fmap f (Shift pmap) = Shift (mapMap (fmap f) pmap)+ fmap f (p ::: ptrie) = f p ::: fmap f ptrie+ fmap f (Found p ptrie) = Found (f p) (fmap f ptrie)+++instance Ord s => Parser (ParserTrie s) s where+ parse = error "PairTrie: parse is not implemented"++ parseFull (Found p _) inp = [p]+ parseFull (p ::: ptrie) inp = p : parseFull ptrie inp+ parseFull (Shift _) [] = []+ parseFull (Shift pmap) (s:inp) = case pmap ? s of+ Just ptrie -> parseFull ptrie inp+ Nothing -> []
+ FunParsing/Parsers/Parser.hs view
@@ -0,0 +1,170 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.Parser+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- The classes of context-free and monadic combinator+-- parsers, from sections 2.4, 2.5 and 2.7 together+-- with the derived combinators from section 2.8++-- observe that the class hierarchy differs somewhat+-- from the thesis, /return/ is already defined in+-- the /Monad/ class+++module FunParsing.Parsers.Parser where++infixr 4 <:>+infixl 3 <*> , *>+infixl 2 <+>+++--------------------------------------------------+-- the /Parser/ class (section 2.4)++class Parser m s | m -> s where+ parse :: m a -> [s] -> [([s], a)]+ parseFull :: m a -> [s] -> [a]+ parseFull p inp = [ a | ([], a) <- parse p inp ]+++--------------------------------------------------+-- the /Monoid/ class (section 2.5)++class Monoid m where+ zero :: m a+ (<+>) :: m a -> m a -> m a+ anyof :: [m a] -> m a+ anyof = foldr (<+>) zero+++{-------------------------------------------------+-- the /PreMonad/ class (section 2.5) cannot be+-- defined, since /return/ is already in /Monad/++class PreMonad m where+ return :: a -> m a+--}+++--------------------------------------------------+-- the /Sequence/ class (section 2.5)+-- depends on /return/, which means that it+-- has to depend on /Monad/++-- also we require it to be a /Functor/ because+-- of the definitions in section 2.8++class (Monad m, Functor m) => Sequence m where+ (<*>) :: m (a -> b) -> m a -> m b+ ( *>) :: m a -> m b -> m b+ p <*> q = p >>= \f -> fmap f q+ p *> q = fmap (\x y -> y) p <*> q+++{-------------------------------------------------+-- the /Monad/ class is already defined,+-- as is the /Functor/ class++class PreMonad m => Monad m where+ (>>=) :: m a -> (a -> m b) -> m b+ (>>) :: m a -> m b -> m b++class Functor m where+ fmap :: (a -> b) -> m a -> m b+--}+++--------------------------------------------------+-- the /Symbol/ class (section 2.5)++class Eq s => Symbol m s | m -> s where+ sym :: s -> m s+ sat :: (s -> Bool) -> m s+ skip :: m s+ sym s = sat (s ==)+ skip = sat (\x -> True)+++--------------------------------------------------+-- to be able to define /sat/ in terms of /sym/+-- we need a list of all possible input symbols+-- as explaine in section 2.5, the paragraph on+-- input symbols++-- this class is used in the trie parsers+-- from chapter 4++class Ord s => InputSymbol s where+ minSym, maxSym :: s+ symbols :: [s]++instance InputSymbol Char where+ minSym = minBound+ maxSym = maxBound+ symbols = [minSym .. maxSym]++instance InputSymbol Int where+ minSym = minBound+ maxSym = maxBound+ symbols = [minSym .. maxSym]+++--------------------------------------------------+-- the /SymbolCont/ class is used by the continuation+-- transformers in sections 3.3.1 and 3.4++class Eq s => SymbolCont m s | m -> s where+ satCont :: (s -> Bool) -> (s -> m a) -> m a+++--------------------------------------------------+-- the /Lookahead/ class is used by the pairing trie+-- and is described in section 4.4.2++class Lookahead m s | m -> s where+ lookahead :: ([s] -> m a) -> m a+++--------------------------------------------------+-- the derived combinators from section 2.8.1++success :: Monad m => m ()+success = return ()++many0 :: (Monoid m, Sequence m) => m a -> m ()+many0 p = ps+ where ps = success <+> p *> ps++syms0 :: (Sequence m, Symbol m s) => [s] -> m ()+syms0 [] = success+syms0 (s:ss) = sym s *> syms0 ss++(<:>) :: Sequence m => m a -> m [a] -> m [a]+p <:> ps = fmap (:) p <*> ps++many :: (Monoid m, Sequence m) => m a -> m [a]+many p = ps+ where ps = return [] <+> p <:> ps++syms :: (Sequence m, Symbol m s) => [s] -> m [s]+syms [] = return []+syms (s:ss) = sym s <:> syms ss
+ FunParsing/Parsers/Standard.hs view
@@ -0,0 +1,77 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.Standard+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the standard parser from section 3.2+++module FunParsing.Parsers.Standard (Standard) where++import FunParsing.Parsers.Parser+++newtype Standard s a = Std ([s] -> [([s], a)])+++instance Monoid (Standard s) where+ zero = Std (\inp -> [])+ Std p <+> Std q = Std (\inp -> p inp ++ q inp)+++instance Monad (Standard s) where+ return a = Std (\inp -> [(inp,a)])+ Std p >>= k = Std (\inp -> concat [ q inp' |+ (inp', a) <- p inp,+ let Std q = k a ])+++instance Functor (Standard s) where+ fmap f p = do a <- p ; return (f a)+{--+ fmap f (Std p) = Std (\inp -> [ (inp', f a) | (inp', a) <- p inp ])+--}+++instance Sequence (Standard s)+{--+ Std p <*> Std q = Std (\inp -> [ (inp'', f a) | (inp', f) <- p inp, (inp'', a) <- q inp' ])+--}+++instance Eq s => Symbol (Standard s) s where+ sat p = Std sat'+ where sat' (s:inp) | p s = [(inp, s)]+ sat' _ = []+++instance Eq s => SymbolCont (Standard s) s where+ satCont p fut = Std sat'+ where sat' (s:inp) | p s = let Std p = fut s in p inp+ sat' _ = []+++instance Parser (Standard s) s where+ parse (Std p) inp = p inp+++instance Lookahead (Standard s) s where+ lookahead f = Std (\inp -> let Std p = f inp in p inp)
+ FunParsing/Parsers/Stream.hs view
@@ -0,0 +1,88 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.Stream+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the stream processor from section 3.5.2+++module FunParsing.Parsers.Stream (Stream) where++import FunParsing.Parsers.Parser+++data Stream s a = Shift (s -> Stream s a) |+ a ::: Stream s a |+ Nil+++instance Monoid (Stream s) where+ zero = Nil++ Nil <+> bs = bs+ as <+> Nil = as+ (a:::as) <+> bs = a ::: (as <+> bs)+ as <+> (b:::bs) = b ::: (as <+> bs)+ Shift f <+> Shift g = Shift (\s -> f s <+> g s)+++instance Monad (Stream s) where+ return a = a ::: Nil++ Shift f >>= k = Shift (\s -> f s >>= k)+ (a:::as) >>= k = k a <+> (as >>= k)+ Nil >>= k = Nil+++instance Functor (Stream s) where+ fmap f p = do a <- p ; return (f a)+{--+ fmap f (Shift g) = Shift (fmap f . g)+ fmap f (a:::as) = f a ::: fmap f as+ fmap f Nil = Nil+--}+++instance Sequence (Stream s)+++instance Eq s => Symbol (Stream s) s where+ skip = Shift return+ sat p = Shift (\s -> if p s then return s else zero)+++instance Eq s => SymbolCont (Stream s) s where+ satCont p fut = Shift (\s -> if p s then fut s else zero)+++instance Parser (Stream s) s where+ parse (Shift f) (s:inp) = parse (f s) inp+ parse (a:::p) inp = (inp, a) : parse p inp+ parse _ _ = []++ parseFull (Shift f) (s:inp) = parseFull (f s) inp+ parseFull p [] = collect p+ where collect (a:::p) = a : collect p+ collect _ = []+ parseFull (a:::p) inp = parseFull p inp+ parseFull _ _ = []++
+ FunParsing/Parsers/Trie.hs view
@@ -0,0 +1,85 @@+-- --------------------------------------------------------------------------+-- $Revision: 135 $ $Date: 2006-11-10 10:50:22 +0100 (Fri, 10 Nov 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : FunParsing.Parsers.Trie+-- Copyright : Peter Ljunglof 2002+-- License : GPL+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Chapters 3 and 4 of /Pure Functional Parsing – an advanced tutorial/+-- by Peter Ljunglöf+--+-- <http://www.cs.chalmers.se/~peb/pubs/p02-lic-thesis.pdf>+--+-- <http://www.cs.chalmers.se/~peb/software/functional-parsing/>+++--------------------------------------------------+-- the trie parser from section 4.2.1+++module FunParsing.Parsers.Trie (Trie) where++import FunParsing.OrdMap+import FunParsing.Parsers.Parser+++data Trie s a = Shift (Map s (Trie s a)) |+ a ::: Trie s a+++instance Ord s => Monoid (Trie s) where+ zero = Shift emptyMap++ (a ::: p) <+> q = a ::: (p <+> q)+ p <+> (b ::: q) = b ::: (p <+> q)+ Shift pmap <+> Shift qmap = Shift (mergeWith (<+>) pmap qmap)+++instance Ord s => Monad (Trie s) where+ return a = a ::: zero++ (a ::: p) >>= k = k a <+> (p >>= k)+ Shift pmap >>= k = Shift (mapMap (>>=k) pmap)+++instance Ord s => Functor (Trie s) where+ fmap f p = do a <- p ; return (f a)+{--+ fmap f (a ::: p) = f a ::: fmap f p+ fmap f (Shift pmap) = Shift (mapMap (fmap f) pmap)+--}+++instance Ord s => Sequence (Trie s)+++instance InputSymbol s => Symbol (Trie s) s where+ sym s = Shift (s |-> return s)+ sat p = anyof (map sym (filter p symbols))+++instance Ord s => Parser (Trie s) s where+ parse (a ::: p) inp = (inp, a) : parse p inp+ parse _ [] = []+ parse (Shift pmap) (s:inp) = case pmap ? s of+ Just p -> parse p inp+ Nothing -> []++ parseFull p [] = collect p+ where collect (a:::p) = a : collect p+ collect _ = []+ parseFull (_ ::: p) inp = parseFull p inp+ parseFull (Shift pmap) (s:inp) = case pmap ? s of+ Just p -> parseFull p inp+ Nothing -> []++++
+ INSTALL view
@@ -0,0 +1,47 @@+INSTALLATION INSTRUCTIONS++This package is prepared with Cabal. You need some Haskell compiler installed+that understands Cabal and Haddock.++ http://www.haskell.org/ghc/+ http://www.haskell.org/hugs/++ http://www.haskell.org/cabal/+ http://www.haskell.org/haddock/+++1) Unpack the source distribution of this package and move to its root+ directory. You have probably done so already, since you are reading these+ instructions.++2) From the command line, run the following (runhaskell is runghc or runhugs):++ runhaskell Setup.hs --help++ You can then build the package, install it, generate the documentation, ...++ runhaskell Setup.hs configure+ runhaskell Setup.hs build+ runhaskell Setup.hs install+ runhaskell Setup.hs haddock++ Alternatively, you can load Setup.hs into the interpreters (Hugs, GHCi) and+ run the following commands from within them:++ :load Setup.hs++ :main --help++ :main configure+ :main build+ :main install+ :main haddock+++If you need more help, please consult the Cabal documentation website.++ http://www.haskell.org/cabal/release/latest/doc/users-guide/x606.html+ http://www.haskell.org/cabal/release/latest/doc/users-guide/+++Enjoy! ^^
+ LICENSE view
@@ -0,0 +1,339 @@+ GNU GENERAL PUBLIC LICENSE+ Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users. This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it. (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.) You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++ To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have. You must make sure that they, too, receive or can get the+source code. And you must show them these terms so they know their+rights.++ We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++ Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software. If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++ Finally, any free program is threatened constantly by software+patents. We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary. To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++ The precise terms and conditions for copying, distribution and+modification follow.++ GNU GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License. The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language. (Hereinafter, translation is included without limitation in+the term "modification".) Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++ 1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++ 2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) You must cause the modified files to carry prominent notices+ stating that you changed the files and the date of any change.++ b) You must cause any work that you distribute or publish, that in+ whole or in part contains or is derived from the Program or any+ part thereof, to be licensed as a whole at no charge to all third+ parties under the terms of this License.++ c) If the modified program normally reads commands interactively+ when run, you must cause it, when started running for such+ interactive use in the most ordinary way, to print or display an+ announcement including an appropriate copyright notice and a+ notice that there is no warranty (or else, saying that you provide+ a warranty) and that users may redistribute the program under+ these conditions, and telling the user how to view a copy of this+ License. (Exception: if the Program itself is interactive but+ does not normally print such an announcement, your work based on+ the Program is not required to print an announcement.)++These requirements apply to the modified work as a whole. If+identifiable sections of that work are not derived from the Program,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works. But when you+distribute the same sections as part of a whole which is a work based+on the Program, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Program.++In addition, mere aggregation of another work not based on the Program+with the Program (or with a work based on the Program) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++ 3. You may copy and distribute the Program (or a work based on it,+under Section 2) in object code or executable form under the terms of+Sections 1 and 2 above provided that you also do one of the following:++ a) Accompany it with the complete corresponding machine-readable+ source code, which must be distributed under the terms of Sections+ 1 and 2 above on a medium customarily used for software interchange; or,++ b) Accompany it with a written offer, valid for at least three+ years, to give any third party, for a charge no more than your+ cost of physically performing source distribution, a complete+ machine-readable copy of the corresponding source code, to be+ distributed under the terms of Sections 1 and 2 above on a medium+ customarily used for software interchange; or,++ c) Accompany it with the information you received as to the offer+ to distribute corresponding source code. (This alternative is+ allowed only for noncommercial distribution and only if you+ received the program in object code or executable form with such+ an offer, in accord with Subsection b above.)++The source code for a work means the preferred form of the work for+making modifications to it. For an executable work, complete source+code means all the source code for all modules it contains, plus any+associated interface definition files, plus the scripts used to+control compilation and installation of the executable. However, as a+special exception, the source code distributed need not include+anything that is normally distributed (in either source or binary+form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component+itself accompanies the executable.++If distribution of executable or object code is made by offering+access to copy from a designated place, then offering equivalent+access to copy the source code from the same place counts as+distribution of the source code, even though third parties are not+compelled to copy the source along with the object code.++ 4. You may not copy, modify, sublicense, or distribute the Program+except as expressly provided under this License. Any attempt+otherwise to copy, modify, sublicense or distribute the Program is+void, and will automatically terminate your rights under this License.+However, parties who have received copies, or rights, from you under+this License will not have their licenses terminated so long as such+parties remain in full compliance.++ 5. You are not required to accept this License, since you have not+signed it. However, nothing else grants you permission to modify or+distribute the Program or its derivative works. These actions are+prohibited by law if you do not accept this License. Therefore, by+modifying or distributing the Program (or any work based on the+Program), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Program or works based on it.++ 6. Each time you redistribute the Program (or any work based on the+Program), the recipient automatically receives a license from the+original licensor to copy, distribute or modify the Program subject to+these terms and conditions. You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties to+this License.++ 7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Program at all. For example, if a patent+license would not permit royalty-free redistribution of the Program by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Program.++If any portion of this section is held invalid or unenforceable under+any particular circumstance, the balance of the section is intended to+apply and the section as a whole is intended to apply in other+circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system, which is+implemented by public license practices. Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++ 8. If the distribution and/or use of the Program is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Program under this License+may add an explicit geographical distribution limitation excluding+those countries, so that distribution is permitted only in or among+countries not thus excluded. In such case, this License incorporates+the limitation as if written in the body of this License.++ 9. The Free Software Foundation may publish revised and/or new versions+of the General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++Each version is given a distinguishing version number. If the Program+specifies a version number of this License which applies to it and "any+later version", you have the option of following the terms and conditions+either of that version or of any later version published by the Free+Software Foundation. If the Program does not specify a version number of+this License, you may choose any version ever published by the Free Software+Foundation.++ 10. If you wish to incorporate parts of the Program into other free+programs whose distribution conditions are different, write to the author+to ask for permission. For software which is copyrighted by the Free+Software Foundation, write to the Free Software Foundation; we sometimes+make exceptions for this. Our decision will be guided by the two goals+of preserving the free status of all derivatives of our free software and+of promoting the sharing and reuse of software generally.++ NO WARRANTY++ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,+REPAIR OR CORRECTION.++ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+convey the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software; you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation; either version 2 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License along+ with this program; if not, write to the Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.++Also add information on how to contact you by electronic and paper mail.++If the program is interactive, make it output a short notice like this+when it starts in an interactive mode:++ Gnomovision version 69, Copyright (C) year name of author+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, the commands you use may+be called something other than `show w' and `show c'; they could even be+mouse-clicks or menu items--whatever suits your program.++You should also get your employer (if you work as a programmer) or your+school, if any, to sign a "copyright disclaimer" for the program, if+necessary. Here is a sample; alter the names:++ Yoyodyne, Inc., hereby disclaims all copyright interest in the program+ `Gnomovision' (which makes passes at compilers) written by James Hacker.++ <signature of Ty Coon>, 1 April 1989+ Ty Coon, President of Vice++This General Public License does not permit incorporating your program into+proprietary programs. If your program is a subroutine library, you may+consider it more useful to permit linking proprietary applications with the+library. If this is what you want to do, use the GNU Lesser General+Public License instead of this License.
+ LicenseBSD view
@@ -0,0 +1,9 @@+Copyright 2005-2006 Otakar Smrz. All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ LicenseGPL view
@@ -0,0 +1,339 @@+ GNU GENERAL PUBLIC LICENSE+ Version 2, June 1991++ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The licenses for most software are designed to take away your+freedom to share and change it. By contrast, the GNU General Public+License is intended to guarantee your freedom to share and change free+software--to make sure the software is free for all its users. This+General Public License applies to most of the Free Software+Foundation's software and to any other program whose authors commit to+using it. (Some other Free Software Foundation software is covered by+the GNU Lesser General Public License instead.) You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+this service if you wish), that you receive source code or can get it+if you want it, that you can change the software or use pieces of it+in new free programs; and that you know you can do these things.++ To protect your rights, we need to make restrictions that forbid+anyone to deny you these rights or to ask you to surrender the rights.+These restrictions translate to certain responsibilities for you if you+distribute copies of the software, or if you modify it.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must give the recipients all the rights that+you have. You must make sure that they, too, receive or can get the+source code. And you must show them these terms so they know their+rights.++ We protect your rights with two steps: (1) copyright the software, and+(2) offer you this license which gives you legal permission to copy,+distribute and/or modify the software.++ Also, for each author's protection and ours, we want to make certain+that everyone understands that there is no warranty for this free+software. If the software is modified by someone else and passed on, we+want its recipients to know that what they have is not the original, so+that any problems introduced by others will not reflect on the original+authors' reputations.++ Finally, any free program is threatened constantly by software+patents. We wish to avoid the danger that redistributors of a free+program will individually obtain patent licenses, in effect making the+program proprietary. To prevent this, we have made it clear that any+patent must be licensed for everyone's free use or not licensed at all.++ The precise terms and conditions for copying, distribution and+modification follow.++ GNU GENERAL PUBLIC LICENSE+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION++ 0. This License applies to any program or other work which contains+a notice placed by the copyright holder saying it may be distributed+under the terms of this General Public License. The "Program", below,+refers to any such program or work, and a "work based on the Program"+means either the Program or any derivative work under copyright law:+that is to say, a work containing the Program or a portion of it,+either verbatim or with modifications and/or translated into another+language. (Hereinafter, translation is included without limitation in+the term "modification".) Each licensee is addressed as "you".++Activities other than copying, distribution and modification are not+covered by this License; they are outside its scope. The act of+running the Program is not restricted, and the output from the Program+is covered only if its contents constitute a work based on the+Program (independent of having been made by running the Program).+Whether that is true depends on what the Program does.++ 1. You may copy and distribute verbatim copies of the Program's+source code as you receive it, in any medium, provided that you+conspicuously and appropriately publish on each copy an appropriate+copyright notice and disclaimer of warranty; keep intact all the+notices that refer to this License and to the absence of any warranty;+and give any other recipients of the Program a copy of this License+along with the Program.++You may charge a fee for the physical act of transferring a copy, and+you may at your option offer warranty protection in exchange for a fee.++ 2. You may modify your copy or copies of the Program or any portion+of it, thus forming a work based on the Program, and copy and+distribute such modifications or work under the terms of Section 1+above, provided that you also meet all of these conditions:++ a) You must cause the modified files to carry prominent notices+ stating that you changed the files and the date of any change.++ b) You must cause any work that you distribute or publish, that in+ whole or in part contains or is derived from the Program or any+ part thereof, to be licensed as a whole at no charge to all third+ parties under the terms of this License.++ c) If the modified program normally reads commands interactively+ when run, you must cause it, when started running for such+ interactive use in the most ordinary way, to print or display an+ announcement including an appropriate copyright notice and a+ notice that there is no warranty (or else, saying that you provide+ a warranty) and that users may redistribute the program under+ these conditions, and telling the user how to view a copy of this+ License. (Exception: if the Program itself is interactive but+ does not normally print such an announcement, your work based on+ the Program is not required to print an announcement.)++These requirements apply to the modified work as a whole. If+identifiable sections of that work are not derived from the Program,+and can be reasonably considered independent and separate works in+themselves, then this License, and its terms, do not apply to those+sections when you distribute them as separate works. But when you+distribute the same sections as part of a whole which is a work based+on the Program, the distribution of the whole must be on the terms of+this License, whose permissions for other licensees extend to the+entire whole, and thus to each and every part regardless of who wrote it.++Thus, it is not the intent of this section to claim rights or contest+your rights to work written entirely by you; rather, the intent is to+exercise the right to control the distribution of derivative or+collective works based on the Program.++In addition, mere aggregation of another work not based on the Program+with the Program (or with a work based on the Program) on a volume of+a storage or distribution medium does not bring the other work under+the scope of this License.++ 3. You may copy and distribute the Program (or a work based on it,+under Section 2) in object code or executable form under the terms of+Sections 1 and 2 above provided that you also do one of the following:++ a) Accompany it with the complete corresponding machine-readable+ source code, which must be distributed under the terms of Sections+ 1 and 2 above on a medium customarily used for software interchange; or,++ b) Accompany it with a written offer, valid for at least three+ years, to give any third party, for a charge no more than your+ cost of physically performing source distribution, a complete+ machine-readable copy of the corresponding source code, to be+ distributed under the terms of Sections 1 and 2 above on a medium+ customarily used for software interchange; or,++ c) Accompany it with the information you received as to the offer+ to distribute corresponding source code. (This alternative is+ allowed only for noncommercial distribution and only if you+ received the program in object code or executable form with such+ an offer, in accord with Subsection b above.)++The source code for a work means the preferred form of the work for+making modifications to it. For an executable work, complete source+code means all the source code for all modules it contains, plus any+associated interface definition files, plus the scripts used to+control compilation and installation of the executable. However, as a+special exception, the source code distributed need not include+anything that is normally distributed (in either source or binary+form) with the major components (compiler, kernel, and so on) of the+operating system on which the executable runs, unless that component+itself accompanies the executable.++If distribution of executable or object code is made by offering+access to copy from a designated place, then offering equivalent+access to copy the source code from the same place counts as+distribution of the source code, even though third parties are not+compelled to copy the source along with the object code.++ 4. You may not copy, modify, sublicense, or distribute the Program+except as expressly provided under this License. Any attempt+otherwise to copy, modify, sublicense or distribute the Program is+void, and will automatically terminate your rights under this License.+However, parties who have received copies, or rights, from you under+this License will not have their licenses terminated so long as such+parties remain in full compliance.++ 5. You are not required to accept this License, since you have not+signed it. However, nothing else grants you permission to modify or+distribute the Program or its derivative works. These actions are+prohibited by law if you do not accept this License. Therefore, by+modifying or distributing the Program (or any work based on the+Program), you indicate your acceptance of this License to do so, and+all its terms and conditions for copying, distributing or modifying+the Program or works based on it.++ 6. Each time you redistribute the Program (or any work based on the+Program), the recipient automatically receives a license from the+original licensor to copy, distribute or modify the Program subject to+these terms and conditions. You may not impose any further+restrictions on the recipients' exercise of the rights granted herein.+You are not responsible for enforcing compliance by third parties to+this License.++ 7. If, as a consequence of a court judgment or allegation of patent+infringement or for any other reason (not limited to patent issues),+conditions are imposed on you (whether by court order, agreement or+otherwise) that contradict the conditions of this License, they do not+excuse you from the conditions of this License. If you cannot+distribute so as to satisfy simultaneously your obligations under this+License and any other pertinent obligations, then as a consequence you+may not distribute the Program at all. For example, if a patent+license would not permit royalty-free redistribution of the Program by+all those who receive copies directly or indirectly through you, then+the only way you could satisfy both it and this License would be to+refrain entirely from distribution of the Program.++If any portion of this section is held invalid or unenforceable under+any particular circumstance, the balance of the section is intended to+apply and the section as a whole is intended to apply in other+circumstances.++It is not the purpose of this section to induce you to infringe any+patents or other property right claims or to contest validity of any+such claims; this section has the sole purpose of protecting the+integrity of the free software distribution system, which is+implemented by public license practices. Many people have made+generous contributions to the wide range of software distributed+through that system in reliance on consistent application of that+system; it is up to the author/donor to decide if he or she is willing+to distribute software through any other system and a licensee cannot+impose that choice.++This section is intended to make thoroughly clear what is believed to+be a consequence of the rest of this License.++ 8. If the distribution and/or use of the Program is restricted in+certain countries either by patents or by copyrighted interfaces, the+original copyright holder who places the Program under this License+may add an explicit geographical distribution limitation excluding+those countries, so that distribution is permitted only in or among+countries not thus excluded. In such case, this License incorporates+the limitation as if written in the body of this License.++ 9. The Free Software Foundation may publish revised and/or new versions+of the General Public License from time to time. Such new versions will+be similar in spirit to the present version, but may differ in detail to+address new problems or concerns.++Each version is given a distinguishing version number. If the Program+specifies a version number of this License which applies to it and "any+later version", you have the option of following the terms and conditions+either of that version or of any later version published by the Free+Software Foundation. If the Program does not specify a version number of+this License, you may choose any version ever published by the Free Software+Foundation.++ 10. If you wish to incorporate parts of the Program into other free+programs whose distribution conditions are different, write to the author+to ask for permission. For software which is copyrighted by the Free+Software Foundation, write to the Free Software Foundation; we sometimes+make exceptions for this. Our decision will be guided by the two goals+of preserving the free status of all derivatives of our free software and+of promoting the sharing and reuse of software generally.++ NO WARRANTY++ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,+REPAIR OR CORRECTION.++ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.++ END OF TERMS AND CONDITIONS++ How to Apply These Terms to Your New Programs++ If you develop a new program, and you want it to be of the greatest+possible use to the public, the best way to achieve this is to make it+free software which everyone can redistribute and change under these terms.++ To do so, attach the following notices to the program. It is safest+to attach them to the start of each source file to most effectively+convey the exclusion of warranty; and each file should have at least+the "copyright" line and a pointer to where the full notice is found.++ <one line to give the program's name and a brief idea of what it does.>+ Copyright (C) <year> <name of author>++ This program is free software; you can redistribute it and/or modify+ it under the terms of the GNU General Public License as published by+ the Free Software Foundation; either version 2 of the License, or+ (at your option) any later version.++ This program is distributed in the hope that it will be useful,+ but WITHOUT ANY WARRANTY; without even the implied warranty of+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ GNU General Public License for more details.++ You should have received a copy of the GNU General Public License along+ with this program; if not, write to the Free Software Foundation, Inc.,+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.++Also add information on how to contact you by electronic and paper mail.++If the program is interactive, make it output a short notice like this+when it starts in an interactive mode:++ Gnomovision version 69, Copyright (C) year name of author+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.+ This is free software, and you are welcome to redistribute it+ under certain conditions; type `show c' for details.++The hypothetical commands `show w' and `show c' should show the appropriate+parts of the General Public License. Of course, the commands you use may+be called something other than `show w' and `show c'; they could even be+mouse-clicks or menu items--whatever suits your program.++You should also get your employer (if you work as a programmer) or your+school, if any, to sign a "copyright disclaimer" for the program, if+necessary. Here is a sample; alter the names:++ Yoyodyne, Inc., hereby disclaims all copyright interest in the program+ `Gnomovision' (which makes passes at compilers) written by James Hacker.++ <signature of Ty Coon>, 1 April 1989+ Ty Coon, President of Vice++This General Public License does not permit incorporating your program into+proprietary programs. If your program is a subroutine library, you may+consider it more useful to permit linking proprietary applications with the+library. If this is what you want to do, use the GNU Lesser General+Public License instead of this License.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Version.hs view
@@ -0,0 +1,45 @@+-- --------------------------------------------------------------------------+-- $Revision: 106 $ $Date: 2006-10-13 02:31:06 +0200 (Fri, 13 Oct 2006) $+-- --------------------------------------------------------------------------++-- |+--+-- Module : Version+-- Copyright : Otakar Smrz 2005-2006+-- License : BSD-style+--+-- Maintainer : otakar.smrz mff.cuni.cz+-- Stability : provisional+-- Portability : portable+--+-- Extended support for working with the CVS\/SVN revision keyword. The+-- method 'revised' splits the '$Revision ... $' string supplied to it,+-- lets it parse with 'parseVersion' of "Data.Version", and returns the+-- result of type 'Version' defined therein. The "Data.Version" module+-- is exported, too.+++module Version (++ -- * Modules "Data.Version"++ module Data.Version,++ -- * Functions++ revised++ ) where+++import Data.Version++import Text.ParserCombinators.ReadP+++version = revised "$Revision: 106 $"+++revised :: String -> Version++revised revision = fst . last . readP_to_S parseVersion $ words revision !! 1