Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Maximum call stack size exceeded using andThen #22

Open
pablohirafuji opened this issue Aug 14, 2017 · 1 comment
Open

Maximum call stack size exceeded using andThen #22

pablohirafuji opened this issue Aug 14, 2017 · 1 comment
Labels

Comments

@pablohirafuji
Copy link

Minimal example

module Main exposing (..)

import Html exposing (Html, text)
import Parser exposing (andThen, keyword, oneOf, run)


main =
    view (createBigFile 10000)


createBigFile n =
    String.repeat n "1"


crashWithLotsOfText =
    oneOf
        [ keyword "1"
            |> andThen (\_ -> crashWithLotsOfText)
        , Parser.end
        ]


view txt =
    run crashWithLotsOfText txt
        |> Result.mapError (always "")
        |> Result.map (always "")
        |> (toString >> text)

Changing 10000 to 1000 compiles fine.

Error message

Uncaught RangeError: Maximum call stack size exceeded

Ellie reproduction

https://ellie-app.com/42MsxddqX9ya1/0

@robx
Copy link

robx commented Jan 22, 2018

A few notes:

  • I can reproduce the problem, but I had to add another zero to the large number.
  • The analogous code for elm-community/parser-combinators crashes similarly.
  • You can parse the same language just fine using repeat zeroOrMore (keyword "1"). I would suggest that very long documents would generally have a repetitive structure, so might allow parsing using repeat.

I'm a bit curious to what extent an Elm parser combinator library with andThen necessarily exhibits this problem. It feels that due to the general type ((a -> Parser b) -> Parser a -> Parser b as opposed to e.g. (a -> Parser (List a)) -> Parser a -> Parser (List a), some form of recursion might be implied?

@evancz evancz added the problem label May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants