Commit 0fe8225a authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

Speed up parsing of character symbols

This makes lexer combinators like `colon` or `parens` a little faster,
which adds up for large inputs.
parent f3f4112f
......@@ -23,7 +23,6 @@ benchmarks = bgroup "MA.Parser.Lexer"
benchColon :: Benchmark
benchColon = bgroup "colon"
[ benchp "single" L.colon ":"
, benchp "ten" L.colon "::::::::::"
, benchp "failing" L.colon "."
]
......
......@@ -74,36 +74,40 @@ symbol :: MonadParser m => Text -> m Text
symbol = L.symbol space
{-# INLINE symbol #-}
character :: MonadParser m => Char -> m Char
character = lexeme . char
{-# INLINE character #-}
braces :: MonadParser m => m a -> m a
braces = between (symbol "{") (symbol "}")
braces = between (character '{') (character '}')
{-# INLINE braces #-}
parens :: MonadParser m => m a -> m a
parens = between (symbol "(") (symbol ")")
parens = between (character '(') (character ')')
{-# INLINE parens #-}
angles :: MonadParser m => m a -> m a
angles = between (symbol "<") (symbol ">")
angles = between (character '<') (character '>')
{-# INLINE angles #-}
brackets :: MonadParser m => m a -> m a
brackets = between (symbol "[") (symbol "]")
brackets = between (character '[') (character ']')
{-# INLINE brackets #-}
semicolon :: MonadParser m => m Text
semicolon = symbol ";"
semicolon :: MonadParser m => m Char
semicolon = character ';'
{-# INLINE semicolon #-}
comma :: MonadParser m => m Text
comma = symbol ","
comma :: MonadParser m => m Char
comma = character ','
{-# INLINE comma #-}
colon :: MonadParser m => m Text
colon = symbol ":"
colon :: MonadParser m => m Char
colon = character ':'
{-# INLINE colon #-}
dot :: MonadParser m => m Text
dot = symbol "."
dot :: MonadParser m => m Char
dot = character '.'
{-# INLINE dot #-}
name :: MonadParser m => m Text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment