Beispiel #1
0
func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode uint) {
	p.file = fset.AddFile(filename, fset.Base(), len(src))
	p.scanner.Init(p.file, src, p, scannerMode(mode))
	p.mode = mode
	p.trace = mode&Trace != 0 // for convenience (p.trace is used frequently)
	p.next()
}
Beispiel #2
0
func TestNoPos(t *testing.T) {
	if token.NoPos.IsValid() {
		t.Errorf("NoPos should not be valid")
	}
	var fset *token.FileSet
	checkPos(t, "nil NoPos", fset.Position(token.NoPos), token.Position{})
	fset = token.NewFileSet()
	checkPos(t, "fset NoPos", fset.Position(token.NoPos), token.Position{})
}
Beispiel #3
0
func verifyPositions(t *testing.T, fset *token.FileSet, f *token.File, lines []int) {
	for offs := 0; offs < f.Size(); offs++ {
		p := f.Pos(offs)
		offs2 := f.Offset(p)
		if offs2 != offs {
			t.Errorf("%s, Offset: expected offset %d; got %d", f.Name(), offs, offs2)
		}
		line, col := linecol(lines, offs)
		msg := fmt.Sprintf("%s (offs = %d, p = %d)", f.Name(), offs, p)
		checkPos(t, msg, f.Position(f.Pos(offs)), token.Position{f.Name(), offs, line, col})
		checkPos(t, msg, fset.Position(p), token.Position{f.Name(), offs, line, col})
	}
}