Comments (8)
or
sepEndBy' :: m a -> m (Either String a)
sepEndBy' sep = sep <|> (fmap mconcat $ manyTill anyChar sep)
inefficient because sep has to match twice for each pattern, but still maybe something useful here?
from replace-megaparsec.
how about skipManyTill
?
sepEndBy' :: m a -> m (String, a)
sepEndBy' sep = do
getOffset <- off1
skipManyTill $ do
off2 <- getOffset
x <- sep
return (stringSectionBetween off1 off2, x)
// and what about when we come to the end of the stream?
from replace-megaparsec.
from replace-megaparsec.
See also @chshersh 's issue:
from replace-megaparsec.
So here's the thing. Parsers such as takeWhileP
are based on span
, which has type
span :: (Char -> Bool) -> Text -> (Text, Text)
The problem is the predicate only takes one char.
There is also breakOn
which is predicated on a constant string.
What we need to write a sepCap
which is fast in the sparse case is a function which doesn't seems to exist in the world of Text
or ByteString
, which is like breakOn
, but predicated on the beginning of the second string in the break.
breakPred :: (Text -> Bool) -> Text -> (Text, Text)
Actually, what we want is not a predicate, because we need information about how much of the string to break on. So we need this function.
breakSatisfy :: (Text -> Maybe Int) -> Text -> (Text, Text, Text)
Let's call (Text -> Maybe Int)
the "satisfaction" function. breakSatisfy
will call the satisfaction function on each tail of the input string until the satisfaction function returns a span. Then breakSatisfy
will return the substring up until satisfaction began, the satisfying substring, and the remaining unsatisfying substring.
from replace-megaparsec.
untilCap :: Parser a -> Parser (Text, a)
Parser fails when no match. Prefix or suffix may be zero length. Zero-width match allowed?
streamSplit :: Parser a -> s -> Maybe (Text, a, Text)
Nothing when untilCap
fails.
from replace-megaparsec.
@mrkkrp mostly solved this problem this summer in v1.2.0, see manyTill_
and someTill_
.
from replace-megaparsec.
Added anyTill
for untilCap
Added splitCap
for streamSplit
from replace-megaparsec.
Related Issues (20)
- streamEdit docs HOT 1
- use gauge
- change license HOT 1
- disappeared from stackage nightly HOT 1
- shell script template HOT 1
- Safe Haskell
- Parse, don't Validate
- sepCap docs output
- utility functions
- regex-tdfa
- preg-replace-callback
- hackage says ghc-options: -O2 is rarely needed HOT 1
- anyTill HOT 1
- fast bytestring building HOT 1
- parser-combinators >= 1.2.0
- Prelude.undefined with a build executable. HOT 5
- "non-greedy" parser combinator
- Bounds for dependencies seem incorrect HOT 2
- replace-megaparsec-1.4.5.0 testsuite test-textStub crashed ghc-9.4.3 HOT 3
- Haskell Optimization Handbook
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from replace-megaparsec.