maude 0.1.2 → 0.1.3
raw patch · 2 files changed
+24/−13 lines, 2 files
Files
- Foreign/Maude.hs +22/−11
- maude.cabal +2/−2
Foreign/Maude.hs view
@@ -38,6 +38,7 @@ -- $future ) where +import Data.Char (isSpace) import Data.List (break, stripPrefix) import System.IO (hPutStrLn, hClose, openTempFile) import System.Directory (getCurrentDirectory, removeFile)@@ -67,7 +68,7 @@ -- | The 'rewrite' function takes a list of Maude file names and a term, and -- attempts to rewrite the term in the context of those files. It assumes--- the command to run Maude is \"maude\" and that it located somewhere in+-- the command to run Maude is \"maude\" and that it is located somewhere in -- @$PATH@. rewrite :: [FilePath] -> String -> IO (Maybe MaudeResult) rewrite files term = do@@ -80,16 +81,21 @@ -- | Parse Maude's output into a MaudeResult. The current implementation -- does very little sanity checking and can not parse Maude failures. parseMaudeResult :: String -> Maybe MaudeResult-parseMaudeResult str = case lines str of- (stats : res : _) -> do- r <- stripPrefix "result " res- let (sort, term) = break (==':') r- return $ MaudeResult- { resultSort = sort- , resultTerm = drop 2 term- , statistics = stats- }- _ -> Nothing+parseMaudeResult str = do+ let (stats, rest) = break (== '\n') str+ r <- stripPrefix "\nresult " rest+ let (sort, rest') = break (== ':') r+ let term = parseTerm rest'+ return $ MaudeResult+ { resultSort = sort+ , resultTerm = term+ , statistics = stats+ }+ where parseTerm = trim+ . concat+ . filter (/= "Bye.")+ . lines+ . drop 1 -- Remove the ':' -- | Create a temporary file which contains the commands Maude should run at -- startup, namely some formatting commands, the rewrite command, and quit.@@ -103,6 +109,11 @@ hPutStrLn tmph "quit" hClose tmph return tmpf++-- | Remove leading and trailing whitespace from a string.+trim :: String -> String+trim = f . f+ where f = reverse . dropWhile isSpace {- $examples
maude.cabal view
@@ -1,8 +1,8 @@ Name: maude-Version: 0.1.2+Version: 0.1.3 Synopsis: An interface to the Maude rewriting system. Description: This package provides a simple interface for doing Maude- rewrites from within Haskell. + rewrites from within Haskell. Homepage: https://code.google.com/p/maude-hs/ License: MIT License-file: LICENSE