Skip to content

Commit

Permalink
Slow (char-by-char) version of string parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
steshaw committed Jun 16, 2017
1 parent 875e44a commit b8e0418
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion haskell/nix-derivation-parser/parser.hs
Expand Up @@ -15,6 +15,9 @@ import qualified Data.Map
import qualified Data.Set
import qualified Data.Vector
import qualified Data.Attoparsec.Text.Lazy
import qualified Data.Text as T

import Control.Applicative ((<|>))

data Derivation = Derivation
{ outputs :: Map Text DerivationOutput -- ^ keyed on symbolic IDs
Expand Down Expand Up @@ -58,10 +61,21 @@ mapOf keyValue = do
pure $ Data.Map.fromList keyValues

string :: Parser Text
string = todo
string = do
void "\""
s <- Data.Attoparsec.Text.Lazy.many1 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

filepath :: Parser FilePath
filepath = todo
-- path = '"/', { char }, '"'

parseDerivation :: Parser Derivation
parseDerivation = do
Expand Down

0 comments on commit b8e0418

Please sign in to comment.