parser

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package parser translates the linear stream of tokens into ast structures based on the syntax of the ok language.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errors added in v0.17.6

type Errors []error

Errors is a collection of errors.

func (Errors) String added in v0.17.6

func (errs Errors) String() string

type Parser

type Parser struct {

	// Constants are variables defined at the package level. They cannot be
	// modified and only allow literals for values.
	//
	// TODO(elliot): We should allow for expressions that can be resolved at
	//  compile time, such as "3600 * 24".
	Constants map[string]*ast.Literal
	// contains filtered or unexported fields
}

func NewParser added in v0.19.4

func NewParser(anonFunctionName int) *Parser

NewParser creates an empty parser.

func (*Parser) Comments added in v0.19.4

func (parser *Parser) Comments() []*ast.Comment

Comments returns all comments collected from parsing all inputs.

func (*Parser) Errors

func (parser *Parser) Errors() Errors

Errors returns all errors.

func (*Parser) Funcs added in v0.19.4

func (parser *Parser) Funcs() map[string]*ast.Func

func (*Parser) Imports added in v0.19.4

func (parser *Parser) Imports() map[string]string

func (*Parser) Package added in v0.19.7

func (parser *Parser) Package(packageAlias string) *ast.Func

func (*Parser) ParseDirectory added in v0.19.4

func (parser *Parser) ParseDirectory(dirPath string, includeTests bool)

ParseDirectory will read and parse all ".ok" files in a directory (not recursive). This is analogous to parsing a package. If any of the files (or the directory itself) cannot be read the error will be appended to the parser errors.

If includeTests = true, then ".okt" files will also be included.

func (*Parser) ParseFile added in v0.19.4

func (parser *Parser) ParseFile(fileName string)

ParseFile will read and parse the file. If the file cannot be read the error will be appended to the parser errors.

func (*Parser) ParseString added in v0.19.4

func (parser *Parser) ParseString(s string, fileName string)

ParseString parses source code from a string. The fileName is used in error messages, the file does not have to exist.

func (*Parser) ResolveType added in v0.24.0

func (parser *Parser) ResolveType(
	node ast.Node,
	typ *types.Type,
	registry types.Registry,
	imports map[string]*types.Type,
) (*types.Type, error)

func (*Parser) ResolveTypes added in v0.24.0

func (parser *Parser) ResolveTypes(
	registry types.Registry,
	imports map[string]*types.Type,
) error

ResolveTypes is a necessary part between the parsing finishing and the compiler starting. It is the job of this process to translate all the keywords that represent types (that would appear in argument types, return types, etc) into the actual types within this package.

Types referring to an external types (ie. "foo.Bar") are also resolved here, and all imports are expected to be provided to this function.

func (*Parser) SortedFuncNames added in v0.24.0

func (parser *Parser) SortedFuncNames() []string

func (*Parser) Tests added in v0.19.4

func (parser *Parser) Tests() []*ast.Test

Jump to

Keyboard shortcuts

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