Skip to content

Commit

Permalink
Fix slowString. Still slow though :)
Browse files Browse the repository at this point in the history
  • Loading branch information
steshaw committed Jun 16, 2017
1 parent 0a4bae5 commit 61601ea
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions haskell/nix-derivation-parser/parser.hs
Expand Up @@ -89,15 +89,24 @@ mapOf keyValue = do
slowString :: Parser Text
slowString = do
void "\""
s <- Data.Attoparsec.Text.Lazy.many1 char
s <- Data.Attoparsec.Text.Lazy.many' char
void "\""
pure $ T.pack s

char :: Parser Char
char = do
void "\""; Data.Attoparsec.Text.Lazy.anyChar <|>
let notQuoteOrBackslash c = c /= '"' && c /= '\\'
in Data.Attoparsec.Text.Lazy.satisfy notQuoteOrBackslash
char = backSlashed <|> notBackslashed
where
backSlashed = do
void "\\"
c <- Data.Attoparsec.Text.Lazy.anyChar
pure $ case c of
'n' -> '\n'
'r' -> '\r'
't' -> '\t'
_ -> c
notBackslashed =
let notQuoteOrBackslash c = c /= '"' && c /= '\\'
in Data.Attoparsec.Text.Lazy.satisfy notQuoteOrBackslash

-- |
-- Faster string parser. Should be good with Attoparsec.
Expand Down Expand Up @@ -125,7 +134,7 @@ fastString = do
return $ Data.Text.Lazy.toStrict text

string :: Parser Text
string = if False then slowString else fastString
string = if True then slowString else fastString

filePath :: Parser FilePath
filePath = do
Expand Down

0 comments on commit 61601ea

Please sign in to comment.