parser

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package parser parses ECMAScript source text into the syntax tree of package ast.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIdentifierName

func IsIdentifierName(s string) bool

IsIdentifierName reports whether s is an IdentifierName without escapes.

func ParseFunction

func ParseFunction(params, body wtf8.String, kind FunctionKind, opts Options) (*ast.Program, error)

ParseFunction parses a function given as separate parameter text and body text, as the Function constructor and its generator and async variants require.

The source of the returned program is the synthesized function text. Its body is one expression statement holding the function. The returned error is an *Error.

func ParseModule

func ParseModule(src wtf8.String, opts Options) (*ast.Program, error)

ParseModule parses src as a Module. The returned error is an *Error.

func ParseScript

func ParseScript(src wtf8.String, opts Options) (*ast.Program, error)

ParseScript parses src as a Script. The returned error is an *Error.

Types

type Error

type Error struct {
	// Offset is the byte offset of the error in the source text.
	Offset int

	// Line is the 1-based line of the error.
	Line int

	// Column is the 1-based column of the error, counted in code points.
	Column int

	Message string
}

Error is a syntax error.

func (*Error) Error

func (e *Error) Error() string

Error returns the position and the message of the error.

type FunctionKind

type FunctionKind uint8

FunctionKind is the kind of function that ParseFunction creates.

const (
	NormalFunction FunctionKind = iota
	GeneratorFunction
	AsyncFunction
	AsyncGeneratorFunction
)

type Options

type Options struct {
	// Strict makes the code strict mode code from its start.
	Strict bool

	// AllowSuperProperty permits super property accesses at the top level, as in a direct eval inside a method.
	AllowSuperProperty bool

	// AllowSuperCall permits super calls at the top level, as in a direct eval inside a derived constructor.
	AllowSuperCall bool

	// AllowNewTarget permits new.target at the top level, as in a direct eval inside a function.
	AllowNewTarget bool

	// InClassFieldInit makes references to arguments an error, as in a direct eval inside a class field initializer.
	InClassFieldInit bool

	// PrivateNames lists the private names, without '#', declared by the classes enclosing a direct eval.
	PrivateNames []string

	// Poll, when not nil, is called now and then during a long parse, and may stop it by
	// panicking.
	Poll func()
}

Options describes the context that source text is parsed in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL