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 token tracking #34

Merged
merged 8 commits into from
Jun 26, 2024
Merged

add token tracking #34

merged 8 commits into from
Jun 26, 2024

Conversation

NicoBliss
Copy link
Collaborator

adds positional data to the token struct that contains where that token starts
modified the lexer struct and made getc and ungetc wrappers to keep track of location
made the lexing function store tokens with positional data

@NicoBliss
Copy link
Collaborator Author

Would close issue #8

@NicoBliss
Copy link
Collaborator Author

last commit would close #32

char contents[TOKEN_LENGTH]; // The actual contents of the token.
unsigned length; // How long the token is.
char source_file[TOKEN_LENGTH]; // The source file the token was in.
long position_in_file; // Where in the file the token started, as an index.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to get row/column info from this? If not, we should maybe switch to that so we can give helpful error messages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my plan was to have the error reporting find that. It is simpler (i think?) to just crawl to the relevant position and hold onto a few rows of buffer. plus, errors are only usually called a few times, but this is tracked for every token

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok so line and column information is now being tracked instead

src/lexer/lex.c Outdated
}

int lexer_ungetchar(Lexer *l) {
// if called before getchar ever is this could cause problems
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add an normal assert to prevent this and crash

Copy link
Member

Choose a reason for hiding this comment

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

assert(l->position >= 0);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added!

Copy link
Contributor

@adamhutchings adamhutchings left a comment

Choose a reason for hiding this comment

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

Beautiful!

@adamhutchings adamhutchings merged commit b4b8657 into jabacat:main Jun 26, 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