go-ethereum/vendor/github.com/robertkrimen/otto/parser
Péter Szilágyi 289b30715d Godeps, vendor: convert dependency management to trash (#3198)
This commit converts the dependency management from Godeps to the vendor
folder, also switching the tool from godep to trash. Since the upstream tool
lacks a few features proposed via a few PRs, until those PRs are merged in
(if), use github.com/karalabe/trash.

You can update dependencies via trash --update.

All dependencies have been updated to their latest version.

Parts of the build system are reworked to drop old notions of Godeps and
invocation of the go vet command so that it doesn't run against the vendor
folder, as that will just blow up during vetting.

The conversion drops OpenCL (and hence GPU mining support) from ethash and our
codebase. The short reasoning is that there's noone to maintain and having
opencl libs in our deps messes up builds as go install ./... tries to build
them, failing with unsatisfied link errors for the C OpenCL deps.

golang.org/x/net/context is not vendored in. We expect it to be fetched by the
user (i.e. using go get). To keep ci.go builds reproducible the package is
"vendored" in build/_vendor.
2016-10-28 19:05:01 +02:00
..
dbg.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
error.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
expression.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
lexer.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
Makefile Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
parser.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
README.markdown Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
regexp.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
scope.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00
statement.go Godeps, vendor: convert dependency management to trash (#3198) 2016-10-28 19:05:01 +02:00

parser

-- import "github.com/robertkrimen/otto/parser"

Package parser implements a parser for JavaScript.

import (
    "github.com/robertkrimen/otto/parser"
)

Parse and return an AST

filename := "" // A filename is optional
src := `
    // Sample xyzzy example
    (function(){
        if (3.14159 > 0) {
            console.log("Hello, World.");
            return;
        }

        var xyzzy = NaN;
        console.log("Nothing happens.");
        return xyzzy;
    })();
`

// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
program, err := parser.ParseFile(nil, filename, src, 0)

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

func ParseFile(fileSet *file.FileSet, filename string, src interface{}, mode Mode) (*ast.Program, error)

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.

// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
program, err := parser.ParseFile(nil, "", `if (abc > 1) {}`, 0)

func ParseFunction

func ParseFunction(parameterList, body string) (*ast.FunctionLiteral, error)

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 ReadSource(filename string, src interface{}) ([]byte, error)

func TransformRegExp

func TransformRegExp(pattern string) (string, error)

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

type Error struct {
	Position file.Position
	Message  string
}

An Error represents a parsing error. It includes the position where the error occurred and a message/description.

func (Error) Error

func (self Error) Error() string

type ErrorList

type ErrorList []*Error

ErrorList is a list of *Errors.

func (*ErrorList) Add

func (self *ErrorList) Add(position file.Position, msg string)

Add adds an Error with given position and message to an ErrorList.

func (ErrorList) Err

func (self ErrorList) Err() error

Err returns an error equivalent to this ErrorList. If the list is empty, Err returns nil.

func (ErrorList) Error

func (self ErrorList) Error() string

Error implements the Error interface.

func (ErrorList) Len

func (self ErrorList) Len() int

func (ErrorList) Less

func (self ErrorList) Less(i, j int) bool

func (*ErrorList) Reset

func (self *ErrorList) Reset()

Reset resets an ErrorList to no errors.

func (ErrorList) Sort

func (self ErrorList) Sort()

func (ErrorList) Swap

func (self ErrorList) Swap(i, j int)

type Mode

type Mode uint

A Mode value is a set of flags (or 0). They control optional parser functionality.

const (
	IgnoreRegExpErrors Mode = 1 << iota // Ignore RegExp compatibility errors (allow backtracking)
)

-- godocdown http://github.com/robertkrimen/godocdown