sparsec

simple Haskell parser combinator library
git clone git://git.rr3.xyz/sparsec
Log | Files | Refs | README | LICENSE

commit 2adfe1e78c53e130e138f0d44f894d5a0edfad46
parent 4039f027a606a2a044a862a610eca7e4dc934020
Author: Robert Russell <robert@rr3.xyz>
Date:   Tue, 27 Aug 2024 00:01:46 -0700

Delete lex{,M}

It's cool, but unnecessary once you have bytesOf. Maybe it's still
worthwhile to have a state machine-like parser combinator; we'll
see if we ever end up wanting it.

Diffstat:
MSparsec.hs | 36------------------------------------
1 file changed, 0 insertions(+), 36 deletions(-)

diff --git a/Sparsec.hs b/Sparsec.hs @@ -355,39 +355,3 @@ natural = \case numeral >>= iter (\n -> (nat b * n +) <$> (underscores *> numeral)) _ -> error "natural: invalid base" - -data LexAction e t s - = LexFail - | LexError e - | LexRejectEmit t -- Reject rune and emit token. - | LexAcceptCont s -- Accept rune and continue lexing in the given state. - --- TODO: Delete this. --- lexM (and it's non-monadic counterpart lex) lexes a token (of some type t) --- in the manner of an automaton. That is, given a start state (of some type --- s) and a transition function that maps (s, Rune) pairs to "actions", lexM --- tracks the current state and repeatedly calls the transition function with --- runes from the input until it returns an action indicating it should stop. -lexM :: forall m e t s. (Utf8Error e, Monad m) - => s - -> ((s, Rune) -> m (LexAction e t s)) - -> ParseT e m (ByteString, t) -lexM startState trans = do - (input, beg) <- save - let gobble :: s -> ParseT e m t - gobble s = do - r <- lookahead nextRune - (lift $ trans (s, r)) >>= \case - LexFail -> fail - LexError e -> err e - LexRejectEmit t -> pure t - LexAcceptCont s -> nextRune *> gobble s - t <- gobble startState - end <- getLoc - pure (ByteString.take (end.byte - beg.byte) input, t) - -lex :: (Utf8Error e, Monad m) - => s - -> ((s, Rune) -> LexAction e t s) - -> ParseT e m (ByteString, t) -lex startState trans = lexM startState (pure . trans)