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

Use class Peekable for parser #228

Merged
merged 15 commits into from
Jan 20, 2025

Conversation

neuroevolutus
Copy link
Contributor

@neuroevolutus neuroevolutus commented Jan 19, 2025

This pull request adds a class Peekable which augments an argument Iterator with a peek method. The parser now takes as input an instance of class Peekable that produces a series of tokens rather than relying on a materialised list of tokens. For right now, tokenize is altered to wrap the returned list of tokens in an instance of class Peekable, but, with another PR, we should be able to complete issue #84 and make the lexer fully pull-driven by turning it into a proper Iterator, which we would wrap within an instance of class Peekable.

scrapscript.py Outdated
return String(token.value)
elif token == Operator("..."):
try:
if isinstance(tokens.peek(), Name):
Copy link
Owner

Choose a reason for hiding this comment

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

This kind of stuff is really subtle and I am wondering if there is a way we can clean it up somehow. Maybe some kind of have_tokens() function? :/

@tekknolagi tekknolagi merged commit 0b27487 into tekknolagi:trunk Jan 20, 2025
45 of 47 checks passed
@tekknolagi
Copy link
Owner

Great stuff! Thank you!

@tekknolagi tekknolagi deployed to scrapscript-pr-228 January 20, 2025 21:27 — with GitHub Actions Active
@neuroevolutus neuroevolutus deleted the use-peekable-for-parser branch January 20, 2025 21:35
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