Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JoinMaps ¶
func JoinMaps[S comparable, T comparable](target *Map[S], source *Map[T], mapping func(T) S)
JoinMaps incorporates all mappings from one source map (the source) into another source map (the target), whilst applying a given mapping to the node types.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a given source file (typically stored on disk).
func NewSourceFile ¶
NewSourceFile constructs a new source file from a given byte array.
func (*File) FindFirstEnclosingLine ¶
FindFirstEnclosingLine determines the first line in this source file which encloses the start of a span. Observe that, if the position is beyond the bounds of the source file then the last physical line is returned. Also, the returned line is not guaranteed to enclose the entire span, as these can cross multiple lines.
func (*File) SyntaxError ¶
func (s *File) SyntaxError(span Span, msg string) *SyntaxError
SyntaxError constructs a syntax error over a given span of this file with a given message.
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line provides information about a given line within the original string. This includes the line number (counting from 1), and the span of the line within the original string.
func (*Line) Number ¶
Number gets the line number of this line, where the first line in a string has line number 1.
type Map ¶
type Map[T comparable] struct { // contains filtered or unexported fields }
Map maps terms from an AST to slices of their originating string. This is important for error handling when we wish to highlight exactly where, in the original source file, a given error has arisen.
This provides various useful functions to aid reporting syntax errors, such as identifying the enclosing line for a given span, etc.
func NewSourceMap ¶
func NewSourceMap[T comparable](srcfile File) *Map[T]
NewSourceMap constructs an initially empty source map for a given string.
func (*Map[T]) Get ¶
Get determines the span associated with a given AST item extract from the original text. Note, if the item is not registered with this source map, then it will panic.
func (*Map[T]) Put ¶
Put registers a new AST item with a given span. Note, if the item exists already, then it will panic.
func (*Map[T]) SyntaxError ¶
func (p *Map[T]) SyntaxError(item T, msg string) *SyntaxError
SyntaxError constructs a syntax error for a given node contained within the source file associated with this source map.
func (*Map[T]) SyntaxErrors ¶
func (p *Map[T]) SyntaxErrors(item T, msg string) []SyntaxError
SyntaxErrors is really just a helper that construct a syntax error and then places it into an array of size one. This is helpful for situations where sets of syntax errors are being passed around.
type Maps ¶
type Maps[T comparable] struct { // contains filtered or unexported fields }
Maps provides a mechanism for mapping terms from an AST to multiple source files.
func NewSourceMaps ¶
func NewSourceMaps[T comparable]() *Maps[T]
NewSourceMaps constructs an (initially empty) set of source maps. The intention is that this is populated as each file is parsed.
func (*Maps[T]) Copy ¶
func (p *Maps[T]) Copy(from T, to T)
Copy copies the source mapping for one node to the source mapping for another. The main use of this is when an existing node is expanded into some other nodes (e.g. during preprocessing).
func (*Maps[T]) Has ¶
Has checks whether a given node has a mapping in one of the source maps embodied within.
func (*Maps[T]) Join ¶
Join a given source map into this set of source maps. The effect of this is that nodes recorded in the given source map can be accessed from this set.
func (*Maps[T]) Lookup ¶
Lookup returns the source file and span for a given node. If the node is found in any of the contained source maps, it returns the corresponding File and Span with ok=true; otherwise it returns zero values with ok=false.
func (*Maps[T]) SyntaxError ¶
func (p *Maps[T]) SyntaxError(node T, msg string) *SyntaxError
SyntaxError constructs a syntax error for a given node contained within one of the source files managed by this set of source maps.
func (*Maps[T]) SyntaxErrors ¶
func (p *Maps[T]) SyntaxErrors(node T, msg string) []SyntaxError
SyntaxErrors is really just a helper that construct a syntax error and then places it into an array of size one. This is helpful for situations where sets of syntax errors are being passed around.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents a contiguous slice of the original string. Instead of representing this as a string slice, however, it is useful to retain the physical indices. This allows us to do certain things, such as determine the enclosing line, etc.
func NewSpan ¶
NewSpan constructs a new span whilst checking the internal invariants are maintained.
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError is a structured error which retains the index into the original string where an error occurred, along with an error message.
func (*SyntaxError) Error ¶
func (p *SyntaxError) Error() string
Error implements the error interface.
func (*SyntaxError) FirstEnclosingLine ¶
func (p *SyntaxError) FirstEnclosingLine() Line
FirstEnclosingLine determines the first line in this source file to which this error is associated. Observe that, if the position is beyond the bounds of the source file then the last physical line is returned. Also, the returned line is not guaranteed to enclose the entire span, as these can cross multiple lines.
func (*SyntaxError) Message ¶
func (p *SyntaxError) Message() string
Message returns the message to be reported.
func (*SyntaxError) SourceFile ¶
func (p *SyntaxError) SourceFile() *File
SourceFile returns the underlying source file that this syntax error covers.
func (*SyntaxError) Span ¶
func (p *SyntaxError) Span() Span
Span returns the span of the original text on which this error is reported.