-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
refactor(tokenizer): Use explicit offsets for locations #402
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ const DEFAULT_BUFFER_WATERLINE = 1 << 16; | |
export class Preprocessor { | ||
public html = ''; | ||
private pos = -1; | ||
private lastGapPos = -1; | ||
// NOTE: Initial `lastGapPos` is -2, to ensure `col` on initialisation is 0 | ||
private lastGapPos = -2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would complicate things quite a bit. The issue here is the check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private gapStack: number[] = []; | ||
private skipNextNewLine = false; | ||
private lastChunkWritten = false; | ||
|
@@ -106,7 +107,7 @@ export class Preprocessor { | |
this.lineStartPos -= this.pos; | ||
this.droppedBufferSize += this.pos; | ||
this.pos = 0; | ||
this.lastGapPos = -1; | ||
this.lastGapPos = -2; | ||
this.gapStack.length = 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.
not
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.
The doubly negated offset makes things a bit difficult here. An offset of
+1
means "start one character ago".-1
means "start one character after our last seen one".The preprocessor is initiated at position
-1
. We access the location here before we read anything, so have to give a negative offset of-1
to get the position of the first character in the input. The same is done again in_emitCurrentToken
.I have played with flipping the sign of
getCurrentLocation
'soffset
, but then other places are hard to read.