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

Weird behavior with flatten? #5

Closed
kevmoo opened this issue Apr 5, 2013 · 2 comments
Closed

Weird behavior with flatten? #5

kevmoo opened this issue Apr 5, 2013 · 2 comments

Comments

@kevmoo
Copy link
Contributor

kevmoo commented Apr 5, 2013

I'd expect this to pass (copy-paste into core_test.dart).

Thoughts?

test('foo', () {
  var letterLine = letter().plus().flatten().seq(Token.newlineParser())
      .pick(0);

  var parser = digit().plus().seq(letterLine).flatten();
  expectSuccess(parser, '123abc\n', '123abc');
});
@kevmoo
Copy link
Contributor Author

kevmoo commented Apr 5, 2013

Perhaps I'm confused by the behavior of flatten.

In the above code, if you remove flatten() at the end of var parser = one gets

[[1, 2, 3], abc]

The newline was consumed, but it was excluded by a pick.

My naive view would be that flatten would take whatever it's given and, well, flatten the strings.

The fact that it uses the starting and ending parse positions to get a substring is weird...at least to me.

...but I'm new to this.

@renggli
Copy link
Member

renggli commented Apr 5, 2013

The following parser makes your test pass:

var parser = digit().plus()
    .seq(letter().plus())
    .flatten()
      .seq(Token.newlineParser())
      .pick(0);

Regarding the behavior of flatten please check the docs and let me know if something is unclear. To process and join the strings you cold use map and join along the following snippet:

digit().plus().map((List list) => list.join())

@renggli renggli closed this as completed Apr 5, 2013
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