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

Add the generalized Pratt parsing example #277

Open
wants to merge 41 commits into
base: hkmc2
Choose a base branch
from

Conversation

chengluyu
Copy link
Member

No description provided.

Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the test outputs are not up to date.


module Iter with ...

fun derive(iterable, makeNext) = Iterable of () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is quite confusing. Why not

Suggested change
fun derive(iterable, makeNext) = Iterable of () =>
fun adaptIterator(iterable, makeNext) = Iterable of () =>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why does it require all callers to wrap things in an obfuscating () =>?

Copy link
Member Author

@chengluyu chengluyu Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're referring to the second parameter. This function takes the old iterator and produces a function that is going to be used as the next method on the new iterator. That's why it's called makeNext.

In summary, the function derive does the following things:

  • takes an Iterable,
  • creates an iterator by calling its Symbol.iterator,
  • passed the iterator to makeNext, and
  • uses the produced function as the next method on the new iterator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I didn't use the Commit suggestion feature to make the changes because the references below also needs to be updated.)

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

Successfully merging this pull request may close these issues.

2 participants