Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parens, squareBrackets, braces, envelopes, bananas are not actually lazy when parsing an input string #90

Open
changlinli opened this issue Sep 20, 2018 · 3 comments

Comments

@changlinli
Copy link

All the derived specializations of bracket aren't actually lazy in their argument when the generated parser is finally applied to some string. This prevents me from writing mutually recursive parsers that make use of any of these specializations of bracket as they will promptly enter an infinite loop when asked to parse any string.

import atto._
import Atto._

def dummyParser: Parser[Char] = {println("activate!"); char('a')}

// Prints activate!
parens(dummyParser).parseOnly("notparentheses")

def myParens[A](p: => Parser[A]): Parser[A] =
  bracket(char('('), p, char(')')) // Notice the absence of named

// Does not print anything
myParens(dummyParser).parseOnly("notparentheses")
@changlinli changlinli changed the title parens, squareBrackets, braces, envelopes, bananas are not actually lazy parens, squareBrackets, braces, envelopes, bananas are not actually lazy when parsing an input string Sep 20, 2018
@tpolecat
Copy link
Owner

Thanks, I'll have a look. This is a port of a lazy library and there are strictness issues buried here and there.

@changlinli
Copy link
Author

FWIW I'm pretty sure the evaluation here is "accidental" in the sense that what's being forced is ultimately the toString method rather than the parsing itself.

@tpolecat
Copy link
Owner

Yep yep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants