mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
![]() This patch implements source map support in the parser, the runtime, the script record, and the stack trace printing. The library used to parse and use the source maps is gopkg.in/sourcemap.v1. Unlike earlier versions of this patch, the consumer of otto does not need parse the source map on their own - it's now handled similarly to parsing JavaScript content. To use a source map, the consumer must explicitly parse their source into a `Script` object with `Otto.CompileWithSourceMap`. The script record returned from that call will carry source map information with it, and all location-related functions should reflect the original source positions. |
||
---|---|---|
.. | ||
file.go | ||
README.markdown |
file
-- import "github.com/robertkrimen/otto/file"
Package file encapsulates the file abstractions used by the ast & parser.
Usage
type File
type File struct {
}
func NewFile
func NewFile(filename, src string, base int) *File
func (*File) Base
func (fl *File) Base() int
func (*File) Name
func (fl *File) Name() string
func (*File) Source
func (fl *File) Source() string
type FileSet
type FileSet struct {
}
A FileSet represents a set of source files.
func (*FileSet) AddFile
func (self *FileSet) AddFile(filename, src string) int
AddFile adds a new file with the given filename and src.
This an internal method, but exported for cross-package use.
func (*FileSet) File
func (self *FileSet) File(idx Idx) *File
func (*FileSet) Position
func (self *FileSet) Position(idx Idx) *Position
Position converts an Idx in the FileSet into a Position.
type Idx
type Idx int
Idx is a compact encoding of a source position within a file set. It can be converted into a Position for a more convenient, but much larger, representation.
type Position
type Position struct {
Filename string // The filename where the error occurred, if any
Offset int // The src offset
Line int // The line number, starting at 1
Column int // The column number, starting at 1 (The character count)
}
Position describes an arbitrary source position including the filename, line, and column location.
func (*Position) String
func (self *Position) String() string
String returns a string in one of several forms:
file:line:column A valid position with filename
line:column A valid position without filename
file An invalid position with filename
- An invalid position without filename
-- godocdown http://github.com/robertkrimen/godocdown