Commit ee76351b authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

Merge branch 'femtoparsec' into refactor

parents 4e63d32b 783d8642
......@@ -62,7 +62,7 @@ MainModule
Fusion: False
OtherModules
Module
Name: Development.Scrub
Name: Data.Slice
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
......@@ -76,7 +76,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Attoparsec
Name: Data.String
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
......@@ -90,22 +90,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: GenEq
Dir: {Application}/lib/Generics
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: GenPrint
Dir: {Application}/lib/Generics
Name: Development.Scrub
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -118,8 +104,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: StdMaybe
Dir: {Application}/lib/StdLib
Name: Prelude
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -132,8 +118,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Control.Applicative
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Name: Text.Femtoparsec
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -146,8 +132,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Control.Monad
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Name: GenEq
Dir: {Application}/lib/Generics
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -160,8 +146,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Bool
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Name: GenPrint
Dir: {Application}/lib/Generics
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -174,8 +160,8 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Char
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Name: StdMaybe
Dir: {Application}/lib/StdLib
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -188,7 +174,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Either
Name: Control.Applicative
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -202,7 +188,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Eq
Name: Control.Monad
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -216,7 +202,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Error
Name: Data.Array
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -230,7 +216,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Foldable
Name: Data.Bool
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -244,7 +230,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Func
Name: Data.Char
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -258,7 +244,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Functor
Name: Data.Either
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -272,7 +258,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Int
Name: Data.Eq
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -286,7 +272,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.List
Name: Data.Error
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -300,7 +286,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Map
Name: Data.Foldable
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -314,7 +300,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Maybe
Name: Data.Func
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -328,7 +314,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Monoid
Name: Data.Functor
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -342,7 +328,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Num
Name: Data.Int
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -356,7 +342,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Ord
Name: Data.List
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -370,7 +356,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Result
Name: Data.Map
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -384,7 +370,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Set
Name: Data.Maybe
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -398,7 +384,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Set.Operators
Name: Data.Monoid
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -412,7 +398,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.String
Name: Data.Num
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -426,7 +412,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Traversable
Name: Data.Ord
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -440,7 +426,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Tuple
Name: Data.Result
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -454,7 +440,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Void
Name: Data.Set
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -468,7 +454,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.CommandLine
Name: Data.Set.Operators
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -482,7 +468,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.Console.Output
Name: Data.Show
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -496,7 +482,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.FilePath
Name: Data.Traversable
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -510,7 +496,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.FilePath.Find
Name: Data.Tuple
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -524,7 +510,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System.IO
Name: Data.Void
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -538,7 +524,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: System._Pointer
Name: System.CommandLine
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -552,7 +538,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text
Name: System.Console.Output
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -566,7 +552,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.JSON
Name: System.FilePath
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -580,7 +566,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.PPrint
Name: System.FilePath.Find
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -594,7 +580,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Parsers.ParserLanguage
Name: System.IO
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -608,7 +594,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Parsers.Parsers
Name: System._Pointer
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -622,7 +608,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Parsers.ParsersAccessories
Name: Text
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -636,7 +622,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Parsers.ParsersDerived
Name: Text.JSON
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......@@ -650,7 +636,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: Text.Parsers.ParsersKernel
Name: Text.PPrint
Dir: {Project}/../clean-platform/src/libraries/OS-Independent
Compiler
NeverMemoryProfile: False
......
definition module Data.Slice
from Data.Eq import class ==
from Data.Ord import class <
from Data.Maybe import :: Maybe
from StdOverloaded import class %
////////////////////////////////////////////////////////////////////////////////
/// # Data Type
////////////////////////////////////////////////////////////////////////////////
:: Slice
instance == Slice
instance < Slice
instance % Slice
////////////////////////////////////////////////////////////////////////////////
/// # Primitives
////////////////////////////////////////////////////////////////////////////////
empty :: Slice
singleton :: !Char -> Slice
slice :: !Int !Int !String -> Slice
wrap :: !String -> Slice
unwrap :: !Slice -> String
////////////////////////////////////////////////////////////////////////////////
/// # Basics
////////////////////////////////////////////////////////////////////////////////
head :: !Slice -> Maybe Char
tail :: !Slice -> Maybe Slice
init :: !Slice -> Maybe Slice
last :: !Slice -> Maybe Char
uncons :: !Slice -> Maybe (Char,Slice)
unsnoc :: !Slice -> Maybe (Slice,Char)
unsafeHead :: !Slice -> Char
unsafeTail :: !Slice -> Slice
unsafeInit :: !Slice -> Slice
unsafeLast :: !Slice -> Char
unsafeUncons :: !Slice -> (Char,Slice)
unsafeUnsnoc :: !Slice -> (Slice,Char)
////////////////////////////////////////////////////////////////////////////////
/// # Sliceable
////////////////////////////////////////////////////////////////////////////////
take :: !Int !Slice -> Slice
drop :: !Int !Slice -> Slice
splitAt :: !Int !Slice -> (Slice, Slice)
takeTill :: !(Char -> Bool) !Slice -> Slice
dropTill :: !(Char -> Bool) !Slice -> Slice
break :: !(Char -> Bool) !Slice -> (Slice, Slice)
takeWhile :: !(Char -> Bool) !Slice -> Slice
dropWhile :: !(Char -> Bool) !Slice -> Slice
span :: !(Char -> Bool) !Slice -> (Slice, Slice)
isPrefixOf :: !String !Slice -> Bool
isSuffixOf :: !String !Slice -> Bool
//TODO isInfixOf :: !Slice !Slice -> Bool
////////////////////////////////////////////////////////////////////////////////
/// # Splitable
////////////////////////////////////////////////////////////////////////////////
// split :: !Char !Slice -> [Slice]
// splitWith :: (Char -> Bool) !Slice -> [Slice]
// lines :: !Slice -> [Slice]
// words :: !Slice -> [Slice]
////////////////////////////////////////////////////////////////////////////////
/// # Foldable
////////////////////////////////////////////////////////////////////////////////
// foldl :: (a Char -> a) a Slice -> a
// foldl` :: (a Char -> a) a !Slice -> a
// foldl1 :: (Char Char -> Char) Slice -> a
// foldl1` :: (Char Char -> Char) !Slice -> a
// foldr :: (a Char -> a) a Slice -> a
// foldr` :: (a Char -> a) a !Slice -> a
// foldr1 :: (Char Char -> Char) Slice -> a
// foldr1` :: (Char Char -> Char) !Slice -> a
isEmpty :: !Slice -> Bool
length :: !Slice -> Int
// any :: !(Char -> Bool) !Slice -> Bool
// all :: !(Char -> Bool) !Slice -> Bool
// maximum :: !Slice -> Bool
// minimum :: !Slice -> Bool
////////////////////////////////////////////////////////////////////////////////
/// # Indexable
////////////////////////////////////////////////////////////////////////////////
findIndex :: !(Char -> Bool) !Slice -> Maybe Int
findIndexOrEnd :: !(Char -> Bool) !Slice -> Int
implementation module Data.Slice
import Prelude
import qualified Data.String as String
////////////////////////////////////////////////////////////////////////////////
/// # Data Type
////////////////////////////////////////////////////////////////////////////////
:: Slice =
{ string :: !String
, position :: !Int
, length :: !Int
}
// instance == Slice where
// (==) left right
// | left.length <> right.length = False
// = check (left.length - 1)
// where
// check 0 = left.string.[left.position] == right.string.[right.position]
// check i = left.string.[left.position + i] == right.string.[right.position + i] && check (i - 1)
/// Instance of Eq
instance == Slice where
(==) left right
| left.length <> right.length = False
= check left.position right.position
where
lmax = left.position + left.length
// rmax = right.position + right.length
check l r
// | l < lmax && r < rmax = left.string.[l] == right.string.[r] && check (l + 1) (r + 1)
| l < lmax = left.string.[l] == right.string.[r] && check (l + 1) (r + 1)
= True
/// Instance of Ord
instance < Slice where
(<) left right
| left.length > right.length = False
= check left.position right.position
where
lmax = left.position + left.length
check l r
# lchar = left.string.[l]
# rchar = right.string.[r]
| l < lmax
| lchar < rchar = True
| lchar == rchar = check (l + 1) (r + 1)
= False
= left.length < right.length
/// Instance of Sliceable
instance % Slice where
(%) {string,position,length} (upper,lower) =
{ string = string // Retains the string
, position = position + min upper length
, length = max (lower - upper + 1) 0
}
///TODO Instance of Print
///TODO Instance of Scan
////////////////////////////////////////////////////////////////////////////////
/// # Primitives
////////////////////////////////////////////////////////////////////////////////
empty :: Slice
empty = wrap 'String'.empty
singleton :: !Char -> Slice
singleton char = wrap ('String'.singleton char)
slice :: !Int !Int !String -> Slice
slice upper lower string = wrap string % (upper, lower)
wrap :: !String -> Slice
wrap string =
{ string = string // Retains the string
, position = 0
, length = size string
}
unwrap :: !Slice -> String
unwrap {string,position,length} = string % (position, position + length - 1) // Releases the string
////////////////////////////////////////////////////////////////////////////////
/// # Basics
////////////////////////////////////////////////////////////////////////////////
/// ## Safe basics
head :: !Slice -> Maybe Char
head slice
| slice.length <= 0 = Nothing
= Just $ unsafeHead slice
tail :: !Slice -> Maybe Slice
tail slice
| slice.length <= 0 = Nothing
= Just $ unsafeTail slice
init :: !Slice -> Maybe Slice
init slice
| slice.length <= 0 = Nothing
= Just $ unsafeInit slice
last :: !Slice -> Maybe Char
last slice
| slice.length <= 0 = Nothing
= Just $ unsafeLast slice
uncons :: !Slice -> Maybe (Char,Slice)
uncons slice
| slice.length <= 0 = Nothing
= Just (unsafeHead slice, unsafeTail slice)
unsnoc :: !Slice -> Maybe (Slice,Char)
unsnoc slice
| slice.length <= 0 = Nothing
= Just (unsafeInit slice, unsafeLast slice)
/// ### Unsafe basics
unsafeHead :: !Slice -> Char
unsafeHead {string,position,length} = string.[position]
unsafeTail :: !Slice -> Slice
unsafeTail {string,position,length} =
{ string = string
, position = position + 1
, length = length - 1
}
unsafeInit :: !Slice -> Slice
unsafeInit {string,position,length} =
{ string = string
, position = position
, length = length - 1
}
unsafeLast :: !Slice -> Char
unsafeLast {string,position,length} = string.[position + length - 1]
unsafeUncons :: !Slice -> (Char,Slice)
unsafeUncons slice
= (unsafeHead slice, unsafeTail slice)
unsafeUnsnoc :: !Slice -> (Slice,Char)
unsafeUnsnoc slice
= (unsafeInit slice, unsafeLast slice)
/// ## Length
isEmpty :: !Slice -> Bool
isEmpty {string,position,length} = length == 0
length :: !Slice -> Int
length {string,position,length} = length
////////////////////////////////////////////////////////////////////////////////