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 next token #17

Merged
merged 7 commits into from
Jun 22, 2024
Merged

Add next token #17

merged 7 commits into from
Jun 22, 2024

Conversation

TheCrystalKeeper
Copy link
Collaborator

@TheCrystalKeeper TheCrystalKeeper commented Jun 21, 2024

Adds support for jumping to next token (avoiding block comments and single line comments). Also skips leading spaces.

Essentially, this code works by stopping on the first character that is not considered to be a block comment.

Possible issue: May be missing an edge case where the wrong place is returned in the case of#include <folder/file>. Will fix later if confirmed. Fixed.

@TheCrystalKeeper TheCrystalKeeper marked this pull request as draft June 21, 2024 00:33
src/lexer/lex.c Outdated
char prev;
if ((cur = fgetc(l->fp)) != EOF) {
prev = cur;
if (!(cur == ' ' || cur == '/')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about tabs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted -- Fixing now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be resolved.

src/lexer/lex.c Outdated
} else {
return -1; // file done, no more tokens
}
// read each character from the file until EOF
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having a bit of trouble understanding what this section of code (until the end of the file) is doing, to be honest. Does this correctly handle a case like

/* Comment
number one*/ /* Comment number two*/ int x = 3;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is just a check to make sure the file is not already over. If EOF is the next character, then it returns -1 meaning there are no tokens to get.

@TheCrystalKeeper TheCrystalKeeper self-assigned this Jun 21, 2024
@TheCrystalKeeper TheCrystalKeeper linked an issue Jun 21, 2024 that may be closed by this pull request
@TheCrystalKeeper TheCrystalKeeper marked this pull request as ready for review June 21, 2024 23:09
@adamhutchings adamhutchings merged commit d54f3a7 into main Jun 22, 2024
1 check passed
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.

Create a function to skip all whitespace and comments
2 participants