Skip to content

Commit e16a886

Browse files
committed
added takeTok, when and get to Token module
1 parent 4ff8e97 commit e16a886

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docs/Module.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Module Text.Parsing.Parser
44

5+
6+
57
#### `ParseError`
68

79
``` purescript
@@ -159,8 +161,13 @@ fail :: forall m s a. (Monad m) => String -> ParserT s m a
159161

160162

161163

164+
165+
# Module Documentation
166+
162167
## Module Text.Parsing.Parser.Combinators
163168

169+
170+
164171
#### `(<?>)`
165172

166173
``` purescript
@@ -337,8 +344,13 @@ many1Till :: forall s a m e. (Monad m) => ParserT s m a -> ParserT s m e -> Pars
337344

338345

339346

347+
348+
# Module Documentation
349+
340350
## Module Text.Parsing.Parser.Expr
341351

352+
353+
342354
#### `Assoc`
343355

344356
``` purescript
@@ -430,8 +442,13 @@ buildExprParser :: forall m s a. (Monad m) => OperatorTable m s a -> ParserT s m
430442

431443

432444

445+
446+
# Module Documentation
447+
433448
## Module Text.Parsing.Parser.String
434449

450+
451+
435452
#### `eof`
436453

437454
``` purescript
@@ -489,8 +506,34 @@ noneOf :: forall s m a. (Monad m) => [String] -> ParserT String m String
489506

490507

491508

509+
510+
# Module Documentation
511+
492512
## Module Text.Parsing.Parser.Token
493513

514+
515+
516+
#### `takeTok`
517+
518+
``` purescript
519+
takeTok :: forall m a. (Monad m) => ParserT [a] m a
520+
```
521+
522+
523+
#### `when`
524+
525+
``` purescript
526+
when :: forall m a. (Monad m) => (a -> Boolean) -> ParserT [a] m a
527+
```
528+
529+
530+
#### `get`
531+
532+
``` purescript
533+
get :: forall a m. (Monad m, Eq a) => a -> ParserT [a] m a
534+
```
535+
536+
494537
#### `LanguageDef`
495538

496539
``` purescript
@@ -502,4 +545,8 @@ type LanguageDef s m = { caseSensitive :: Boolean, reservedOpNames :: [String],
502545

503546
``` purescript
504547
type TokenParser s m = { commaSep1 :: forall a. ParserT s m a -> ParserT s m [a], commaSep :: forall a. ParserT s m a -> ParserT s m [a], semiSep1 :: forall a. ParserT s m a -> ParserT s m [a], semiSep :: forall a. ParserT s m a -> ParserT s m [a], dot :: ParserT s m String, colon :: ParserT s m String, comma :: ParserT s m String, semi :: ParserT s m String, brackets :: forall a. ParserT s m a -> ParserT s m a, angles :: forall a. ParserT s m a -> ParserT s m a, braces :: forall a. ParserT s m a -> ParserT s m a, parens :: forall a. ParserT s m a -> ParserT s m a, whiteSpace :: ParserT s m { }, lexme :: forall a. ParserT s m a -> ParserT s m a, symbol :: String -> ParserT s m Number, octal :: ParserT s m Number, hexadecimal :: ParserT s m Number, decimal :: ParserT s m Number, naturalOrFloat :: ParserT s m Number, float :: ParserT s m Number, integer :: ParserT s m Number, natural :: ParserT s m Number, stringLiteral :: ParserT s m String, charLiteral :: ParserT s m String, reservedOp :: String -> ParserT s m String, operator :: ParserT s m String, reserved :: String -> ParserT s m String, identifier :: ParserT s m String }
505-
```
548+
```
549+
550+
551+
552+

src/Text/Parsing/Parser/Token.purs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Text.Parsing.Parser.Token where
22

33
import Data.String
4+
import Data.Either
45

56
import Control.Monad.State.Class
67
import Control.Monad.Error.Class
@@ -9,6 +10,26 @@ import Text.Parsing.Parser
910
import Text.Parsing.Parser.String
1011
import Text.Parsing.Parser.Combinators
1112

13+
takeTok :: forall m a. (Monad m) => ParserT [a] m a
14+
takeTok = ParserT $ \s ->
15+
return $ case s of
16+
x:xs -> {consumed: true,
17+
input: xs,
18+
result: Right x}
19+
_ -> {consumed: false,
20+
input: s,
21+
result: Left (ParseError {message: "there is nothing in 'takeTok'"})}
22+
23+
when :: forall m a. (Monad m) => (a -> Boolean) -> ParserT [a] m a
24+
when f = try $ do
25+
a <- takeTok
26+
if f a then return a
27+
else fail "token doesn't satisfy when test"
28+
29+
get :: forall a m. (Monad m, Eq a) => a -> ParserT [a] m a
30+
get token = when ((==) token)
31+
32+
1233
type LanguageDef s m = {
1334
commentStart :: String,
1435
commentEnd :: String,

0 commit comments

Comments
 (0)