parent
5cc96cbdba
commit
f3bce99120
18 changed files with 289 additions and 103 deletions
|
@ -18,9 +18,13 @@ import Text.Parsec
|
|||
notFollowedBy,
|
||||
sepBy,
|
||||
many,
|
||||
try )
|
||||
try, spaces, endOfLine )
|
||||
import qualified Text.Parsec as P ( string )
|
||||
import Text.Parsec.String ( Parser )
|
||||
import Text.Parsec.Combinator (lookAhead)
|
||||
|
||||
gameFile :: Parser [Structure]
|
||||
gameFile = try $ do many1 $ ignoreWS structure
|
||||
|
||||
-------------------------- StructureElement --------------------------
|
||||
|
||||
|
@ -111,7 +115,7 @@ data Value = String String
|
|||
----------------------------------------------------------------------
|
||||
|
||||
value :: Parser Value
|
||||
value = choice [layout, string, integer, infinite, action, direction]
|
||||
value = choice [layout, string, integer, infinite, direction, action]
|
||||
|
||||
string :: Parser Value
|
||||
string = try $ String <$> between (char '\"') (char '\"') reading
|
||||
|
@ -149,7 +153,7 @@ direction = try $ do
|
|||
ignoreWS $ P.string "left",
|
||||
ignoreWS $ P.string "right"
|
||||
]
|
||||
notFollowedBy alphaNum
|
||||
-- lookAhead $ char ','
|
||||
return $ Direction $ make value
|
||||
where make "up" = North
|
||||
make "right" = East
|
||||
|
@ -160,15 +164,12 @@ direction = try $ do
|
|||
layout :: Parser Value
|
||||
layout = try $ do
|
||||
open <- ignoreWS $ oneOf openingBrackets
|
||||
ignoreWS $ char '|'
|
||||
list <- ignoreWS $ ignoreWS strip `sepBy` ignoreWS (char '|')
|
||||
let closing = getMatchingClosingBracket open
|
||||
ignoreWS $ char closing
|
||||
return $ Layout list
|
||||
value <- many1 strip <* ignoreWS (char closing)
|
||||
return $ Layout value
|
||||
|
||||
strip :: Parser Strip
|
||||
strip = try $ do
|
||||
physical `sepBy` char ' '
|
||||
strip = try $ do ignoreWS (char '|') *> ignoreWS (physical `sepBy` char ' ')
|
||||
|
||||
physical :: Parser Physical
|
||||
physical = try $ do
|
||||
|
|
Reference in a new issue