diff options
| -rw-r--r-- | Parse.hs | 45 | ||||
| -rw-r--r-- | Semantic.hs | 22 | ||||
| -rw-r--r-- | Syntactic.hs | 25 | 
3 files changed, 47 insertions, 45 deletions
diff --git a/Parse.hs b/Parse.hs new file mode 100644 index 0000000..769a883 --- /dev/null +++ b/Parse.hs @@ -0,0 +1,45 @@ +import Control.Monad( liftM ) +import qualified Data.Char as Char + + +getLines :: FilePath -> IO [String] +getLines = liftM lines . readFile + + +stripReturn :: String -> String +stripReturn s = if (last s == '\r') then init s else s + + +removeEscChars :: String -> String +removeEscChars [] = [] +removeEscChars (x:[]) = [x] +removeEscChars x = if (head x == '\\') +                   then (x!!1) : (removeEscChars . (drop 2) $ x) +                   else (head x) : (removeEscChars . tail $ x) + + +removeQuotes :: String -> String +removeQuotes = init . tail + + +separateBy :: String -> Char -> [String] +separateBy char list = +	let f = (\x -> if (x == char) +		           then ' ' +		           else x) +	in words . (map f) $ list + + +isComment :: String -> Bool +isComment = (==) '#' . head + + +isNumber :: String -> Bool +isNumber ('0':[]) = True +isNumber ('-':ns) +         | (ns /= [] && head ns /= '0') = isNumber ns +isNumber n = all (Char.isNumber) n + + +isName :: String -> Bool +isName s = all ((==) '"') [head s, last s] diff --git a/Semantic.hs b/Semantic.hs index 0697179..e40f4bc 100644 --- a/Semantic.hs +++ b/Semantic.hs @@ -1,4 +1,3 @@ -import Control.Monad( liftM )  import System( getArgs )  import Data.List  import qualified Data.Set as Set @@ -7,6 +6,7 @@ import TypeVar  import Term  import Theorem  import Object +import Parse @@ -70,9 +70,7 @@ parse n = Command (number n)  name :: String -> ((Stack,Dictionary,Assumptions,Theorems) -> (Stack,Dictionary,Assumptions,Theorems))  name str = \(s,d,a,t) -> -               let unQuoted = init . tail $ str -                   escaped = removeEscChars unQuoted -                   wordList = words . (map (\x -> if (x == '.') then ' ' else x)) $ escaped +               let wordList = (separateBy '.') . removeEscChars . removeQuotes $ str                     name = Name (init wordList) (last wordList)                     s' = Stack $ ObjName name : (stackList s)                 in (s',d,a,t) @@ -370,22 +368,6 @@ doSemanticCheck =      -- important to use foldl here so commands get applied in the correct order -getLines :: FilePath -> IO [String] -getLines = liftM lines . readFile - - -stripReturn :: String -> String -stripReturn s = if (last s == '\r') then init s else s - - -removeEscChars :: String -> String -removeEscChars [] = [] -removeEscChars (x:[]) = [x] -removeEscChars x = if (head x == '\\') -                   then (x!!1) : (removeEscChars . (drop 2) $ x) -                   else (head x) : (removeEscChars . tail $ x) - -  main = do        args <- getArgs        list <- getLines $ head args diff --git a/Syntactic.hs b/Syntactic.hs index 45eedda..6502c43 100644 --- a/Syntactic.hs +++ b/Syntactic.hs @@ -1,30 +1,5 @@ -import Control.Monad( liftM )  import System( getArgs )  import Text.Printf -import qualified Data.Char as Char - - -getLines :: FilePath -> IO [String] -getLines = liftM lines . readFile - - -stripReturn :: String -> String -stripReturn s = if (last s == '\r') then init s else s - - -isComment :: String -> Bool -isComment = (==) '#' . head - - -isNumber :: String -> Bool -isNumber ('0':[]) = True -isNumber ('-':ns) -         | (ns /= [] && head ns /= '0') = isNumber ns -isNumber n = all (Char.isNumber) n - - -isName :: String -> Bool -isName s = all ((==) '"') [head s, last s]  scan :: String -> String  | 
