github.com/neugram/ng@v0.0.0-20180309130942-d472ff93d872/syntax/src/pos.go (about)

     1  // Copyright 2017 The Neugram Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package src provides source code position tracking.
     6  package src
     7  
     8  import "fmt"
     9  
    10  // Pos is a position in a source file.
    11  type Pos struct {
    12  	Filename string // path as provided by the user
    13  	Line     int32  // line number, valid values start at 1
    14  	Column   int16
    15  }
    16  
    17  func (p Pos) String() string {
    18  	if p.Filename == "" && p.Line == 0 {
    19  		return "<unknown line>"
    20  	}
    21  	if p.Column == 0 {
    22  		return fmt.Sprintf("%s:%d", p.Filename, p.Line)
    23  	} else {
    24  		return fmt.Sprintf("%s:%d:%d", p.Filename, p.Line, p.Column)
    25  	}
    26  }