packages feed

haskellish 0.2.4.3 → 0.3.1

raw patch · 3 files changed

+73/−6 lines, 3 filessetup-changedPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Language.Haskellish: enumFromThenTo :: Haskellish st a -> Haskellish st b -> Haskellish st c -> Haskellish st (a, b, c)
+ Language.Haskellish: enumFromTo :: Haskellish st a -> Haskellish st b -> Haskellish st (a, b)
+ Language.Haskellish: parseWithModeAndRun :: ParseMode -> Haskellish st a -> st -> String -> Either (Span, Text) (a, st)
+ Language.Haskellish: removeComments :: String -> String
+ Language.Haskellish: removeCommentsLiteralString :: String -> String
+ Language.Haskellish: removeCommentsMultiLine :: String -> String
+ Language.Haskellish: removeCommentsSingleLine :: String -> String
- Language.Haskellish: parseAndRun :: Haskellish st a -> st -> Text -> Either (Span, Text) (a, st)
+ Language.Haskellish: parseAndRun :: Haskellish st a -> st -> String -> Either (Span, Text) (a, st)

Files

Language/Haskellish.hs view
@@ -35,9 +35,12 @@ -- running a Haskellish parser. It uses haskell-src-exts to parse Text into a Haskell AST -- that is then parsed by the Haskellish parser. -parseAndRun :: Haskellish st a -> st -> Text -> Either (Span,Text) (a,st)-parseAndRun h st x = do-  case Exts.parseExp (T.unpack x) of+parseAndRun :: Haskellish st a -> st -> String -> Either (Span,Text) (a,st)+parseAndRun = parseWithModeAndRun Exts.defaultParseMode++parseWithModeAndRun :: Exts.ParseMode -> Haskellish st a -> st -> String -> Either (Span,Text) (a,st)+parseWithModeAndRun m h st x = do+  case Exts.parseWithMode m x of     Exts.ParseOk e -> do       case _run h st e of         Right (a,st) -> Right (a,st)@@ -49,6 +52,43 @@         b = Exts.srcColumn loc  +-- removing Haskell comments (while preserving document/newlines structure) before+-- asking haskell-src-exts to parse the Haskell AST simplifies some applications+-- where haskellish is used in ways that don't quite conform to the full Haskell+-- syntax rules. 'removeComments' can be used ahead of parseAndRun for this purpose++-- 1. default is we are not in a comment or a string+removeComments :: String -> String+removeComments [] = []+removeComments ('-':'-':xs) = removeCommentsSingleLine xs+removeComments ('{':'-':xs) = "  " ++ removeCommentsMultiLine xs+removeComments ('\"':xs) = '\"' : removeCommentsLiteralString xs+removeComments (x:xs) = x : removeComments xs++-- 2. if we are in a single-line comment, then we throw away characters until the next new line, which we keep+removeCommentsSingleLine :: String -> String+removeCommentsSingleLine [] = []+removeCommentsSingleLine ('\n':xs) = '\n' : removeComments xs+removeCommentsSingleLine (_:xs) = removeCommentsSingleLine xs++-- 3. if we are in a multi-line comment, then we replace characters (except newlines) with spaces until we get the terminator+-- (we replace with spaces, instead of throwing away, to preserve the line structure in lines that contain the terminator)+removeCommentsMultiLine :: String -> String+removeCommentsMultiLine [] = []+removeCommentsMultiLine ('\n':xs) = '\n' : removeCommentsMultiLine xs+removeCommentsMultiLine ('-':'}':xs) = "  " ++ removeComments xs+removeCommentsMultiLine (_:xs) = ' ' : removeCommentsMultiLine xs++-- 4. if we are in a literal string, then we are in a literal string until the string is terminated+-- (note: this implementation does not currently support Haskell multi-line strings and may not accurately+-- reflect what is supposed to happen if a literal string is not appropriately terminated within a given line.)+removeCommentsLiteralString :: String -> String+removeCommentsLiteralString [] = []+removeCommentsLiteralString ('\\':'"':xs) = "\"" ++ removeCommentsLiteralString xs+removeCommentsLiteralString ('"':xs) = '"' : removeComments xs+removeCommentsLiteralString (x:xs) = x : removeCommentsLiteralString xs++ exp :: Haskellish st (Exp SrcSpanInfo) exp = Haskellish (\st e -> return (e,st)) @@ -322,3 +362,32 @@   (x,st'') <- _run xP st' xE   return ((f,x),st'')   )+++-- | enumFromTo matches anything with the following form: [a..b]++enumFromTo :: Haskellish st a -> Haskellish st b -> Haskellish st (a,b)+enumFromTo aP bP = Haskellish (\st e -> do+  (aE,bE) <- f e+  (a,st') <- _run aP st aE+  (b,st'') <- _run bP st' bE+  return ((a,b),st'')+  )+  where+    f (EnumFromTo _ aE bE) = Right (aE,bE)+    f e = Left $ NonFatal (expToSpan e) "expected application enumFromTo"+++-- | enumFromThenTo matches anything with theform [a,b..c]++enumFromThenTo :: Haskellish st a -> Haskellish st b -> Haskellish st c -> Haskellish st (a,b,c)+enumFromThenTo aP bP cP = Haskellish (\st e -> do+  (aE,bE,cE) <- f e+  (a,st') <- _run aP st aE+  (b,st'') <- _run bP st' bE+  (c,st''') <- _run cP st'' cE+  return ((a,b,c),st''')+  )+  where+    f (EnumFromThenTo _ aE bE cE) = Right (aE,bE,cE)+    f e = Left $ NonFatal (expToSpan e) "expected application enumFromThenTo"
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
haskellish.cabal view
@@ -1,5 +1,5 @@ name:                haskellish-version:             0.2.4.3+version:             0.3.1 synopsis:            For parsing Haskell-ish languages homepage:            http://github.com/dktr0/Haskellish license:             BSD3