Encode 0.7 → 1.1
raw patch · 46 files changed
+7783/−5693 lines, 46 filesdep +mtlsetup-changednew-component:exe:decodenew-component:exe:encode
Dependencies added: mtl
Files
- Encode.cabal +179/−70
- Encode.hs +118/−111
- Encode/Arabic.hs +48/−48
- Encode/Arabic/ArabTeX.hs +1154/−1152
- Encode/Arabic/ArabTeX/ZDMG.hs +782/−774
- Encode/Arabic/Buckwalter.hs +108/−108
- Encode/Arabic/Byte.hs +564/−564
- Encode/ExPlus.hs +191/−0
- Encode/Extend.hs +211/−211
- Encode/Mapper.hs +548/−548
- Encode/Unicode.hs +50/−48
- Encode/Unicode/UTF8.hs +91/−89
- Exec/Decode/Main.hs +153/−0
- Exec/Encode/Main.hs +153/−0
- FunParsing.hs +0/−52
- FunParsing/OrdMap.hs +0/−140
- FunParsing/OrdSet.hs +0/−129
- FunParsing/Parsers.hs +0/−70
- FunParsing/Parsers/AmbExTrie.hs +0/−92
- FunParsing/Parsers/AmbTrie.hs +0/−79
- FunParsing/Parsers/ExTrie.hs +0/−94
- FunParsing/Parsers/PairTrie.hs +0/−113
- FunParsing/Parsers/Parser.hs +0/−170
- FunParsing/Parsers/Standard.hs +0/−77
- FunParsing/Parsers/Stream.hs +0/−88
- FunParsing/Parsers/Trie.hs +0/−85
- INSTALL +51/−47
- LICENSE +674/−339
- LicenseBSD +9/−9
- LicenseGPL +674/−339
- Parsek.hs +561/−0
- PureFP.hs +52/−0
- PureFP/OrdMap.hs +140/−0
- PureFP/OrdSet.hs +129/−0
- PureFP/Parsers.hs +70/−0
- PureFP/Parsers/AmbExTrie.hs +92/−0
- PureFP/Parsers/AmbTrie.hs +79/−0
- PureFP/Parsers/ExTrie.hs +94/−0
- PureFP/Parsers/PairTrie.hs +113/−0
- PureFP/Parsers/Parser.hs +170/−0
- PureFP/Parsers/Standard.hs +86/−0
- PureFP/Parsers/Stream.hs +90/−0
- PureFP/Parsers/Trie.hs +85/−0
- Setup.PL +217/−0
- Setup.hs +2/−2
- Version.hs +45/−45
Encode.cabal view
@@ -1,70 +1,179 @@-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+name: Encode +version: 1.1 +license: GPL +license-file: LICENSE +extra-source-files: INSTALL, LicenseBSD, LicenseGPL, Setup.PL +copyright: 2008 +author: Otakar Smrz +maintainer: otakar.smrz mff.cuni.cz +homepage: http://ufal.mff.cuni.cz/~smrz/ +package-url: http://sourceforge.net/projects/encode-arabic/ +category: Text, Codec +build-depends: Cabal, base, mtl +build-type: Simple +synopsis: Encoding character data +description: The "Encode" library provides a unified interface for + converting strings from different encodings into a common + representation, and vice versa. This representation is + isomorphic to the Unicode character set, and the encodings + can be both standard and user-defined. For this purpose, + the "Encode" module defines the 'Encode.UPoint' data type + and the 'Encode.Encoding' type class with the 'encode' and + 'decode' methods. + . + The "Encode" library is being proposed as a Haskell + analogy to the /Encode/ extension in Perl, + <http://search.cpan.org/dist/Encode/>. + . + The "Exec.Encode.Main" and "Exec.Decode.Main" programs + mimick the fuction calls to 'encode' and 'decode', + respectively, with the following usage of the executables: + . + > decode ArabTeX < decode.d | encode Buckwalter > encode.d + > + > decode MacArabic < data.MacArabic > data.UTF8 + > + > encode WinArabic < data.UTF8 > data.WinArabic + . + The installation instructions are given in "INSTALL". + For the list of supported encoding schemes, please refer + to "Encode" and the source files of the programs. With the + executables, the naming of encodings is /case-insensitive/ + and some further options are allowed: + . + > encode|decode [--OPTIONS] [ENCODING] + > -h --help show usage information + > -l --lines use line-oriented mode + > -p text --prefix=text prefix input with text + > -s text --suffix=text suffix input with text + > -v --version show program's version + . + The "PureFP" 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.ling.gu.se/~peb/software.html>. + . + The "Parsek" library is included for experimental purposes + and subsumes "PureFP.Parsers.Stream". /Parsek/ was developed + by Koen Claessen in his functional pearl article /Parallel + Parsing Processes/, Journal of Functional Programming, + 14(6), 741–757, Cambridge University Press, 2004, + <http://www.cs.chalmers.se/~koen/pubs/entry-jfp04-parser.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" "PureFP" "Parsek" "Version" +exposed-modules: Encode, + Encode.Arabic, + Encode.Arabic.ArabTeX, + Encode.Arabic.ArabTeX.ZDMG, + Encode.Arabic.Buckwalter, + Encode.Arabic.Byte, + Encode.Extend, + Encode.ExPlus, + Encode.Mapper, + Encode.Unicode, + Encode.Unicode.UTF8, + PureFP, + PureFP.OrdMap, + PureFP.OrdSet, + PureFP.Parsers, + PureFP.Parsers.AmbExTrie, + PureFP.Parsers.AmbTrie, + PureFP.Parsers.ExTrie, + PureFP.Parsers.PairTrie, + PureFP.Parsers.Parser, + PureFP.Parsers.Standard, + PureFP.Parsers.Stream, + PureFP.Parsers.Trie, + Parsek, + Version +extensions: MultiParamTypeClasses, + FunctionalDependencies, + ExistentialQuantification, + PolymorphicComponents, + TypeSynonymInstances, + FlexibleInstances, + FlexibleContexts +hugs-options: -98 +o +u -h96M + +executable: encode +main-is: Exec/Encode/Main.hs +other-modules: Encode, + Encode.Arabic, + Encode.Arabic.ArabTeX, + Encode.Arabic.ArabTeX.ZDMG, + Encode.Arabic.Buckwalter, + Encode.Arabic.Byte, + Encode.Extend, + Encode.ExPlus, + Encode.Mapper, + Encode.Unicode, + Encode.Unicode.UTF8, + PureFP, + PureFP.OrdMap, + PureFP.OrdSet, + PureFP.Parsers, + PureFP.Parsers.AmbExTrie, + PureFP.Parsers.AmbTrie, + PureFP.Parsers.ExTrie, + PureFP.Parsers.PairTrie, + PureFP.Parsers.Parser, + PureFP.Parsers.Standard, + PureFP.Parsers.Stream, + PureFP.Parsers.Trie, + Parsek, + Version +extensions: MultiParamTypeClasses, + FunctionalDependencies, + ExistentialQuantification, + PolymorphicComponents, + TypeSynonymInstances, + FlexibleInstances, + FlexibleContexts +hugs-options: -98 +o +u -h96M + +executable: decode +main-is: Exec/Decode/Main.hs +other-modules: Encode, + Encode.Arabic, + Encode.Arabic.ArabTeX, + Encode.Arabic.ArabTeX.ZDMG, + Encode.Arabic.Buckwalter, + Encode.Arabic.Byte, + Encode.Extend, + Encode.ExPlus, + Encode.Mapper, + Encode.Unicode, + Encode.Unicode.UTF8, + PureFP, + PureFP.OrdMap, + PureFP.OrdSet, + PureFP.Parsers, + PureFP.Parsers.AmbExTrie, + PureFP.Parsers.AmbTrie, + PureFP.Parsers.ExTrie, + PureFP.Parsers.PairTrie, + PureFP.Parsers.Parser, + PureFP.Parsers.Standard, + PureFP.Parsers.Stream, + PureFP.Parsers.Trie, + Parsek, + Version +extensions: MultiParamTypeClasses, + FunctionalDependencies, + ExistentialQuantification, + PolymorphicComponents, + TypeSynonymInstances, + FlexibleInstances, + FlexibleContexts +hugs-options: -98 +o +u -h96M
Encode.hs view
@@ -1,111 +1,118 @@--- ----------------------------------------------------------------------------- $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+-- -------------------------------------------------------------------------- +-- $Revision: 548 $ $Date: 2008-05-06 01:23:06 +0200 (Tue, 06 May 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode +-- Copyright : Otakar Smrz 2005-2008 +-- 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, CSpace, + + -- * Methods + + encode, decode + + ) where + + +import Data.Word + +import Version + +version = revised "$Revision: 548 $" + + +-- | The datatype introduced for the internal representation of Unicode code +-- points is currently defined as @newtype 'UPoint' = UPoint CSpace@. 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 CSpace + + deriving (Eq, Ord) + + +-- | The 'CSpace' type denotes the code space, and it is a synonym to 'Word'. + +type CSpace = Word + + +-- | 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 "PureFP" 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 (fromIntegral x) :: Char) + | otherwise = showsPrec p ("&#" ++ showsPrec p x ";") + + +instance Enum UPoint where + + fromEnum (UPoint x) = fromIntegral x + + toEnum x = UPoint (fromIntegral x)
Encode/Arabic.hs view
@@ -1,48 +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 $"+-- -------------------------------------------------------------------------- +-- $Revision: 542 $ $Date: 2008-04-25 23:34:45 +0200 (Fri, 25 Apr 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Arabic +-- Copyright : Otakar Smrz 2005-2008 +-- 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: 542 $"
Encode/Arabic/ArabTeX.hs view
@@ -1,1152 +1,1154 @@--- ----------------------------------------------------------------------------- $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 ] )- ]+-- -------------------------------------------------------------------------- +-- $Revision: 582 $ $Date: 2008-06-20 00:41:41 +0200 (Fri, 20 Jun 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Arabic.ArabTeX +-- Copyright : Otakar Smrz 2005-2008 +-- 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 PureFP.OrdMap + +import Version + +version = revised "$Revision: 582 $" + + +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 = Nodiacritics | 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 > Nodiacritics 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 + <|> parseDefinite + + <|> 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 Nodiacritics q : r + "noneplus" -> setMode Nodiacritics q : r + "nodiacritics" -> setMode Nodiacritics 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 + + "'y" -> "'y" + "'w" -> "'w" + "'A" -> "'A" + "'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 + "'i" -> "'|" + "'|" -> "'|" + "'y" -> "'y" + _ -> "'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" + + "aNA" -> "'N" + + _ -> "'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 [sunny, moony, bound, taaaa, invis, silent] + x <- upper [c] [sunny, moony, bound, taaaa, invis, silent] + parseSyllVowel c x + + +parseDoubleCons = + do c <- oneof [sunny, moony, bound, taaaa, invis, silent] + lower [c] [] + x <- upper [c] [sunny, moony, bound, taaaa, invis, silent] + y <- upperWith shaddaControl + ["*"] [shadda] + parseSyllVowel c (x `plus` y) + + +parseHyphen = + do lower ["-"] [] + resetEnv setEarly [] + parseNothing + + +parseDefinite = + do c <- oneof [sunny, moony, bound] -- [sunny] + lower ["-", c] [c, c] + upper ["l"] [sunny] + + {- + do c <- oneof [sunny, moony, bound] + lower ["-", c] + x <- upper ["l", c] [sunny, moony, bound] + 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 = rulePunctuation + + |+| ruleVerbalSilentAlif + |+| ruleMaqsuuraWithAlif + |+| ruleInternalTaaaa + |+| ruleInternalYaaaa + + |+| ruleLiWithDefinite + |+| ruleDefinite + |+| ruleIndefinite + + |+| ruleMultiVowel + |+| ruleHyphenedVowel + + |+| ruleWhitePlusControl + |+| ruleIgnoreCapControl + |+| ruleControlSequence + + +rulePunctuation = + + "-" |.| ["-"] |+| + "\"" |.| ["\\\""] |+| + "\\\"" |.| ["\""] + + +ruleVerbalSilentAlif = + + "aWA" |-| "awW" |:| [] |+| + "aW" |-| "awW" |:| [] |+| + "UA" |-| "UW" |:| [] |+| + "uW" |-| "UW" |:| [] + + +ruleMaqsuuraWithAlif = + + "yY" |-| "yA" |:| [] |+| + "yaNY" |-| "yaN" |:| [] |+| + + "aN_A" |-| "aNY" |:| [] |+| + "iN_A" |-| "iNY" |:| [] |+| + "uN_A" |-| "uNY" |:| [] |+| + + "y_A" |-| "yY" |:| [] |+| + "yaN_A" |-| "yaNY" |:| [] |+| + + "_A" |-| "Y" |:| [] + + +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 <-> "") + -} + + +ruleLiWithDefinite = + + 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] ] + -} + + +ruleDefinite = + + anyof [ + "l" ++ "-" ++ c ++ c |-| + "-" ++ c |:| [c] + + | c <- elems [sunny, moony] ] + + +ruleIndefinite = + + 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], + v <- elems [vowel, nuuns] ++ + quote [vowel, nuuns, sukun] ] + + +ruleInternalYaaaa = + + anyof [ + "Y" ++ c |-| "A" ++ c |:| [] + + | c <- elems [sunny, moony, invis, taaaa] ] + + +-- -------------------------------------------------------------------------- +-- 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], [CSpace])] -> LowerUp + +define l = makeMapWith const [ (x, map (toEnum . fromIntegral) 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
@@ -1,774 +1,782 @@--- ----------------------------------------------------------------------------- $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 ] )- ]+-- -------------------------------------------------------------------------- +-- $Revision: 667 $ $Date: 2008-08-12 15:36:28 +0200 (Tue, 12 Aug 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Arabic.ArabTeX.ZDMG +-- Copyright : Otakar Smrz 2005-2008 +-- 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 PureFP.OrdMap + +import Version + +version = revised "$Revision: 667 $" + + +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 = Nodiacritics | 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 > Nodiacritics 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 Nodiacritics q : r + "noneplus" -> setMode Nodiacritics q : r + "nodiacritics" -> setMode Nodiacritics q : r + + "setverb" -> setVerb True q : r + "setarab" -> setVerb False q : r + + _ -> error "Weird control sequence" + + returnEList envList + parseNothing + + +parseInitVowel = + do v <- oneof [define [("i", []), ("u", [])]] + c <- oneof [define [("w", []), ("y", [])]] + e <- inspectEnv + if envCap e || not (envWasla e) + then do lower [] [if v == "i" then "I" else "U"] + parseNothing + else do lower [] [c] + y <- upperWith (vowelControl "W") + [v] [vowel] + completeSyllable y + <|> + do v <- oneof [vowel] + 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 [sunny, moony, extra, invis] + x <- upperWith consControl + [c] [sunny, moony, extra, invis] + resetEnv setCap False + parseSyllVowel c x + <|> + do c <- oneof [minor] + x <- upper [c] [minor] + parseSyllVowel c x + + +parseDoubleCons = + do c <- oneof [sunny, moony, extra, invis] + lower [c] [] + x <- upperWith consControl + [c] [sunny, moony, extra, invis] + resetEnv setCap False + y <- upperWith shaddaControl + [c] [sunny, moony, 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 + +-- |+| ruleLiWithDefinite + |+| ruleDefinite + |+| ruleIndefinite + + |+| ruleMultiVowel + |+| ruleHyphenedVowel + + |+| ruleWhitePlusControl + |+| ruleIgnoreCapControl + |+| ruleControlSequence + + |+| rulePunctuation + + +rulePunctuation = + + "-" |.| ["-"] |+| + "\"" |.| ["\\\""] |+| + "\\\"" |.| ["\""] + + +ruleVerbalSilentAlif = + + "aWA" |-| "aw" |:| [] |+| + "aW" |-| "aw" |:| [] |+| + "UA" |-| "U" |:| [] |+| + "uW" |-| "uw" |:| [] + + +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, minor] ] + + +ruleControlSequence = + + do x <- sym '\\' <:> + some (anySymbol (['A'..'Z'] ++ ['a'..'z'])) + many whites + return ([], [x]) + + +ruleLiWithDefinite = + + anyof [ + "l" ++ v ++ "-a" ++ c ++ "-" ++ c |-| + "l" ++ v ++ c ++ "-" ++ c |:| [] + + | c <- elems [sunny, moony, minor], 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, minor], c == "l", + v <- elems [vowel, sukun] ++ quote [vowel, sukun] ] + + +ruleDefinite = + + anyof [ + "l" ++ "-" ++ c ++ c |-| + "-" ++ c |:| [c] + + | c <- elems [sunny, moony, minor] ] + + +ruleIndefinite = + + "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, minor, 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], [CSpace])] -> LowerUp + +define l = makeMapWith const [ (x, map (toEnum . fromIntegral) y) | + (x, y) <- l ] + + +consonant :: LowerUp +consonant = unionMap [sunny, moony, minor] + + +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 ] ), + -- ( "aa", [ 0x0061, 0x0061 ] ), + ( "_a", [ 0x0061, 0x0304 ] ), + ( "_aA", [ 0x0061, 0x0304 ] ), + ( "_aY", [ 0x0061, 0x0304 ] ), + ( "_aU", [ 0x0061, 0x0304 ] ), + ( "_aI", [ 0x0061, 0x0304 ] ), + ( "A", [ 0x0061, 0x0304 ] ), + ( "^A", [ 0x0061, 0x0304 ] ), + ( "e", [ 0x0065 ] ), + -- ( "ee", [ 0x0065, 0x0065 ] ), + ( "E", [ 0x0065, 0x0304 ] ), + ( "i", [ 0x0069 ] ), + -- ( "ii", [ 0x0069, 0x0069 ] ), + ( "_i", [ 0x0069, 0x0304 ] ), + ( "I", [ 0x0069, 0x0304 ] ), + ( "^I", [ 0x0069, 0x0304 ] ), + ( "_I", [ 0x0069 ] ), + ( "o", [ 0x006F ] ), + -- ( "oo", [ 0x006F, 0x006F ] ), + ( "O", [ 0x006F, 0x0304 ] ), + ( "u", [ 0x0075 ] ), + -- ( "uu", [ 0x0075, 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
@@ -1,108 +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"-- )+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Arabic.Buckwalter +-- Copyright : Otakar Smrz 2005-2007 +-- 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 PureFP.OrdMap + +--import Data.Map (Map) +--import qualified Data.Map as Map + +import Version + +version = revised "$Revision: 262 $" + + +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
@@ -1,564 +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]---}+-- -------------------------------------------------------------------------- +-- $Revision: 728 $ $Date: 2008-10-16 00:11:37 +0200 (Thu, 16 Oct 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Arabic.Byte +-- Copyright : Otakar Smrz 2005-2007 +-- 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 PureFP.OrdMap + +--import Data.Map (Map) +--import qualified Data.Map as Map + +import Version + +version = revised "$Revision: 728 $" + + +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/ExPlus.hs view
@@ -0,0 +1,191 @@+-- -------------------------------------------------------------------------- +-- $Revision: 455 $ $Date: 2007-12-14 20:22:04 +0100 (Fri, 14 Dec 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.ExPlus +-- Copyright : Otakar Smrz 2005-2007 +-- License : GPL +-- +-- Maintainer : otakar.smrz mff.cuni.cz +-- Stability : provisional +-- Portability : portable +-- +-- "Encode.Extend" + + +module Encode.ExPlus ( + + -- * Modules + + module PureFP.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 PureFP.OrdMap +import PureFP.Parsers.Parser +import PureFP.Parsers.Standard + +import Control.Monad +import Control.Monad.State +import Control.Monad.Trans + +import Version + +version = revised "$Revision: 455 $" + + +class ExtEnv e where + + initEnv :: e i + + +type Extend e s = StateT [e s] (Standard s) + +-- 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 = lift get + -- Ext (\ (i, e) -> [((i, e), i)]) + +returnIList :: [s] -> Extend e s [s] +returnIList i = lift (put i >> return i) + -- Ext (\ (_, e) -> [((i, e), i)]) + +inspectEList :: Extend e s [e s] +inspectEList = get + -- Ext (\ (i, e) -> [((i, e), e)]) + +returnEList :: [e s] -> Extend e s [e s] +returnEList e = put e >> return e + -- Ext (\ (i, _) -> [((i, e), e)]) + +inspectEnv :: Extend e s (e s) +inspectEnv = gets head + -- get >>= return . head + -- do x <- get; return (head x) + +resetEnv :: (a -> e s -> e s) -> a -> Extend e s (e s) +resetEnv f v = modify (\(e : q) -> f v e : q) >> gets head + + +infixr 2 <|> + +(<|>) :: Extend e s a -> Extend e s a -> Extend e s a + +(<|>) p q = StateT (\s -> Std (\inp -> let Std pp = runStateT p s + r = pp inp + Std qq = runStateT q s + t = qq inp + + takeOne (x:_) = [x] + takeOne [] = [] + + in case r of [] -> takeOne t + _ -> takeOne 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 = lift (syms s >> modify (c ++) >> get) + +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 = lift zero + p <+> q = StateT (\s -> runStateT p s <+> runStateT q s) + + +instance Sequence (Extend e s) + + +instance Eq s => Symbol (Extend e s) s where + sat p = lift (sat p) + +{- +instance Eq s => SymbolCont (Extend e s) s where + satCont p fut = lift (satCont p fut) +{- + 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 p = parse (evalStateT p [initEnv]) + parseFull p = parseFull (evalStateT p [initEnv]) + +{- +instance Lookahead (Extend e s) s where + lookahead f = Ext (\ (inp, e) -> let Ext p = f inp in p (inp, e)) +-}
Encode/Extend.hs view
@@ -1,211 +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]) ]+-- -------------------------------------------------------------------------- +-- $Revision: 291 $ $Date: 2007-04-26 19:17:16 +0200 (Thu, 26 Apr 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 PureFP.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 PureFP.OrdMap +import PureFP.Parsers.Parser + +import Control.Monad + +import Version + +version = revised "$Revision: 291 $" + + +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 -> let Ext pp = p + r = pp cs + Ext qq = q + t = qq cs + + takeOne (x:_) = [x] + takeOne [] = [] + + in case r of [] -> takeOne t + _ -> takeOne r ) + +{- +(<|>) p q = Ext (\ cs -> case r cs of [] -> []; (x:xs) -> [x]) + where Ext r = p <+> q +-} + + +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
@@ -1,548 +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)+-- -------------------------------------------------------------------------- +-- $Revision: 264 $ $Date: 2007-04-13 18:24:56 +0200 (Fri, 13 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Mapper +-- Copyright : Otakar Smrz 2005-2007 +-- 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 PureFP.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 PureFP.OrdMap +--import Data.Map (Map) +--import qualified Data.Map as Map + +import PureFP.Parsers.Parser + +import Version + +version = revised "$Revision: 264 $" + +{- +(?) 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 (FMap g p) = unfoldWith (f . g) p +unfoldWith f (Node as pmap) = Node (map f as) (mapMap (FMap f) pmap) + + +unfoldTrie :: Ord s => Mapper s a -> Mapper s a +unfoldTrie (FMap g p) = unfoldWith g p +unfoldTrie node = node + + +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
@@ -1,48 +1,50 @@--- ----------------------------------------------------------------------------- $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+-- -------------------------------------------------------------------------- +-- $Revision: 542 $ $Date: 2008-04-25 23:34:45 +0200 (Fri, 25 Apr 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Unicode +-- Copyright : Otakar Smrz 2005-2008 +-- 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, + + module Encode, + + -- * Types + + Unicode (..) + + ) where + + +import Encode + +import Encode.Unicode.UTF8 + +import Version + +version = revised "$Revision: 542 $" + + +data Unicode = Unicode | UCS + + deriving (Enum, Show) + + +instance Encoding Unicode
Encode/Unicode/UTF8.hs view
@@ -1,89 +1,91 @@--- ----------------------------------------------------------------------------- $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)+-- -------------------------------------------------------------------------- +-- $Revision: 549 $ $Date: 2008-05-06 12:32:16 +0200 (Tue, 06 May 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Encode.Unicode.UTF8 +-- Copyright : Otakar Smrz 2005-2008 +-- 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: 549 $" + + +data UTF8 = UTF8 | UTF + + deriving (Enum, Show) + + +instance Encoding UTF8 where + + encode _ = map (toEnum . fromIntegral) . codespaceUTF . + map (fromIntegral . fromEnum) + + decode _ = map (toEnum . fromIntegral) . codespaceUCS . + map (fromIntegral . fromEnum) + + +-- http://repetae.net/john/repos/jhc/UTF8.hs +-- rewritten by Otakar Smrz +-- +-- toUTF :: String -> [Word8] +-- toUTF = map fromIntegral . codespaceUTF . map fromEnum +-- +-- fromUTF :: [Word8] -> String +-- fromUTF = map toEnum . codespaceUCS . map fromIntegral + + +codespaceUTF :: [CSpace] -> [CSpace] +codespaceUTF [] = [] +codespaceUTF (x:xs) + | x <= 0x007F = x : codespaceUTF xs + | x <= 0x07FF = (0xC0 .|. ((x `shift` (-6)) .&. 0x1F)) + : (0x80 .|. (x .&. 0x3F)) + : codespaceUTF xs + | otherwise = (0xE0 .|. ((x `shift` (-12)) .&. 0x0F)) + : (0x80 .|. ((x `shift` (-6)) .&. 0x3F)) + : (0x80 .|. (x .&. 0x3F)) + : codespaceUTF xs + + +codespaceUCS :: [CSpace] -> [CSpace] +codespaceUCS [] = [] +codespaceUCS (x:xs) + | x <= 0x7F = x : codespaceUCS xs + | x <= 0xBF = error ("codespaceUCS: illegal character byte " ++ show x) + | x <= 0xDF = doubleByte x xs + | x <= 0xEF = tripleByte x xs + | otherwise = error ("codespaceUCS: illegal character byte " ++ show x) + +doubleByte x1 (x2:xs) = (((x1 .&. 0x1F) `shift` 6) + .|. (x2 .&. 0x3F)) + : codespaceUCS xs +doubleByte x _ = error ("codespaceUCS: illegal 2-byte sequence " ++ show x) + +tripleByte x1 (x2:x3:xs) = (((x1 .&. 0x0F) `shift` 12) + .|. ((x2 .&. 0x3F) `shift` 6) + .|. (x3 .&. 0x3F)) + : codespaceUCS xs +tripleByte x _ = error ("codespaceUCS: illegal 3-byte sequence " ++ show x)
+ Exec/Decode/Main.hs view
@@ -0,0 +1,153 @@+-- -------------------------------------------------------------------------- +-- $Revision: 747 $ $Date: 2008-11-07 22:53:30 +0100 (Fri, 07 Nov 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Exec.Decode.Main +-- Copyright : Otakar Smrz 2005-2008 +-- License : GPL +-- +-- Maintainer : otakar.smrz mff.cuni.cz +-- Stability : provisional +-- Portability : portable +-- +-- "Encode.Arabic" "Encode.Mapper" "Encode.Unicode" + + +module Main where + +import Encode +import Encode.Arabic +import Encode.Unicode + +import System.Environment +import System.Console.GetOpt +import System.IO + +import Data.Char +import Data.List +import Data.Version (showVersion) + +import Version + +version = Version [1, 1, build] [] + + where Version [build] [] = revised "$Revision: 747 $" + + +data Opts = DisplayUsage | PrintVersion | LineOriented | + + Prefix String | Suffix String + + deriving (Eq, Ord) + + +options :: [OptDescr Opts] + +options = [ Option ['h'] ["help"] (NoArg DisplayUsage) + "show usage information", + + Option ['l'] ["lines"] (NoArg LineOriented) + "use line-oriented mode", + + Option ['p'] ["prefix"] (ReqArg Prefix "text") + "prefix input with text", + + Option ['s'] ["suffix"] (ReqArg Suffix "text") + "suffix input with text", + + Option ['v'] ["version"] (NoArg PrintVersion) + "show program's version" ] + + +copyleft = unlines ["Encode Arabic (C) 2008-2005 Otakar Smrz", + "GNU General Public License http://www.gnu.org/licenses/"] + +synopsis = unlines [copyleft, + " http://sourceforge.net/projects/encode-arabic/", + " http://quest.ms.mff.cuni.cz/encode/", + " <otakar.smrz mff.cuni.cz>", + "", + "decode [--OPTIONS] [ENCODING]"] + + +main = do argv <- getArgs + + let (opts, nons, errs) = getOpt Permute options argv + + if null errs then case (sort . nub) opts of + + DisplayUsage : _ -> warn (usageInfo synopsis options) + PrintVersion : _ -> warn (unlines [copyleft, + unwords ["Encode Arabic", + showVersion Main.version, + "November 2008"]]) + LineOriented : _ -> execute True (tail opts) nons + _ -> execute False opts nons + + else warn (usageInfo synopsis options) + + +warn = hPutStr stderr + + +execute l opts nons = case opts of + + [Prefix p] -> interactPlus l e (p ++) + [Prefix p, Suffix s] + -> interactPlus l e ((p ++) . (++ s)) + [Suffix s] -> interactPlus l e (++ s) + _ -> interactPlus l e id + + where e = case nons of [] -> "" + _ -> head nons + + +interactPlus :: Bool -> String -> (String -> String) -> IO () + +interactPlus l e f = interact (if l then unlines . map encodes . lines + else encodes) + + where encodes = encode UTF . decodes . f + + decodes = case map toLower e of + + "arabtex" -> decode ArabTeX + "lagally" -> decode Lagally + "tex" -> decode TeX + + "zdmg" -> decode ZDMG + "arabtex_zdmg" -> decode ArabTeX_ZDMG + "arabtex-zdmg" -> decode ArabTeX_ZDMG + + "buckwalter" -> decode Buckwalter + "tim" -> decode Tim + + "winarabic" -> decode WinArabic + "cp1256" -> decode CP1256 + "windows_1256" -> decode Windows_1256 + "windows-1256" -> decode Windows_1256 + + "isoarabic" -> decode ISOArabic + "iso_8859_6" -> decode ISO_8859_6 + "iso-8859-6" -> decode ISO_8859_6 + + "macarabic" -> decode MacArabic + + "macfarsi" -> decode MacFarsi + + "dosarabic" -> decode DOSArabic + "cp864" -> decode CP864 + + "dosfarsi" -> decode DOSFarsi + "cp1006" -> decode CP1006 + + "asmo449" -> decode ASMO449 + + "isiri3342" -> decode ISIRI3342 + + "utf8" -> decode UTF8 + "utf" -> decode UTF + + _ -> decode Unicode
+ Exec/Encode/Main.hs view
@@ -0,0 +1,153 @@+-- -------------------------------------------------------------------------- +-- $Revision: 747 $ $Date: 2008-11-07 22:53:30 +0100 (Fri, 07 Nov 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Exec.Encode.Main +-- Copyright : Otakar Smrz 2005-2008 +-- License : GPL +-- +-- Maintainer : otakar.smrz mff.cuni.cz +-- Stability : provisional +-- Portability : portable +-- +-- "Encode.Arabic" "Encode.Mapper" "Encode.Unicode" + + +module Main where + +import Encode +import Encode.Arabic +import Encode.Unicode + +import System.Environment +import System.Console.GetOpt +import System.IO + +import Data.Char +import Data.List +import Data.Version (showVersion) + +import Version + +version = Version [1, 1, build] [] + + where Version [build] [] = revised "$Revision: 747 $" + + +data Opts = DisplayUsage | PrintVersion | LineOriented | + + Prefix String | Suffix String + + deriving (Eq, Ord) + + +options :: [OptDescr Opts] + +options = [ Option ['h'] ["help"] (NoArg DisplayUsage) + "show usage information", + + Option ['l'] ["lines"] (NoArg LineOriented) + "use line-oriented mode", + + Option ['p'] ["prefix"] (ReqArg Prefix "text") + "prefix input with text", + + Option ['s'] ["suffix"] (ReqArg Suffix "text") + "suffix input with text", + + Option ['v'] ["version"] (NoArg PrintVersion) + "show program's version" ] + + +copyleft = unlines ["Encode Arabic (C) 2008-2005 Otakar Smrz", + "GNU General Public License http://www.gnu.org/licenses/"] + +synopsis = unlines [copyleft, + " http://sourceforge.net/projects/encode-arabic/", + " http://quest.ms.mff.cuni.cz/encode/", + " <otakar.smrz mff.cuni.cz>", + "", + "encode [--OPTIONS] [ENCODING]"] + + +main = do argv <- getArgs + + let (opts, nons, errs) = getOpt Permute options argv + + if null errs then case (sort . nub) opts of + + DisplayUsage : _ -> warn (usageInfo synopsis options) + PrintVersion : _ -> warn (unlines [copyleft, + unwords ["Encode Arabic", + showVersion Main.version, + "November 2008"]]) + LineOriented : _ -> execute True (tail opts) nons + _ -> execute False opts nons + + else warn (usageInfo synopsis options) + + +warn = hPutStr stderr + + +execute l opts nons = case opts of + + [Prefix p] -> interactPlus l e (p ++) + [Prefix p, Suffix s] + -> interactPlus l e ((p ++) . (++ s)) + [Suffix s] -> interactPlus l e (++ s) + _ -> interactPlus l e id + + where e = case nons of [] -> "" + _ -> head nons + + +interactPlus :: Bool -> String -> (String -> String) -> IO () + +interactPlus l e f = interact (if l then unlines . map decodes . lines + else decodes) + + where decodes = encodes . decode UTF . f + + encodes = case map toLower e of + + "arabtex" -> encode ArabTeX + "lagally" -> encode Lagally + "tex" -> encode TeX + + "zdmg" -> encode ZDMG + "arabtex_zdmg" -> encode ArabTeX_ZDMG + "arabtex-zdmg" -> encode ArabTeX_ZDMG + + "buckwalter" -> encode Buckwalter + "tim" -> encode Tim + + "winarabic" -> encode WinArabic + "cp1256" -> encode CP1256 + "windows_1256" -> encode Windows_1256 + "windows-1256" -> encode Windows_1256 + + "isoarabic" -> encode ISOArabic + "iso_8859_6" -> encode ISO_8859_6 + "iso-8859-6" -> encode ISO_8859_6 + + "macarabic" -> encode MacArabic + + "macfarsi" -> encode MacFarsi + + "dosarabic" -> encode DOSArabic + "cp864" -> encode CP864 + + "dosfarsi" -> encode DOSFarsi + "cp1006" -> encode CP1006 + + "asmo449" -> encode ASMO449 + + "isiri3342" -> encode ISIRI3342 + + "utf8" -> encode UTF8 + "utf" -> encode UTF + + _ -> encode Unicode
− FunParsing.hs
@@ -1,52 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,140 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,129 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,70 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,92 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,79 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,94 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,113 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,170 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,77 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,88 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,85 +0,0 @@--- ----------------------------------------------------------------------------- $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
@@ -1,47 +1,51 @@-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! ^^+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 haddock + runhaskell Setup.hs install + + 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 haddock + :main install + + If you have Perl installed, you can simply run Setup.PL to do everything: + + perl Setup.PL + + +In case you need more help, please consult the Cabal documentation website. + + http://www.haskell.org/cabal/release/latest/doc/users-guide/builders.html + http://www.haskell.org/cabal/release/latest/doc/users-guide/ + + +Enjoy! ^^
LICENSE view
@@ -1,339 +1,674 @@- 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.+ GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state 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 3 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, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU 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. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
LicenseBSD view
@@ -1,9 +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.+Copyright 2005-2007 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
@@ -1,339 +1,674 @@- 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.+ GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. 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 +them 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 prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. 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. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey 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; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +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. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + 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 +state 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 3 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, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program 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, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU 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. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+ Parsek.hs view
@@ -0,0 +1,561 @@+-- -------------------------------------------------------------------------- +-- $Revision: 531 $ $Date: 2008-04-11 00:55:45 +0200 (Fri, 11 Apr 2008) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : Parsek +-- Copyright : Koen Claessen 2003 +-- License : GPL +-- +-- Maintainer : otakar.smrz mff.cuni.cz +-- Stability : provisional +-- Portability : portable +-- +-- This module provides the /Parsek/ library developed by Koen Claessen in his +-- functional pearl article /Parallel Parsing Processes/, Journal of Functional +-- Programming, 14(6), 741–757, Cambridge University Press, 2004: +-- +-- <http://www.cs.chalmers.se/~koen/pubs/entry-jfp04-parser.html> +-- +-- <http://www.cs.chalmers.se/Cs/Grundutb/Kurser/afp/> +-- +-- <http://www.cs.chalmers.se/Cs/Grundutb/Kurser/afp/code/week3/Parsek.hs> +-- +-- +-- Copyright (C) 2003 Koen Claessen +-- +-- 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. +-- +-- +-- "PureFP.Parsers.Stream" + +------------------------------------------------------------------ +-- Parsek, a Parser Combinator Library -- +-- Copyright (c) 2003 Koen Claessen -- +-- koen@cs.chalmers.se -- +-- -- +-- This file is part of Parsek. -- +-- -- +-- Parsek 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. -- +-- -- +-- Parsek 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 Parsek; if not, write to the Free -- +-- Software Foundation, Inc., 59 Temple Place, Suite 330, -- +-- Boston, MA 02111-1307 USA. -- +------------------------------------------------------------------ + +module Parsek + -- basic parser type + ( Parser -- :: * -> * -> *; Functor, Monad, MonadPlus + , Expect -- :: *; = [String] + , Unexpect -- :: *; = [String] + + -- parsers + , satisfy -- :: Show s => (s -> Bool) -> Parser s s + , look -- :: Parser s [s] + , succeeds -- :: Parser s a -> Parser s (Maybe a) + , string -- :: (Eq s, Show s) => [s] -> Parser s [s] + + , char -- :: Eq s => s -> Parser s s + , noneOf -- :: Eq s => [s] -> Parser s s + , oneOf -- :: Eq s => [s] -> Parser s s + + , spaces -- :: Parser Char () + , space -- :: Parser Char Char + , newline -- :: Parser Char Char + , tab -- :: Parser Char Char + , upper -- :: Parser Char Char + , lower -- :: Parser Char Char + , alphaNum -- :: Parser Char Char + , letter -- :: Parser Char Char + , digit -- :: Parser Char Char + , hexDigit -- :: Parser Char Char + , octDigit -- :: Parser Char Char + , anyChar -- :: Parser s s + , anySymbol -- :: Parser s s + , munch, munch1 -- :: (s -> Bool) -> Parser s [s] + + -- parser combinators + , label -- :: String -> Parser s a -> Parser s a + , (<?>) -- :: Parser s a -> String -> Parser s a + , pzero -- :: Parser s a + , (<|>) -- :: Parser s a -> Parser s a -> Parser s a + , (<<|>) -- :: Parser s a -> Parser s a -> Parser s a + , try -- :: Parser s a -> Parser s a; = id + , choice -- :: [Parser s a] -> Parser s a + , option -- :: a -> Parser s a -> Parser s a + , optional -- :: Parser s a -> Parser s () + , between -- :: Parser s open -> Parser s close -> Parser s a -> Parser s a + , count -- :: Int -> Parser s a -> Parser s [a] + + , chainl1 -- :: Parser s a -> Parser s (a -> a -> a) -> Parser s a + , chainl -- :: Parser s a -> Parser s (a -> a -> a) -> a -> Parser s a + , chainr1 -- :: Parser s a -> Parser s (a -> a -> a) -> Parser s a + , chainr -- :: Parser s a -> Parser s (a -> a -> a) -> a -> Parser s a + + , skipMany1 -- :: Parser s a -> Parser s () + , skipMany -- :: Parser s a -> Parser s () + , many1 -- :: Parser s a -> Parser s [a] + , many -- :: Parser s a -> Parser s [a] + , sepBy1 -- :: Parser s a -> Parser s sep -> Parser s [a] + , sepBy -- :: Parser s a -> Parser s sep -> Parser s [a] + + -- parsing & parse methods + , ParseMethod -- :: * -> * -> * -> * -> * + , ParseResult -- :: * -> * -> *; = Either (e, Expect, Unexpect) r + , parseFromFile -- :: Parser Char a -> ParseMethod Char a e r -> FilePath -> IO (ParseResult e r) + , parse -- :: Parser s a -> ParseMethod s a e r -> [s] -> ParseResult e r + + , shortestResult -- :: ParseMethod s a (Maybe s) a + , longestResult -- :: ParseMethod s a (Maybe s) a + , longestResults -- :: ParseMethod s a (Maybe s) [a] + , allResults -- :: ParseMethod s a (Maybe s) [a] + , allResultsStaged -- :: ParseMethod s a (Maybe s) [[a]] + , completeResults -- :: ParseMethod s a (Maybe s) [a] + + , shortestResultWithLeftover -- :: ParseMethod s a (Maybe s) (a,[s]) + , longestResultWithLeftover -- :: ParseMethod s a (Maybe s) (a,[s]) + , longestResultsWithLeftover -- :: ParseMethod s a (Maybe s) ([a],[s]) + , allResultsWithLeftover -- :: ParseMethod s a (Maybe s) [(a,[s])] + + , completeResultsWithLine -- :: ParseMethod Char a Int [a] + ) + where + +import Control.Monad + ( MonadPlus(..) + , guard + ) + +import Data.List + ( union + , intersperse + ) + +import Data.Char + +infix 0 <?> +infixr 1 <|>, <<|> + +------------------------------------------------------------------------- +-- type Parser + +newtype Parser s a + = Parser (forall res . (a -> Expect -> P s res) -> Expect -> P s res) + +-- type P; parsing processes + +data P s res + = Symbol (s -> P s res) + | Look ([s] -> P s res) + | Fail Expect Unexpect + | Result res (P s res) + +-- type Expect, Unexpect + +type Expect + = [String] + +type Unexpect + = [String] + +------------------------------------------------------------------------- +-- instances: Functor, Monad, MonadPlus + +instance Functor (Parser s) where + fmap p (Parser f) = + Parser (\fut -> f (fut . p)) + +instance Monad (Parser s) where + return a = + Parser (\fut -> fut a) + + Parser f >>= k = + Parser (\fut -> f (\a -> let Parser g = k a in g fut)) + + fail s = + Parser (\fut exp -> Fail exp [s]) + +instance MonadPlus (Parser s) where + mzero = + Parser (\fut exp -> Fail exp []) + + mplus (Parser f) (Parser g) = + Parser (\fut exp -> f fut exp `plus` g fut exp) + +plus :: P s res -> P s res -> P s res +Symbol fut1 `plus` Symbol fut2 = Symbol (\s -> fut1 s `plus` fut2 s) +Fail exp1 err1 `plus` Fail exp2 err2 = Fail (exp1 `union` exp2) (err1 `union` err2) +p `plus` Result res q = Result res (p `plus` q) +Result res p `plus` q = Result res (p `plus` q) +Look fut1 `plus` Look fut2 = Look (\s -> fut1 s `plus` fut2 s) +Look fut1 `plus` q = Look (\s -> fut1 s `plus` q) +p `plus` Look fut2 = Look (\s -> p `plus` fut2 s) +p@(Symbol _) `plus` _ = p +_ `plus` q@(Symbol _) = q + +------------------------------------------------------------------------- +-- primitive parsers + +anySymbol :: Parser s s +anySymbol = + Parser (\fut exp -> Symbol (\c -> + fut c [] + )) + +satisfy :: Show s => (s -> Bool) -> Parser s s +satisfy pred = + Parser (\fut exp -> Symbol (\c -> + if pred c + then fut c [] + else Fail exp [show [c]] + )) + +label :: Parser s a -> String -> Parser s a +label (Parser f) s = + Parser (\fut exp -> + if null exp + then f (\a _ -> fut a []) [s] + else f fut exp + ) + +look :: Parser s [s] +look = + Parser (\fut exp -> + Look (\s -> fut s exp) + ) + +succeeds :: Parser s a -> Parser s (Maybe a) +succeeds (Parser f) = + Parser (\fut exp -> + Look (\xs -> + let sim (Symbol f) q (x:xs) = sim (f x) (\k -> Symbol (\_ -> q k)) xs + sim (Look f) q xs = sim (f xs) q xs + sim p@(Result _ _) q xs = q (cont p) + sim _ _ _ = fut Nothing [] + + cont (Symbol f) = Symbol (\x -> cont (f x)) + cont (Look f) = Look (\s -> cont (f s)) + cont (Result a p) = fut (Just a) [] `plus` cont p + cont (Fail exp unexp) = Fail exp unexp + + in sim (f (\a _ -> Result a (Fail [] [])) exp) id xs + ) + ) + +-- specialized + +string :: (Eq s, Show s) => [s] -> Parser s [s] +string s = + Parser (\fut exp -> + let inputs [] = fut s [] + inputs (x:xs) = + Symbol (\c -> + if c == x + then inputs xs + else Fail (if null exp then [show s] else exp) [show [c]] + ) + + in inputs s + ) + +------------------------------------------------------------------------- +-- derived parsers + +char c = satisfy (==c) <?> show [c] +noneOf cs = satisfy (\c -> not (c `elem` cs)) +oneOf cs = satisfy (\c -> c `elem` cs) + +spaces = skipMany space <?> "white space" +space = satisfy (isSpace) <?> "space" +newline = char '\n' <?> "new-line" +tab = char '\t' <?> "tab" +upper = satisfy (isUpper) <?> "uppercase letter" +lower = satisfy (isLower) <?> "lowercase letter" +alphaNum = satisfy (isAlphaNum) <?> "letter or digit" +letter = satisfy (isAlpha) <?> "letter" +digit = satisfy (isDigit) <?> "digit" +hexDigit = satisfy (isHexDigit) <?> "hexadecimal digit" +octDigit = satisfy (isOctDigit) <?> "octal digit" +anyChar = anySymbol + +munch :: (s -> Bool) -> Parser s [s] +munch p = + do cs <- look + scan cs + where + scan (c:cs) | p c = do anySymbol; as <- scan cs; return (c:as) + scan _ = do return [] + +munch1 :: Show s => (s -> Bool) -> Parser s [s] +munch1 p = + do c <- satisfy p + cs <- munch p + return (c:cs) + +----------------------------------------------------------- +-- parser combinators + +(<?>) :: Parser s a -> String -> Parser s a +p <?> s = label p s + +pzero :: Parser s a +pzero = mzero + +(<|>) :: Parser s a -> Parser s a -> Parser s a +p <|> q = p `mplus` q + +(<<|>) :: Parser s a -> Parser s a -> Parser s a +p <<|> q = + do ma <- succeeds p + case ma of + Nothing -> q + Just a -> return a + +try :: Parser s a -> Parser s a +try p = p -- backwards compatibility with Parsec + +choice :: [Parser s a] -> Parser s a +choice ps = foldr (<|>) mzero ps + +option :: a -> Parser s a -> Parser s a +option x p = p <|> return x + +optional :: Parser s a -> Parser s () +optional p = (do p; return ()) <|> return () + +between :: Parser s open -> Parser s close -> Parser s a -> Parser s a +between open close p = do open; x <- p; close; return x + +-- repetition + +skipMany1,skipMany :: Parser s a -> Parser s () +skipMany1 p = do p; skipMany p +skipMany p = let scan = (do p; scan) <|> return () in scan + +many1,many :: Parser s a -> Parser s [a] +many1 p = do x <- p; xs <- many p; return (x:xs) +many p = let scan f = (do x <- p; scan (f.(x:))) <|> return (f []) in scan id + +sepBy1,sepBy :: Parser s a -> Parser s sep -> Parser s [a] +sepBy p sep = sepBy1 p sep <|> return [] +sepBy1 p sep = do x <- p; xs <- many (do sep; p); return (x:xs) + +count :: Int -> Parser s a -> Parser s [a] +count n p = sequence (replicate n p) + +chainr,chainl :: Parser s a -> Parser s (a -> a -> a) -> a -> Parser s a +chainr p op x = chainr1 p op <|> return x +chainl p op x = chainl1 p op <|> return x + +chainr1,chainl1 :: Parser s a -> Parser s (a -> a -> a) -> Parser s a +chainr1 p op = scan + where + scan = do x <- p; rest x + rest x = (do f <- op; y <- scan; return (f x y)) <|> return x + +chainl1 p op = scan + where + scan = do x <- p; rest x + rest x = (do f <- op; y <- p; rest (f x y)) <|> return x + +------------------------------------------------------------------------- +-- type ParseMethod, ParseResult + +type ParseMethod s a e r + = P s a -> [s] -> ParseResult e r + +type ParseResult e r + = Either (e, Expect, Unexpect) r + +-- parse functions + +parseFromFile :: Parser Char a -> ParseMethod Char a e r -> FilePath -> IO (ParseResult e r) +parseFromFile p method file = + do s <- readFile file + return (parse p method s) + +parse :: Parser s a -> ParseMethod s a e r -> [s] -> ParseResult e r +parse (Parser f) method xs = + case method (f (\a exp -> Result a (Fail exp [])) []) xs of + Left (err, exp, unexp) -> Left (err, [ s | s@(_:_) <- exp ], unexp) + Right x -> Right x + +-- parse methods + +shortestResult :: ParseMethod s a (Maybe s) a +shortestResult p xs = scan p xs + where + scan (Symbol sym) (x:xs) = scan (sym x) xs + scan (Symbol _) [] = scan (Fail [] []) [] + scan (Result res _) _ = Right res + scan (Fail exp err) (x:xs) = failSym x exp err + scan (Fail exp err) [] = failEof exp err + scan (Look f) xs = scan (f xs) xs + +longestResult :: ParseMethod s a (Maybe s) a +longestResult p xs = scan p Nothing xs + where + scan (Symbol sym) mres (x:xs) = scan (sym x) mres xs + scan (Symbol _) mres [] = scan (Fail [] []) mres [] + scan (Result res p) _ xs = scan p (Just res) xs + scan (Fail exp err) Nothing (x:xs) = failSym x exp err + scan (Fail exp err) Nothing [] = failEof exp err + scan (Fail _ _) (Just res) _ = Right res + scan (Look f) mres xs = scan (f xs) mres xs + +longestResults :: ParseMethod s a (Maybe s) [a] +longestResults p xs = scan p [] [] xs + where + scan (Symbol sym) [] old (x:xs) = scan (sym x) [] old xs + scan (Symbol sym) new old (x:xs) = scan (sym x) [] new xs + scan (Symbol _) new old [] = scan (Fail [] []) new old [] + scan (Result res p) new old xs = scan p (res:new) [] xs + scan (Fail exp err) [] [] (x:xs) = failSym x exp err + scan (Fail exp err) [] [] [] = failEof exp err + scan (Fail _ _) [] old _ = Right old + scan (Fail _ _) new _ _ = Right new + scan (Look f) new old xs = scan (f xs) new old xs + +allResultsStaged :: ParseMethod s a (Maybe s) [[a]] +allResultsStaged p xs = Right (scan p [] xs) + where + scan (Symbol sym) ys (x:xs) = ys : scan (sym x) [] xs + scan (Symbol _) ys [] = [ys] + scan (Result res p) ys xs = scan p (res:ys) xs + scan (Fail _ _) ys _ = [ys] + scan (Look f) ys xs = scan (f xs) ys xs + +allResults :: ParseMethod s a (Maybe s) [a] +allResults p xs = scan p xs + where + scan (Symbol sym) (x:xs) = scan (sym x) xs + scan (Symbol _) [] = scan (Fail [] []) [] + scan (Result res p) xs = Right (res : scan' p xs) + scan (Fail exp err) (x:xs) = failSym x exp err + scan (Fail exp err) [] = failEof exp err + scan (Look f) xs = scan (f xs) xs + + scan' p xs = + case scan p xs of + Left _ -> [] + Right ress -> ress + +completeResults :: ParseMethod s a (Maybe s) [a] +completeResults p xs = scan p xs + where + scan (Symbol sym) (x:xs) = scan (sym x) xs + scan (Symbol _) [] = scan (Fail [] []) [] + scan (Result res p) [] = Right (res : scan' p []) + scan (Result _ p) xs = scan p xs + scan (Fail exp err) (x:xs) = failSym x exp err + scan (Fail exp err) [] = failEof exp err + scan (Look f) xs = scan (f xs) xs + + scan' p xs = + case scan p xs of + Left _ -> [] + Right ress -> ress + +-- with left overs + +shortestResultWithLeftover :: ParseMethod s a (Maybe s) (a,[s]) +shortestResultWithLeftover p xs = scan p xs + where + scan (Symbol sym) (x:xs) = scan (sym x) xs + scan (Symbol _) [] = scan (Fail [] []) [] + scan (Result res _) xs = Right (res,xs) + scan (Fail exp err) (x:xs) = failSym x exp err + scan (Fail exp err) [] = failEof exp err + scan (Look f) xs = scan (f xs) xs + +longestResultWithLeftover :: ParseMethod s a (Maybe s) (a,[s]) +longestResultWithLeftover p xs = scan p Nothing xs + where + scan (Symbol sym) mres (x:xs) = scan (sym x) mres xs + scan (Symbol _) mres [] = scan (Fail [] []) mres [] + scan (Result res p) _ xs = scan p (Just (res,xs)) xs + scan (Fail exp err) Nothing (x:xs) = failSym x exp err + scan (Fail exp err) Nothing [] = failEof exp err + scan (Fail _ _) (Just resxs) _ = Right resxs + scan (Look f) mres xs = scan (f xs) mres xs + +longestResultsWithLeftover :: ParseMethod s a (Maybe s) ([a],Maybe [s]) +longestResultsWithLeftover p xs = scan p empty empty xs + where + scan (Symbol sym) ([],_) old (x:xs) = scan (sym x) empty old xs + scan (Symbol sym) new old (x:xs) = scan (sym x) empty new xs + scan (Symbol _) new old [] = scan (Fail [] []) new old [] + scan (Result res p) (as,_) old xs = scan p (res:as,Just xs) empty xs + scan (Fail exp err) ([],_) ([],_) (x:xs) = failSym x exp err + scan (Fail exp err) ([],_) ([],_) [] = failEof exp err + scan (Fail _ _) ([],_) old _ = Right old + scan (Fail _ _) new _ _ = Right new + scan (Look f) new old xs = scan (f xs) new old xs + + empty = ([],Nothing) + +allResultsWithLeftover :: ParseMethod s a (Maybe s) [(a,[s])] +allResultsWithLeftover p xs = scan p xs + where + scan (Symbol sym) (x:xs) = scan (sym x) xs + scan (Symbol _) [] = scan (Fail [] []) [] + scan (Result res p) xs = Right ((res,xs) : scan' p xs) + scan (Fail exp err) (x:xs) = failSym x exp err + scan (Fail exp err) [] = failEof exp err + scan (Look f) xs = scan (f xs) xs + + scan' p xs = + case scan p xs of + Left _ -> [] + Right ress -> ress + +completeResultsWithLine :: ParseMethod Char a Int [a] +completeResultsWithLine p xs = scan p 1 xs + where + scan (Symbol sym) n (x:xs) = let n' = x |> n in n' `seq` scan (sym x) n' xs + scan (Symbol _) n [] = scan (Fail [] ["end of file"]) n [] + scan (Result res p) n [] = Right (res : scan' p n []) + scan (Result _ p) n xs = scan p n xs + scan (Fail exp err) n xs = Left (n, exp, err) + scan (Look f) n xs = scan (f xs) n xs + + scan' p n xs = + case scan p n xs of + Left _ -> [] + Right ress -> ress + + '\n' |> n = n+1 + _ |> n = n + +-- failing + +failSym :: s -> Expect -> Unexpect -> ParseResult (Maybe s) r +failSym s exp err = Left (Just s, exp, err) + +failEof :: Expect -> Unexpect -> ParseResult (Maybe s) r +failEof exp err = Left (Nothing, exp, err ++ ["end of file"]) + +------------------------------------------------------------------------- +-- the end.
+ PureFP.hs view
@@ -0,0 +1,52 @@+-- -------------------------------------------------------------------------- +-- $Revision: 264 $ $Date: 2007-04-13 18:24:56 +0200 (Fri, 13 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP +-- 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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software.html> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> +-- +-- +-- Copyright (C) 2002 Peter Ljunglof (C) 2005-2007 Otakar Smrz +-- +-- 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. +-- +-- +-- "PureFP.OrdMap" "PureFP.OrdSet" "PureFP.Parsers" + + +module PureFP where + + +import Version + +version = revised "$Revision: 264 $"
+ PureFP/OrdMap.hs view
@@ -0,0 +1,140 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.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 PureFP.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)
+ PureFP/OrdSet.hs view
@@ -0,0 +1,129 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.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 PureFP.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 + +
+ PureFP/Parsers.hs view
@@ -0,0 +1,70 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.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@] +-- "PureFP.Parsers.Standard", +-- the standard parser, sec. 3.2 +-- +-- ['Stream' @s@] +-- "PureFP.Parsers.Stream", +-- the stream processor parser, sec. 3.5.2 +-- +-- ['Trie' @s@] +-- "PureFP.Parsers.Trie", +-- the trie parser, sec. 4.2.1 +-- +-- ['AmbTrie' @s@] +-- "PureFP.Parsers.AmbTrie", +-- the ambiguous trie parser, sec. 4.2.2 +-- +-- ['ExTrie' @s@] +-- "PureFP.Parsers.ExTrie", +-- the extended trie parser, sec. 4.3.3 +-- +-- ['AmbExTrie' @s@] +-- "PureFP.Parsers.AmbExTrie", +-- the ambiguous extended trie parser, sec. 4.3.4 +-- +-- ['PairTrie' 'Standard' @s@] +-- "PureFP.Parsers.PairTrie", together with +-- "PureFP.Parsers.Standard", +-- the paired trie parser, sec. 4.4 +-- +-- "PureFP.OrdMap" "PureFP.Parsers.Parser" + + +module PureFP.Parsers where + + +import PureFP.Parsers.Standard +import PureFP.Parsers.Stream +import PureFP.Parsers.Trie +import PureFP.Parsers.AmbTrie +import PureFP.Parsers.ExTrie +import PureFP.Parsers.AmbExTrie +import PureFP.Parsers.PairTrie + +import Version + +version = revised "$Revision: 262 $"
+ PureFP/Parsers/AmbExTrie.hs view
@@ -0,0 +1,92 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the ambiguous extended trie from section 4.3.4 + + +module PureFP.Parsers.AmbExTrie (AmbExTrie (..), unfold) where + +import PureFP.OrdMap +import PureFP.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 -> []
+ PureFP/Parsers/AmbTrie.hs view
@@ -0,0 +1,79 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the ambiguous trie from section 4.2.2 + + +module PureFP.Parsers.AmbTrie (AmbTrie (..)) where + +import PureFP.OrdMap +import PureFP.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 -> []
+ PureFP/Parsers/ExTrie.hs view
@@ -0,0 +1,94 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the extended trie from section 4.3.3 + + +module PureFP.Parsers.ExTrie (ExTrie) where + +import PureFP.OrdMap +import PureFP.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 -> []
+ PureFP/Parsers/PairTrie.hs view
@@ -0,0 +1,113 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the pairing trie parser from section 4.4 + + +module PureFP.Parsers.PairTrie (PairTrie, ParserTrie) where + +import PureFP.OrdMap +import PureFP.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 -> []
+ PureFP/Parsers/Parser.hs view
@@ -0,0 +1,170 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.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 PureFP.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
+ PureFP/Parsers/Standard.hs view
@@ -0,0 +1,86 @@+-- -------------------------------------------------------------------------- +-- $Revision: 287 $ $Date: 2007-04-25 23:25:57 +0200 (Wed, 25 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the standard parser from section 3.2 + + +module PureFP.Parsers.Standard (Standard (..)) where + +import PureFP.Parsers.Parser + +import Control.Monad.State + + +newtype Standard s a = Std ([s] -> [([s], a)]) + + +instance MonadState [s] (Standard s) where + + get = Std (\inp -> [(inp, inp)]) + + put s = Std (\inp -> [(s, ())]) + + +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)
+ PureFP/Parsers/Stream.hs view
@@ -0,0 +1,90 @@+-- -------------------------------------------------------------------------- +-- $Revision: 264 $ $Date: 2007-04-13 18:24:56 +0200 (Fri, 13 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> +-- +-- "Parsek" + + +-------------------------------------------------- +-- the stream processor from section 3.5.2 + + +module PureFP.Parsers.Stream (Stream) where + +import PureFP.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 _ _ = [] + +
+ PureFP/Parsers/Trie.hs view
@@ -0,0 +1,85 @@+-- -------------------------------------------------------------------------- +-- $Revision: 262 $ $Date: 2007-04-12 12:19:50 +0200 (Thu, 12 Apr 2007) $ +-- -------------------------------------------------------------------------- + +-- | +-- +-- Module : PureFP.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.ling.gu.se/~peb/pubs/p02-lic-thesis.pdf> +-- +-- <http://www.ling.gu.se/~peb/software/functional-parsing/> + + +-------------------------------------------------- +-- the trie parser from section 4.2.1 + + +module PureFP.Parsers.Trie (Trie) where + +import PureFP.OrdMap +import PureFP.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 -> [] + + + +
+ Setup.PL view
@@ -0,0 +1,217 @@+#! env perl + +# ###################################################################### Otakar Smrz, 2006/11/13 +# +# Building Encode ############################################################################## + +# $Id: Setup.PL 748 2008-11-07 22:31:28Z smrz $ + +our $VERSION = do { q $Revision: 748 $ =~ /(\d+)/; sprintf "%4.2f", $1 / 100 }; + + +use File::Spec; +use File::Copy; + + +sub path ($) { + + return File::Spec->join(split ' ', $_[0]); +} + + $DdotsEncodeExecbin = path "... Encode bin"; + + $Ddots = path "..."; + + $Dbin = path ". bin"; + $Ddoc = path ". doc"; + + $fLICENSE = path ". LICENSE"; + $fSOURCE = path ". SOURCE"; + + $\ = "\n"; + + + $file = path ". Encode.cabal"; + + open C, '<', $file or die "Cannot open " . $file . "!\n"; + + while (<C>) { + + $ver = $1 if /^\s* version \s* : \s* ([^\s]+) \s*$/ix; + $url = $1 if /^\s* package-url \s* : \s* ([^\s]+) \s*$/ix; + $author = $1 if /^\s* author \s* : \s* ([^\s]+\ [^\s]+)\s*$/ix; + $maintainer = $1 if /^\s* maintainer \s* : \s* ([^\s]+\ [^\s]+)\s*$/ix; + $homepage = $1 if /^\s* homepage \s* : \s* ([^\s]+) \s*$/ix; + $copyright = $1 if /^\s* copyright \s* : \s* ([^\s]+) \s*$/ix; + } + + close C; + + die "Version not recognized!\n" unless $ver; + die "Package-URL not recognized!\n" unless $url; + die "Author not recognized!\n" unless $author; + die "Maintainer not recognized!\n" unless $maintainer; + die "Homepage not recognized!\n" unless $homepage; + die "Copyright not recognized!\n" unless $copyright; + + + mkdir "dist" unless -d "dist"; + + print "Changing directory: dist"; + chdir "dist"; + + + print "Removing ..."; + + foreach $file ((glob path "Encode doc decode *"), + (glob path "Encode doc encode *"), + (glob path "Encode doc *"), + (glob path "Encode bin *"), + (glob path "Encode *")) { + + print ' <- ' . $file; + + unlink $file; + } + + rmdir path "Encode doc decode"; + rmdir path "Encode doc encode"; + rmdir path "Encode doc"; + rmdir path "Encode bin"; + rmdir path "Encode"; + + die "Remove the " . ( path "dist Encode" ). " directory first!\n" if -d "Encode"; + + mkdir path "Encode"; + mkdir path "Encode bin"; + mkdir path "Encode doc"; + mkdir path "Encode doc encode"; + mkdir path "Encode doc decode"; + + + print "Changing directory: .."; + chdir ".."; + + + @param = @ARGV ? @ARGV : $^O eq 'MSWin32' ? "--global" + : "--user --prefix $ENV{'HOME'}/.cabal"; + + print "Configuring with parameters: @param"; + + system "runhaskell Setup.hs configure @param"; + system "runhaskell Setup.hs build"; + system "runhaskell Setup.hs haddock --executables"; + system "runhaskell Setup.hs install"; + system "runhaskell Setup.hs sdist"; + + + print "Changing directory: dist"; + chdir "dist"; + + + $path = path "Encode bin"; + + print $path; + + @execs = $^O eq 'MSWin32' ? (path "build encode encode.exe", path "build decode decode.exe") + : (path "build encode encode", path "build decode decode"); + + foreach $file (@execs) { + + print ' <- ' . $file; + + copy $file, $path; + } + + + $path = path "Encode doc encode"; + + print $path; + + foreach $file (glob path "doc html Encode encode *") { + + print ' <- ' . $file; + + move $file, $path; + } + + + $path = path "Encode doc decode"; + + print $path; + + foreach $file (glob path "doc html Encode decode *") { + + print ' <- ' . $file; + + move $file, $path; + } + + + copy path ".. LICENSE", path "Encode"; + + + open S, '>', path "Encode SOURCE"; + + print S << "SOURCE"; + +This software is distributed under the GNU General Public License in $fLICENSE. +The source code for this software can be downloaded from the following address: + + $url + +If experiencing problems, please contact the maintainer of the software: + + $author <$maintainer> + $homepage + +Copyright (C) $copyright $author +SOURCE + + close S; + + + open I, '>', path "Encode INSTALL"; + + print I << "INSTALL"; + +This package includes the $^O-built executables of the "Encode-$ver" library: + + $url + +Before using the programs in the $Dbin directory, please read the license terms +in $fLICENSE and $fSOURCE. The HTML documentation is in the $Ddoc directories. + +In order to run the programs, unpack the contents of the distribution package +and then: + +either execute the programs from within the $Dbin directory + + or copy the contents of the $Dbin directory to some other directory that + is already included in the PATH environment variable + + or extend the setting of the PATH variable with $DdotsEncodeExecbin, where + $Ddots stands for the actual path to the unpacked distribution + +If experiencing problems, please contact the maintainer of the software: + + $author <$maintainer> + $homepage + +Copyright (C) $copyright $author +INSTALL + + close I; + + + $name = "Encode-Exec-" . $ver . "-built-" . $^O; + + system "tar -cf " . $name . ".tar" . " Encode"; + + system "gzip -9 " . $name . ".tar"; + + print "Done with " . $name . ".tar.gz"; + + system "zip -r " . $name . ".zip" . " Encode"; + + print "Done with " . $name . ".zip";
Setup.hs view
@@ -1,2 +1,2 @@-import Distribution.Simple-main = defaultMain+import Distribution.Simple +main = defaultMain
Version.hs view
@@ -1,45 +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+-- -------------------------------------------------------------------------- +-- $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