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 operator lexing #35

Merged
merged 10 commits into from
Jun 25, 2024
Merged

Add operator lexing #35

merged 10 commits into from
Jun 25, 2024

Conversation

adamhutchings
Copy link
Contributor

No description provided.

@adamhutchings
Copy link
Contributor Author

Do not want to merge yet until token type identification is fixed.

@TheCrystalKeeper
Copy link
Collaborator

TheCrystalKeeper commented Jun 25, 2024

Seems like it doesn't break anything, but I'm convinced that the code

        ungetc(c, l->fp);
        t->contents[pos - 1] = '\0';
        t->type = ttype_from_string(t->contents);
        t->length = pos;
        return 0;

doesn't need to be duplicated inside of lex()

@adamhutchings adamhutchings marked this pull request as ready for review June 25, 2024 16:46
@adamhutchings
Copy link
Contributor Author

I could #define a macro to do that, or goto an end block which would be called finalize_token or something similar. What do you think?

@TheCrystalKeeper
Copy link
Collaborator

Try adding a return 1 to those places where you want to void the values of t. Then inside of lex() if it is determined to be 1, set t appropriately. I think that makes it just clearer.

t->contents[pos++] = (c = getc(l->fp));
}
// We've ended!
// Can we reduce this code duplication from above in a smart way?
Copy link
Member

Choose a reason for hiding this comment

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

A few lines is okay imo

@adamhutchings adamhutchings merged commit d493287 into jabacat:main Jun 25, 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.

3 participants