{"modulePath":"github.com/kosmosJS/engine","version":"v0.0.0-20220430162127-d31e18d194ab","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package parser\n\nPackage parser implements a parser for JavaScript.\n\n\timport (\n\t    \"github.com/kosmosJS/engine/parser\"\n\t)\n\nParse and return an AST\n\n\tfilename := \"\" // A filename is optional\n\tsrc := `\n\t    // Sample xyzzy example\n\t    (function(){\n\t        if (3.14159 \u003e 0) {\n\t            console.log(\"Hello, World.\");\n\t            return;\n\t        }\n\n\t        var xyzzy = NaN;\n\t        console.log(\"Nothing happens.\");\n\t        return xyzzy;\n\t    })();\n\t`\n\n\t// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList\n\tprogram, err := parser.ParseFile(nil, filename, src, 0)\n\n### Warning {#hdr-Warning}\n\nThe parser and AST interfaces are still works-in-progress (particularly where node types are concerned) and may change in the future.\n\n## Constants\n\n```go\nconst (\n\tWhitespaceChars = \" \\f\\n\\r\\t\\v\\u00a0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff\"\n\tRe2Dot          = \"[^\\r\\n\\u2028\\u2029]\"\n)\n```\n\n## Functions\n\n```go\nfunc IsIdentifier(s string) bool\n```\n\n```go\nfunc ParseFile(fileSet *file.FileSet, filename string, src interface{}, mode Mode, options ...Option) (*ast.Program, error)\n```\nParseFile parses the source code of a single JavaScript/ECMAScript source file and returns the corresponding ast.Program node.\n\nIf fileSet == nil, ParseFile parses source without a FileSet. If fileSet != nil, ParseFile first adds filename and src to fileSet.\n\nThe filename argument is optional and is used for labelling errors, etc.\n\nsrc may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST always be in UTF-8.\n\n\t// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList\n\tprogram, err := parser.ParseFile(nil, \"\", `if (abc \u003e 1) {}`, 0)\n\n```go\nfunc ParseFunction(parameterList, body string, options ...Option) (*ast.FunctionLiteral, error)\n```\nParseFunction parses a given parameter list and body as a function and returns the corresponding ast.FunctionLiteral node.\n\nThe parameter list, if any, should be a comma-separated list of identifiers.\n\n```go\nfunc ReadSource(filename string, src interface{}) ([]byte, error)\n```\n\n```go\nfunc TransformRegExp(pattern string) (transformed string, err error)\n```\nTransformRegExp transforms a JavaScript pattern into  a Go \"regexp\" pattern.\n\nre2 (Go) cannot do backtracking, so the presence of a lookahead (?=) (?!) or backreference (\\\\1, \\\\2, ...) will cause an error.\n\nre2 (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.\n\nIf the pattern is valid, but incompatible (contains a lookahead or backreference), then this function returns an empty string an error of type RegexpErrorIncompatible.\n\nIf the pattern is invalid (not valid even in JavaScript), then this function returns an empty string and a generic error.\n\n```go\nfunc WithDisableSourceMaps(opts *options)\n```\nWithDisableSourceMaps is an option to disable source maps support. May save a bit of time when source maps are not in use.\n\n## Types\n\n```go\ntype Error struct {\n\tPosition file.Position\n\tMessage  string\n}\n```\nAn Error represents a parsing error. It includes the position where the error occurred and a message/description.\n\n```go\nfunc (self Error) Error() string\n```\n\n```go\ntype ErrorList []*Error\n```\nErrorList is a list of \\*Errors.\n\n```go\nfunc (self *ErrorList) Add(position file.Position, msg string)\n```\nAdd adds an Error with given position and message to an ErrorList.\n\n```go\nfunc (self ErrorList) Err() error\n```\nErr returns an error equivalent to this ErrorList. If the list is empty, Err returns nil.\n\n```go\nfunc (self ErrorList) Error() string\n```\nError implements the Error interface.\n\n```go\nfunc (self ErrorList) Len() int\n```\n\n```go\nfunc (self ErrorList) Less(i, j int) bool\n```\n\n```go\nfunc (self *ErrorList) Reset()\n```\nReset resets an ErrorList to no errors.\n\n```go\nfunc (self ErrorList) Sort()\n```\n\n```go\nfunc (self ErrorList) Swap(i, j int)\n```\n\n```go\ntype Mode uint\n```\nA Mode value is a set of flags (or 0). They control optional parser functionality.\n\n```go\nconst (\n\tIgnoreRegExpErrors Mode = 1 \u003c\u003c iota // Ignore RegExp compatibility errors (allow backtracking)\n)\n```\n\n```go\ntype Option func(*options)\n```\nOption represents one of the options for the parser to use in the Parse methods. Currently supported are: WithDisableSourceMaps and WithSourceMapLoader.\n\n```go\nfunc WithSourceMapLoader(loader func(path string) ([]byte, error)) Option\n```\nWithSourceMapLoader is an option to set a custom source map loader. The loader will be given a path or a URL from the sourceMappingURL. If sourceMappingURL is not absolute it is resolved relatively to the name of the file being parsed. Any error returned by the loader will fail the parsing. Note that setting this to nil does not disable source map support, there is a default loader which reads from the filesystem. Use WithDisableSourceMaps to disable source map support.\n\n```go\ntype RegexpErrorIncompatible struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (s RegexpErrorIncompatible) Error() string\n```\n\n```go\ntype RegexpSyntaxError struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (s RegexpSyntaxError) Error() string\n```\n\n","path":"github.com/kosmosJS/engine/parser","name":"parser","synopsis":"Package parser implements a parser for JavaScript.","isRedistributable":true}
