summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2012-05-14 22:13:30 +1000
committerJed Barber <jjbarber@y7mail.com>2012-05-14 22:13:30 +1000
commit8e9f71bbec90d74390cae13db6f091bc5609f79e (patch)
tree838cf32c9742151d095c0903cfe2e34f9bdea52e
parentca22154af94bb260c812af4e11441b5a79790575 (diff)
Moved a number of article format parsing functions to a separate file
-rw-r--r--Parse.hs45
-rw-r--r--Semantic.hs22
-rw-r--r--Syntactic.hs25
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