Verified Commit d4176dc1 authored by Camil Staps's avatar Camil Staps
Browse files

Use trim from Text

parent 393afb03
...@@ -21,8 +21,8 @@ import Data.GenDefault ...@@ -21,8 +21,8 @@ import Data.GenDefault
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import Data.Tuple import Data.Tuple
from Text import class Text(join,split), instance Text String from Text import class Text(join,split,trim,rtrim),
import qualified Text instance Text String, instance Text [Char]
import Text.Language import Text.Language
import Text.Parsers.Simple.ParserCombinators import Text.Parsers.Simple.ParserCombinators
...@@ -113,7 +113,7 @@ parseDoc s = docBlockToDoc{|*|} (Left [s]) ...@@ -113,7 +113,7 @@ parseDoc s = docBlockToDoc{|*|} (Left [s])
generic docBlockToDoc d :: !(Either [String] DocBlock) -> Either ParseError (!d, ![ParseWarning]) generic docBlockToDoc d :: !(Either [String] DocBlock) -> Either ParseError (!d, ![ParseWarning])
docBlockToDoc{|String|} (Left []) = Left InternalNoDataError docBlockToDoc{|String|} (Left []) = Left InternalNoDataError
docBlockToDoc{|String|} (Left ss) = Right (toString $ trim $ fromString $ last ss, []) docBlockToDoc{|String|} (Left ss) = Right (trim $ last ss, [])
docBlockToDoc{|[]|} fx (Left ss) = (\vws -> (map fst vws, flatten (map snd vws)) ) <$> mapM fx (map (Left o pure) ss) docBlockToDoc{|[]|} fx (Left ss) = (\vws -> (map fst vws, flatten (map snd vws)) ) <$> mapM fx (map (Left o pure) ss)
docBlockToDoc{|Maybe|} fx (Left []) = Right (Nothing, []) docBlockToDoc{|Maybe|} fx (Left []) = Right (Nothing, [])
docBlockToDoc{|Maybe|} fx ss=:(Left _) = appFst Just <$> fx ss docBlockToDoc{|Maybe|} fx ss=:(Left _) = appFst Just <$> fx ss
...@@ -198,7 +198,7 @@ where ...@@ -198,7 +198,7 @@ where
docBlockToDoc{|PropertyVarInstantiation|} (Left [s]) = case split "=" s of docBlockToDoc{|PropertyVarInstantiation|} (Left [s]) = case split "=" s of
[var:type:[]] -> case 'T'.parseType (fromString type) of [var:type:[]] -> case 'T'.parseType (fromString type) of
Just t -> Right (PropertyVarInstantiation ('Text'.trim var, t), []) Just t -> Right (PropertyVarInstantiation (trim var, t), [])
Nothing -> Left (UnknownError "type could not be parsed") Nothing -> Left (UnknownError "type could not be parsed")
_ -> Left (UnknownError "property var instantiation could not be parsed") _ -> Left (UnknownError "property var instantiation could not be parsed")
...@@ -244,7 +244,7 @@ where ...@@ -244,7 +244,7 @@ where
desc = flatten $ intersperse ['\n'] $ if (isEmpty descline) restdesc [tl descline:restdesc] desc = flatten $ intersperse ['\n'] $ if (isEmpty descline) restdesc [tl descline:restdesc]
parseFs :: ![Char] ![Char] !DocBlock -> Either ParseError (!DocBlock, ![ParseWarning]) parseFs :: ![Char] ![Char] !DocBlock -> Either ParseError (!DocBlock, ![ParseWarning])
parseFs field val d = Right ([(toString field,toString val):d], []) parseFs field val d = Right ([(toString field,toString (rtrim val)):d], [])
prepareString :: (String -> Either ParseError [[Char]]) prepareString :: (String -> Either ParseError [[Char]])
prepareString = checkAsterisks o map trim o break '\n' o fromString prepareString = checkAsterisks o map trim o break '\n' o fromString
...@@ -270,8 +270,6 @@ where ...@@ -270,8 +270,6 @@ where
linesToString :: ([[Char]] -> String) linesToString :: ([[Char]] -> String)
linesToString = toString o flatten o intersperse ['\n'] linesToString = toString o flatten o intersperse ['\n']
trim :== twice (reverse o dropWhile isSpace)
instance toString ParseWarning instance toString ParseWarning
where where
toString (UnknownField f) = "Doc warning: unknown field '" +++ f +++ "'" toString (UnknownField f) = "Doc warning: unknown field '" +++ f +++ "'"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment