Skip to content

Commit

Permalink
icon definition parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJustyna committed May 21, 2024
1 parent e4acca2 commit 31f7881
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 19 additions & 6 deletions app/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
iconDefinition' :: Parser String
iconDefinition' = do
_ <- symbol "icon"
_ <- symbol "\""
name <- token identifier
_ <- symbol "\""
_ <- symbol "as"
_ <- symbol "start"
return name

iconDefinition :: Parser String
iconDefinition = token iconDefinition'

0 comments on commit 31f7881

Please sign in to comment.