Documentation ¶
Index ¶
- type Index
- func (idx *Index) FromRuneOffset(offset int) (int, error)
- func (idx *Index) FromUTF16Offset(offset int) (int, error)
- func (idx *Index) LineCol(offset int) (int, int, error)
- func (idx *Index) Offset(line, col int) (int, error)
- func (idx *Index) RuneOffset(offset int) (int, error)deprecated
- func (idx *Index) ToRuneOffset(offset int) (int, error)
- func (idx *Index) ToUTF16LineCol(offset int) (int, int, error)
- func (idx *Index) ToUTF16Offset(offset int) (int, error)
- func (idx *Index) ToUnicodeLineCol(offset int) (int, int, error)
- func (idx *Index) UTF16Offset(offset int) (int, error)deprecated
- type IndexOptions
- type Positioner
- type TokenFromSource
- type VerifyToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶ added in v3.2.0
type Index struct {
// contains filtered or unexported fields
}
Index is a positional index.
func NewIndex ¶ added in v3.2.0
func NewIndex(data []byte, opt *IndexOptions) *Index
NewIndex creates a new positional index. If opt == nil, all options default to their zero values.
func (*Index) FromRuneOffset ¶ added in v3.2.0
FromRuneOffset returns a zero-based byte offset given a zero-based Unicode character offset within a file.
func (*Index) FromUTF16Offset ¶ added in v3.2.0
FromUTF16Offset returns a zero-based byte offset given a zero-based UTF-16 code unit offset within a file.
func (*Index) LineCol ¶ added in v3.2.0
LineCol returns a one-based line and one-based column offset given a zero-based byte offset within a file. It returns an error if the given offset is out of bounds.
func (*Index) Offset ¶ added in v3.2.0
Offset returns a zero-based byte offset within a file given a one-based line and one-based column offset. It returns an error if the given line and column are out of bounds.
func (*Index) RuneOffset
deprecated
added in
v3.2.0
func (*Index) ToRuneOffset ¶ added in v3.2.0
ToRuneOffset returns a zero-based Unicode character offset given a zero-based byte offset within a file.
func (*Index) ToUTF16LineCol ¶ added in v3.2.0
ToUTF16LineCol returns a one-based line and one-based col in UTF-16 code units given a zero-based byte offset within a file. It returns an error if the given offset is out of bounds.
func (*Index) ToUTF16Offset ¶ added in v3.2.0
ToUTF16Offset returns a zero-based UTF-16 code unit offset given a zero-based byte offset within a file.
func (*Index) ToUnicodeLineCol ¶ added in v3.2.0
ToUnicodeLineCol returns a one-based line and one-based col in Unicode characters given a zero-based byte offset within a file. It returns an error if the given offset is out of bounds.
func (*Index) UTF16Offset
deprecated
added in
v3.2.0
type IndexOptions ¶ added in v3.2.0
type IndexOptions struct { // Unicode flag controls if an index is build to accept UTF-8/UTF-16 rune offsets in // addition to byte offsets. // If the flag is not set, RuneOffset and UTF16Offset will always fail with an error. Unicode bool }
IndexOptions is a set of options for positional index.
type Positioner ¶
type Positioner struct {
// contains filtered or unexported fields
}
Positioner is a transformation that only changes positional information. The transformation should be initialized with the source code by calling OnCode.
func FromLineCol ¶
func FromLineCol() Positioner
FromLineCol fills the Offset field of all Position nodes by using their Line and Col.
func FromOffset ¶
func FromOffset() Positioner
FromOffset fills the Line and Col fields of all Position nodes by using their Offset.
func FromUTF16Offset ¶
func FromUTF16Offset() Positioner
FromUTF16Offset fills the Line, Col and Offset fields of all Position nodes by interpreting their Offset as a 0-based UTF-16 code unit index.
func FromUnicodeOffset ¶
func FromUnicodeOffset() Positioner
FromUnicodeOffset fills the Line, Col and Offset fields of all Position nodes by interpreting their Offset as a 0-based Unicode character index.
func (Positioner) OnCode ¶
func (t Positioner) OnCode(code string) transformer.Transformer
OnCode uses the source code to update positional information of UAST nodes.
type TokenFromSource ¶
type TokenFromSource struct { // Key is the name of the token field to update. Uses uast.KeyToken, if not set. // Only nodes with this field will be considered. Key string // Types is the list of node types that will be updated. Empty means all nodes. Types []string }
TokenFromSource extract node's token from the source code by using positional information.
func (TokenFromSource) OnCode ¶
func (t TokenFromSource) OnCode(code string) transformer.Transformer
OnCode implements transformer.CodeTransformer.
type VerifyToken ¶
type VerifyToken struct { // Key is the name of the token field to check. Uses uast.KeyToken, if not set. Key string // Types is the list of node types that will be checked. Empty means all nodes. Types []string }
VerifyToken check that node's token matches its positional information.