Beispiel #1
0
func countSpaces(lx *Lexer) int {
	spaces := 0
	for ; common.IsSpace(lx.curChar); lx.nextChar() {
		spaces += common.SpaceAmount(lx.curChar)
	}
	return spaces
}
Beispiel #2
0
func trySpace(lx *Lexer) (tok common.Token, moved bool) {
	atStart := lx.srcBuf.AtStartOfLine() && lx.inParens <= 0
	if common.IsSpace(lx.curChar) || atStart {
		mark := lx.srcBuf.NewMark()
		tok, moved = lx.newSpaceTok(mark, countSpaces(lx), atStart), true
		lx.srcBuf.NotAtStartOfLine()
	}
	return
}
Beispiel #3
0
/// HasSpaceAround - return:
///   -1 for front space only
///   +1 for back space only
///    0 for front and back being equal
func (tok *SimpleToken) HasSpaceAround() int {
	line := tok.WholeLine()
	// look for space before token:
	front := 0
	col := tok.StartColumn() - 1
	if col < 0 || common.IsSpace(line[col]) {
		front = 1
	}

	// look for space after token:
	back := 0
	col = tok.StartColumn() + len(tok.Content())
	if col >= len(line) || common.IsSpace(line[col]) {
		back = 1
	}

	return back - front
}