summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-12-17 11:34:35 +1100
committerJed Barber <jjbarber@y7mail.com>2014-12-17 11:34:35 +1100
commit2700f64b858584167fa5292c810fa67f11640e35 (patch)
tree732a713991f793d43407dd69e840159cfa33957e /src
parent92b5c479a964af8ee4ec50bba9ba8364e06156e9 (diff)
Grasp parser now more forgiving about whitespace
Diffstat (limited to 'src')
-rw-r--r--src/Grasp/Parser.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/Grasp/Parser.hs b/src/Grasp/Parser.hs
index 7274919..244bbc6 100644
--- a/src/Grasp/Parser.hs
+++ b/src/Grasp/Parser.hs
@@ -34,7 +34,7 @@ parseGrasp input =
-- removes comments but otherwise leaves input unchanged
-removeComments = gline `sepEndBy` eol >>= return . concat
+removeComments = gline `sepEndBy` eol >>= return . concat . (map (++ "\n"))
eol = try (string "\r\n")
@@ -48,12 +48,19 @@ gline = many thing >>= return . concat
thing = try (some (noneOf "\r\n\"/#"))
- <|> try (quotedString >>= return . ("\"" ++) . (++ "\""))
+ <|> try quotedNonComment
<|> try singleLineComment
<|> try multiLineComment
- <|> (anyChar >>= return . (:[]) )
+ <|> ((noneOf "\r\n") >>= return . (:[]))
+quotedNonComment = do
+ char '\"'
+ x <- many (noneOf "\r\n")
+ char '\"'
+ return ("\"" ++ x ++ "\"")
+
+
singleLineComment =
(string "//" >> many (noneOf "\r\n") >> return "")
<|> (string "#" >> many (noneOf "\r\n") >> return "")
@@ -70,13 +77,14 @@ multiLineComment = do
-- parses a DOT graph language file into the data for a grasp program
graspDOT = do
+ whiteSpace
optional strict
graphType
optional ident
openBrace
(n,e) <- stmtList ([],[])
closeBrace
- many blankLine
+ whiteSpace
eof
return (n,e)
@@ -98,13 +106,9 @@ stmtList (n,e) =
<|> try (whiteSpace >> edge >>= (\x -> stmtList (n,x:e)) )
<|> try (whiteSpace >> attr >> stmtList (n,e))
<|> try (whiteSpace >> subgraph >>= (\(x,y) -> stmtList ((reverse x) ++ n, (reverse y) ++ e)) )
- <|> try (blankLine >> stmtList (n,e))
<|> return (reverse n, reverse e)
-blankLine = whiteSpace >> eol
-
-
alphaNumString = do
a <- nonDigitChar
b <- many alphaNumChar
@@ -212,5 +216,5 @@ caseInsensitiveChar c = char (toLower c) <|> char (toUpper c)
caseInsensitiveString s = mapM caseInsensitiveChar s
-whiteSpace = many (oneOf " \t")
+whiteSpace = many (oneOf " \t\r\n")