refactored to add lexemes

This commit is contained in:
macocianradu
2021-10-16 18:22:36 +02:00
parent 4b49051b61
commit 51c625b74b
8 changed files with 76 additions and 212 deletions

View File

@@ -13,41 +13,33 @@ type Parser = Parsec Void Text
spaceConsumer :: Parser ()
spaceConsumer = L.space space1 (L.skipLineComment "//") (L.skipBlockComment "/*" "*/")
symbol :: Text -> Parser Text
symbol = L.symbol spaceConsumer
lexeme :: Parser a -> Parser a
lexeme = L.lexeme spaceConsumer
descriptionParser :: Parser String
descriptionParser =
do
_ <- string "<\""
description <- anySingle `manyTill` string "\">"
_ <- spaceConsumer
return description
lexeme $ anySingle `manyTill` string "\">"
pascalNameParser :: Parser String
pascalNameParser =
do
first <- upperChar
rest <- many (letterChar <|> digitChar <|> char '_')
_ <- spaceConsumer
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
return (first : rest)
camelNameParser :: Parser String
camelNameParser =
do
first <- lowerChar
rest <- many (letterChar <|> digitChar <|> char '_')
_ <- spaceConsumer
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
return (first : rest)
nameParser :: Parser String
nameParser =
do
first <- letterChar <|> char '_'
rest <- many (letterChar <|> digitChar <|> char '_')
_ <- spaceConsumer
return (first:rest)
untilParser :: String -> Parser String
untilParser x = try (anySingle `manyTill` string (pack x))
rest <- lexeme $ many (letterChar <|> digitChar <|> char '_')
return (first:rest)