hlint feedback

Applicative-style parser.
This commit is contained in:
Steven Dee 2013-10-20 19:15:20 -04:00
parent 52f29e70d4
commit 2c5c979ec9
2 changed files with 8 additions and 9 deletions

View File

@ -1,5 +1,6 @@
module Nock5K.Parse (noun) where
import Control.Applicative ((<$>))
import Nock5K.Spec
import Text.ParserCombinators.Parsec
@ -13,13 +14,10 @@ noun :: Parser Noun
noun = atom <|> cell
atom :: Parser Noun
atom = many1 digit >>= (return . Atom . read)
atom = (Atom . read) <$> many1 digit
cell :: Parser Noun
cell = do
char '['
a <- noun
char ' '
bs <- noun `sepBy1` char ' '
char ']'
return $ foldr1 (:-) (a:bs)
cell = foldr1 (:-) <$> noun `sepBy2` char ' ' `surroundBy` "[]"
where
p `sepBy2` sep = do { a <- p; sep; bs <- p `sepBy1` sep; return (a:bs) }
p `surroundBy` (s:e:_) = do { char s; a <- p; char e; return a }

View File

@ -1,3 +1,4 @@
> module Nock5K.Spec (Noun (Atom, (:-)), nock) where
1 Structures
@ -110,7 +111,7 @@
> tar (a :- Atom 6 :- b :- c :- d) =
> tar (a :- Atom 2 :- (Atom 0 :- Atom 1) :- Atom 2 :- (Atom 1 :- c :- d) :-
> (Atom 1 :- Atom 0) :- (Atom 2) :- (Atom 1 :- Atom 2 :- Atom 3) :-
> (Atom 1 :- Atom 0) :- Atom 2 :- (Atom 1 :- Atom 2 :- Atom 3) :-
> (Atom 1 :- Atom 0) :- Atom 4 :- Atom 4 :- b)
*[a 7 b c] *[a 2 b 1 c]