core-haskell 0.6.1 → 0.6.2
raw patch · 4 files changed
+127/−124 lines, 4 filesdep ~basesetup-changed
Dependency ranges changed: base
Files
- LICENSE +26/−26
- Setup.hs +1/−1
- core-haskell.cabal +26/−23
- core-haskell.hs +74/−74
LICENSE view
@@ -1,27 +1,27 @@-Copyright 2014, ChengXi Bao. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. 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. - -3. Neither the name of the author nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -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 OWNER 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 +Copyright 2014, ChengXi Bao. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice,+ this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the author nor the names of its contributors may be+ used to endorse or promote products derived from this software without+ specific prior written permission.++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 OWNER 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.
Setup.hs view
@@ -1,2 +1,2 @@-import Distribution.Simple +import Distribution.Simple main = defaultMain
core-haskell.cabal view
@@ -1,23 +1,26 @@-Name: core-haskell -License: BSD3 -License-file: LICENSE -Category: Language, Compilers/Interpreters -Version: 0.6.1 -Build-Type: Simple -Synopsis: A subset of Haskell using in UCC for teaching purpose -Description: A subset of Haskell using in UCC for teaching purpose. - It enables a tiny subset of Haskell default, but the syntax can be customized, - teacher can enable more syntax along with the teaching progress. -Author: ChengXi Bao -Maintainer: ChengXi Bao <c.x.bao@student.ucc.ie> - -Cabal-Version: >= 1.16 - -executable core-haskell - main-is: core-haskell.hs - Default-Language: Haskell2010 - Build-Depends: base == 4.6.*, - haskeline, - haskell-src-exts, - hint - Buildable: True +Name: core-haskell+Cabal-Version: >= 1.14+License: BSD3+License-file: LICENSE+Category: Language, Compilers/Interpreters+Version: 0.6.2+Build-Type: Simple+Synopsis: A subset of Haskell using in UCC for teaching purpose+Description: A subset of Haskell using in UCC for teaching purpose. + It enables a tiny subset of Haskell default, but the syntax can be customized,+ teacher can enable more syntax along with the teaching progress.+Author: ChengXi Bao+Maintainer: ChengXi Bao <c.x.bao@student.ucc.ie>+Source-Repository head+ type: git+ location: https://github.com/happlebao/Core-Haskell.git+++executable core-haskell+ main-is: core-haskell.hs+ Default-Language: Haskell2010+ Build-Depends: base >= 4.5 && < 5,+ haskeline,+ haskell-src-exts,+ hint+ Buildable: True
core-haskell.hs view
@@ -1,74 +1,74 @@-module Main where - -import Data.List -import Language.Haskell.Interpreter -import SyntaxChecker -import System.Console.Haskeline -import System.Environment (getArgs) - -main :: IO () -main = do - fPath <- getFile - - case fPath of - "" -> run [] fPath - _ -> do - m <- getModule fPath - let ns = getNames m - if isCoreModule ns m then run ns fPath - else error "This is not a vaild Core Haskell Source file." - -run :: [String] -> String -> IO () -run ns fPath = runInputT defaultSettings (loop fPath) where - loop :: String -> InputT IO () - loop fp = do - minput <- getInputLine "Prelude> " - case minput of - Nothing -> return () - Just "quit" -> return () - Just input -> do - rst <- liftIO (evaluate ns fp input) - outputStrLn $ "Result: " ++ rst - loop fp - -getFile :: IO String -getFile = do - args <- getArgs - case args of - [] -> return "" - [fPath] -> return - (if ".hs" `isSuffixOf` fPath then fPath - else error "This is not a vaild haskell source file.") - _ -> return (error "You can't supply more than one file.") - -evaluate :: [String] -> String -> String -> IO String -evaluate ns fPath expr = do - r <- runInterpreter (evaluate' ns fPath expr) - case r of - Left err -> return (show err) - Right rst -> return rst - - -evaluate' :: [String] -> String -> String -> InterpreterT IO String -evaluate' ns fPath expr = do - -- you can't end with ...hs\ or ...hs/ - let mPath = take (length fPath -3) fPath - case mPath of - "" -> evalExpr expr - _ -> do - loadFile mPath - --liftIO (putStrLn ("Module Loaded: " ++ mPath)) - evalExpr expr - where - -- Only test with current directory - loadFile mPath = do - loadModules [mPath ++ ".hs"] - -- todo handle custom module name, instead of harded coded Main - setTopLevelModules ["Main"] - --getModuleExports mPath - evalExpr expression = - if isCoreExpression ns expr then do - setImportsQ [("Prelude", Nothing)] - result <- eval expression - return (show result) - else error "This is not a vaild haskell statement" +module Main where++import Data.List+import Language.Haskell.Interpreter+import SyntaxChecker+import System.Console.Haskeline+import System.Environment (getArgs)++main :: IO ()+main = do+ fPath <- getFile++ case fPath of+ "" -> run [] fPath+ _ -> do+ m <- getModule fPath+ let ns = getNames m+ if isCoreModule ns m then run ns fPath+ else error "This is not a vaild Core Haskell Source file."++run :: [String] -> String -> IO ()+run ns fPath = runInputT defaultSettings (loop fPath) where+ loop :: String -> InputT IO ()+ loop fp = do+ minput <- getInputLine "Prelude> "+ case minput of+ Nothing -> return ()+ Just "quit" -> return ()+ Just input -> do+ rst <- liftIO (evaluate ns fp input)+ outputStrLn $ "Result: " ++ rst+ loop fp++getFile :: IO String+getFile = do+ args <- getArgs+ case args of+ [] -> return ""+ [fPath] -> return+ (if ".hs" `isSuffixOf` fPath then fPath+ else error "This is not a vaild haskell source file.")+ _ -> return (error "You can't supply more than one file.")++evaluate :: [String] -> String -> String -> IO String+evaluate ns fPath expr = do+ r <- runInterpreter (evaluate' ns fPath expr)+ case r of+ Left err -> return (show err)+ Right rst -> return rst+++evaluate' :: [String] -> String -> String -> InterpreterT IO String+evaluate' ns fPath expr = do+ -- you can't end with ...hs\ or ...hs/+ let mPath = take (length fPath -3) fPath+ case mPath of+ "" -> evalExpr expr+ _ -> do+ loadFile mPath+ --liftIO (putStrLn ("Module Loaded: " ++ mPath))+ evalExpr expr+ where+ -- Only test with current directory+ loadFile mPath = do+ loadModules [mPath ++ ".hs"]+ -- todo handle custom module name, instead of harded coded Main+ setTopLevelModules ["Main"]+ --getModuleExports mPath+ evalExpr expression = + if isCoreExpression ns expr then do+ setImportsQ [("Prelude", Nothing)]+ result <- eval expression+ return (show result)+ else error "This is not a vaild haskell statement"