Giter Club home page Giter Club logo

Comments (5)

benrbray avatar benrbray commented on August 13, 2024 1

No worries! I'll do some of my own digging and post any updates here.

from parser-ts.

IMax153 avatar IMax153 commented on August 13, 2024 1

@benrbray - I tracked down the issue. Essentially, the issue stems from the Parser's many combinator, which is used internally by the many combinator in the string module. This combinator has been notorious for causing issues with infinite recursion in the past.

I believe I have figured out a fix to the recursion issue which allows the many combinators to handle infinitely large iterations. Will be pushing a PR soon.

from parser-ts.

IMax153 avatar IMax153 commented on August 13, 2024

Hey @benrbray! Thanks for letting us know!

Unfortunately, I am unable to replicate the recursion issue. For context, here is a CodeSandbox containing the code you posted above. If you check the console, you'll see that all four parsers run as expected.

In addition, we have regression tests in place for the fix for #41 that are currently passing:

parser-ts/test/string.ts

Lines 30 to 42 in 4d58e69

it('should handle long strings without exceeding the recursion limit (#41)', () => {
const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
const target = intercalate(monoidString, RA.Foldable)(' ', RA.replicate(1000, lorem))
const source = intercalate(monoidString, RA.Foldable)(' ', RA.replicate(10000, lorem))
const cursor = target.length
const parser = S.string(target)
assert.deepStrictEqual(
S.run(source)(parser),
success(target, stream(source.split(''), cursor), stream(source.split('')))
)
})
})

Could you perhaps provide more context?

from parser-ts.

benrbray avatar benrbray commented on August 13, 2024

Thanks for the quick reply! I think this will be slightly system- and browser-dependent. I tested in a few different environments:

  • Ubuntu / Chrome v87 -- stack overflow at string length 1000
  • Ubuntu / Firefox v1.0 -- works at length 1000, stack overflow at 2000
  • Windows 10 / Chrome v89 -- works at length 1000, stack overflow at 2000
  • MacOS / Safari 14 via BrowserStack -- works at length 1000, stack overflow at 2000

Are you able to reproduce the error on strings of say, length 10000?

As for solutions, I haven't dug too much into the parser-ts internals yet, but I wonder if it's possible to write a many sat function specialized to strings that avoids recursion by directly iterating over characters. I'm not sure whether that sort of approach would be compatible with Stream, though.

from parser-ts.

IMax153 avatar IMax153 commented on August 13, 2024

Hey @benrbray - I was in fact able to replicate it when I increased the string length to 10,000. However, I am not really sure where the errors are originating from. I will need to do some further work on this but don't have too much time in the near future so this one might take a bit.

from parser-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.