parser
-- import "github.com/robertkrimen/otto/parser"
Package parser implements a parser for JavaScript.
Parse and return an AST
Warning
The parser and AST interfaces are still works-in-progress (particularly where node types are concerned) and may change in the future.
Usage
func ParseFile
ParseFile parses the source code of a single JavaScript/ECMAScript source file and returns the corresponding ast.Program node.
If fileSet == nil, ParseFile parses source without a FileSet. If fileSet != nil, ParseFile first adds filename and src to fileSet.
The filename argument is optional and is used for labelling errors, etc.
src may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST always be in UTF-8.
func ParseFunction
ParseFunction parses a given parameter list and body as a function and returns the corresponding ast.FunctionLiteral node.
The parameter list, if any, should be a comma-separated list of identifiers.
func ReadSource
func TransformRegExp
TransformRegExp transforms a JavaScript pattern into a Go "regexp" pattern.
re2 (Go) cannot do backtracking, so the presence of a lookahead (?=) (?!) or backreference (\1, \2, ...) will cause an error.
re2 (Go) has a different definition for \s: [\t\n\f\r ]. The JavaScript definition, on the other hand, also includes \v, Unicode "Separator, Space", etc.
If the pattern is invalid (not valid even in JavaScript), then this function returns the empty string and an error.
If the pattern is valid, but incompatible (contains a lookahead or backreference), then this function returns the transformation (a non-empty string) AND an error.
type Error
An Error represents a parsing error. It includes the position where the error occurred and a message/description.
func (Error) Error
type ErrorList
ErrorList is a list of *Errors.
func (*ErrorList) Add
Add adds an Error with given position and message to an ErrorList.
func (ErrorList) Err
Err returns an error equivalent to this ErrorList. If the list is empty, Err returns nil.
func (ErrorList) Error
Error implements the Error interface.
func (ErrorList) Len
func (ErrorList) Less
func (*ErrorList) Reset
Reset resets an ErrorList to no errors.
func (ErrorList) Sort
func (ErrorList) Swap
type Mode
A Mode value is a set of flags (or 0). They control optional parser functionality.
-- godocdown http://github.com/robertkrimen/godocdown
Last updated