-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
Would close issue #8 |
last commit would close #32 |
src/lexer/token.h
Outdated
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(l->position >= 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful!
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