Code cleanup.
This commit is contained in:
parent
62cd84bb74
commit
548289560b
|
@ -149,18 +149,18 @@ func (tokenAPI *API) Fork() int {
|
|||
if cap(frames) < (newStackLevel + 1) {
|
||||
newFrames := make([]stackFrame, cap(frames)*2)
|
||||
copy(newFrames, frames)
|
||||
frames = newFrames
|
||||
tokenAPI.stackFrames = newFrames
|
||||
}
|
||||
|
||||
parent := tokenAPI.stackFrame
|
||||
frames[newStackLevel] = stackFrame{
|
||||
tokenAPI.stackFrames[newStackLevel] = stackFrame{
|
||||
offset: parent.offset,
|
||||
bytesStart: parent.bytesEnd,
|
||||
bytesEnd: parent.bytesEnd,
|
||||
tokenStart: parent.tokenEnd,
|
||||
tokenEnd: parent.tokenEnd,
|
||||
}
|
||||
tokenAPI.stackFrame = &frames[newStackLevel]
|
||||
tokenAPI.stackFrame = &tokenAPI.stackFrames[newStackLevel]
|
||||
|
||||
return newStackLevel
|
||||
}
|
||||
|
@ -205,16 +205,19 @@ func (tokenAPI *API) Merge(stackLevel int) {
|
|||
parent.tokenEnd = f.tokenEnd
|
||||
f.tokenStart = f.tokenEnd
|
||||
|
||||
// Update the parent read offset.
|
||||
parent.offset = f.offset
|
||||
|
||||
// Update the parent cursor position.
|
||||
if f.line > parent.line {
|
||||
parent.line += f.line
|
||||
parent.column = f.column
|
||||
} else {
|
||||
parent.column += f.column
|
||||
}
|
||||
|
||||
f.line = 0
|
||||
f.column = 0
|
||||
|
||||
f.err = nil
|
||||
}
|
||||
|
||||
|
@ -223,32 +226,19 @@ func (tokenAPI *API) Merge(stackLevel int) {
|
|||
// cleared as well.
|
||||
func (tokenAPI *API) Reset() {
|
||||
f := tokenAPI.stackFrame
|
||||
if tokenAPI.stackLevel == 0 {
|
||||
f.column = 0
|
||||
f.line = 0
|
||||
f.offset = 0
|
||||
} else {
|
||||
parent := tokenAPI.stackFrames[tokenAPI.stackLevel-1]
|
||||
f.column = 0
|
||||
f.line = 0
|
||||
f.offset = parent.offset
|
||||
}
|
||||
f.bytesEnd = f.bytesStart
|
||||
f.tokenEnd = f.tokenStart
|
||||
f.column = 0
|
||||
f.line = 0
|
||||
if tokenAPI.stackLevel == 0 {
|
||||
f.offset = 0
|
||||
} else {
|
||||
f.offset = tokenAPI.stackFrames[tokenAPI.stackLevel-1].offset
|
||||
}
|
||||
f.err = nil
|
||||
}
|
||||
|
||||
func (tokenAPI *API) Dispose(stackLevel int) {
|
||||
if stackLevel == 0 {
|
||||
callerPanic("Dispose", "tokenize.API.{name}(): {name}() called at {caller} "+
|
||||
"on the top-level API stack level 0")
|
||||
}
|
||||
if stackLevel != tokenAPI.stackLevel {
|
||||
callerPanic("Dispose", "tokenize.API.{name}(): {name}() called at {caller} "+
|
||||
"on API stack level %d, but the current stack level is %d "+
|
||||
"(forgot to Dispose() a forked child?)", stackLevel, tokenAPI.stackLevel)
|
||||
}
|
||||
|
||||
tokenAPI.stackLevel = stackLevel - 1
|
||||
tokenAPI.stackFrame = &tokenAPI.stackFrames[stackLevel-1]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue