From 31f7881f94e07971c15824940208d8d64976a090 Mon Sep 17 00:00:00 2001 From: Piotr Justyna Date: Tue, 21 May 2024 15:56:10 +0000 Subject: [PATCH] icon definition parsing --- app/Main.hs | 3 +-- app/Parser.hs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 071c8e8..c061e22 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,9 +1,8 @@ module Main where import qualified Parser -import qualified Renderer main :: IO () main = do - print $ Parser.parse Parser.naturalNumbers " [1, 22, 333, 4444, 55555] " + print $ Parser.parse Parser.iconDefinition "icon \"starticon1\" as start" diff --git a/app/Parser.hs b/app/Parser.hs index ecf05f9..7449c9b 100644 --- a/app/Parser.hs +++ b/app/Parser.hs @@ -96,6 +96,13 @@ naturalNumbers = do _ <- symbol "[" _ <- symbol "]" return (x:xs) +token :: Parser a -> Parser a +token p = do + space + v <- p + space + return v + symbol :: String -> Parser String symbol xs = token (string xs) @@ -112,9 +119,15 @@ space = do _ <- Control.Applicative.many (sat Data.Char.isSpace) return () -token :: Parser a -> Parser a -token p = do - space - v <- p - space - return v \ No newline at end of file +iconDefinition' :: Parser String +iconDefinition' = do + _ <- symbol "icon" + _ <- symbol "\"" + name <- token identifier + _ <- symbol "\"" + _ <- symbol "as" + _ <- symbol "start" + return name + +iconDefinition :: Parser String +iconDefinition = token iconDefinition' \ No newline at end of file