mirror of
https://github.com/mrdomino/hsnock.git
synced 2024-09-11 13:57:42 +03:00
hlint feedback
Applicative-style parser.
This commit is contained in:
parent
52f29e70d4
commit
2c5c979ec9
@ -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 }
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user