parser

package
v0.0.0-...-1ec0bd7 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImportsOnly

func ImportsOnly(path string) ([]string, error)

ImportsOnly returns just the paths imported by a source file. Imports only parses the imports and ignores the rest of the file; syntax errors after import statements are not reported.

Types

type ArrayLit

type ArrayLit struct {
	Exprs []Expr
	L     loc.Loc
}

func (*ArrayLit) Loc

func (a *ArrayLit) Loc() loc.Loc

type ArrayType

type ArrayType struct {
	ElemType Type
	L        loc.Loc
}

func (*ArrayType) Loc

func (t *ArrayType) Loc() loc.Loc

type BlockLit

type BlockLit struct {
	Parms []FuncParm
	Exprs []Expr
	L     loc.Loc
}

func (*BlockLit) Loc

func (b *BlockLit) Loc() loc.Loc

type Call

type Call struct {
	Fun  Expr
	Args []Expr
	L    loc.Loc
}

func (*Call) Loc

func (c *Call) Loc() loc.Loc

type CaseDef

type CaseDef struct {
	Name Ident
	Type Type // nil if an un-typed case
	L    loc.Loc
}

type CaseVal

type CaseVal struct {
	Name Ident
	Val  Expr // nil if value-less case
	L    loc.Loc
}

type CharLit

type CharLit struct {
	Source string // source text
	Rune   rune
	L      loc.Loc
}

func (*CharLit) Loc

func (c *CharLit) Loc() loc.Loc

type Comment

type Comment struct {
	Text string
	L    loc.Loc
}

func (Comment) Loc

func (c Comment) Loc() loc.Loc

func (Comment) String

func (c Comment) String() string

type Convert

type Convert struct {
	Type Type
	Expr Expr
	L    loc.Loc
}

func (*Convert) Loc

func (c *Convert) Loc() loc.Loc

type Def

type Def interface{}

type Expr

type Expr interface {
	Loc() loc.Loc
}

func ParseExpr

func ParseExpr(str string) (Expr, error)

type FieldDef

type FieldDef struct {
	Name Ident
	Type Type
	L    loc.Loc
}

type FieldVal

type FieldVal struct {
	Name Ident
	Val  Expr
	L    loc.Loc
}

type File

type File struct {
	Imports []*Import
	Defs    []Def
	// All comments sorted by their start location.
	Comments []Comment

	P      string
	NLs    []int
	Length int
}

func (*File) Len

func (f *File) Len() int

func (*File) NewLines

func (f *File) NewLines() []int

func (*File) Path

func (f *File) Path() string

func (*File) Print

func (f *File) Print(w io.Writer, opts ...PrintOpt) error

type FloatLit

type FloatLit struct {
	Text string
	L    loc.Loc
}

func (*FloatLit) Loc

func (f *FloatLit) Loc() loc.Loc

type FuncDecl

type FuncDecl struct {
	Name  Ident
	Parms []Type
	Ret   Type // nil if no return
	L     loc.Loc
}

type FuncDef

type FuncDef struct {
	Exp   bool
	Name  Ident
	Parms []FuncParm
	Ret   Type // nil if no return
	// Constraints is an interface constraint to satisfy
	// after the return type is determined.
	// Each element is either a *FuncDecl
	// or a *NamedType naming an interface.
	Constraints []interface{}
	Exprs       []Expr // nil if unspecified, non-nil, len()==0 if empty
	L           loc.Loc
}

type FuncParm

type FuncParm struct {
	Name Ident
	Type Type
	// Constraints is an interface constraint to satisfy
	// after this parameter type is determined.
	// Each element is either a *FuncDecl
	// or a *NamedType naming an interface.
	Constraints []interface{}
	L           loc.Loc
}

type FuncType

type FuncType struct {
	Parms []Type
	Ret   Type // nil if no return
	L     loc.Loc
}

func (*FuncType) Loc

func (t *FuncType) Loc() loc.Loc

type Ident

type Ident struct {
	Name string

	// Parts contains elements of Name,
	// if it was composed of multiple
	// colon words or question words.
	Parts []Ident

	// L is the location spanning the entire identifier.
	L loc.Loc
}

func (Ident) Loc

func (i Ident) Loc() loc.Loc

func (Ident) String

func (i Ident) String() string

type IfaceDef

type IfaceDef struct {
	Exp       bool
	Opaque    bool
	TypeParms []TypeVar
	Name      Ident
	// Iface and Alias are mutually exclusive.
	// Iface is the defintition of a non-alias interface.
	// Each element is either a *FuncDecl
	// or a *NamedType naming an interface.
	Iface []interface{}
	// Alias is the name of an interface that this one aliases.
	Alias *NamedType
	L     loc.Loc
}

type Import

type Import struct {
	Exp  bool
	Name *Ident // nil if unspecified
	Path string
	L    loc.Loc
}

type IntLit

type IntLit struct {
	Text string
	L    loc.Loc
}

func (*IntLit) Loc

func (i *IntLit) Loc() loc.Loc

type ModSel

type ModSel struct {
	Mod  Ident
	Name Ident
	L    loc.Loc
}

func (*ModSel) Loc

func (m *ModSel) Loc() loc.Loc

type NamedType

type NamedType struct {
	Args []Type
	Mod  *Ident // nil if unspecified
	Name Ident
	L    loc.Loc
}

func (*NamedType) Loc

func (t *NamedType) Loc() loc.Loc

type Parser

type Parser struct {
	Files []*File
	// TrimErrorPathPrefix is trimmed from path names
	// in parse error messages.
	TrimErrorPathPrefix string
	// contains filtered or unexported fields
}

A Parser parses source code files.

func New

func New() *Parser

New returns a new parser.

func NewWithOffset

func NewWithOffset(offs int) *Parser

NewWithOffset returns a new parser with the given location offset.

func (*Parser) Parse

func (p *Parser) Parse(path string, r io.Reader) error

Parse parses a file from an io.Reader. The first argument is the file path or "" if unspecified.

func (*Parser) ParseFile

func (p *Parser) ParseFile(path string) error

ParseFile parses the source from a file path.

type PrintOpt

type PrintOpt func(*config)

func PrintLocs

func PrintLocs(fs ...*File) PrintOpt

type RefType

type RefType struct {
	Type Type
	L    loc.Loc
}

func (*RefType) Loc

func (t *RefType) Loc() loc.Loc

type StrLit

type StrLit struct {
	Raw    bool
	Source string // source text
	Data   string
	L      loc.Loc
}

func (*StrLit) Loc

func (s *StrLit) Loc() loc.Loc

type StructLit

type StructLit struct {
	FieldVals []FieldVal
	L         loc.Loc
}

func (*StructLit) Loc

func (s *StructLit) Loc() loc.Loc

type StructType

type StructType struct {
	Fields []FieldDef
	L      loc.Loc
}

func (*StructType) Loc

func (t *StructType) Loc() loc.Loc

type SubExpr

type SubExpr struct {
	Expr
	L loc.Loc
}

func (*SubExpr) Loc

func (s *SubExpr) Loc() loc.Loc

type TestDef

type TestDef struct {
	Name  Ident
	Exprs []Expr
	L     loc.Loc
}

type Type

type Type interface {
	Loc() loc.Loc
}

func ParseType

func ParseType(str string) (Type, error)

type TypeDef

type TypeDef struct {
	Exp       bool
	Opaque    bool
	Alias     bool
	TypeParms []TypeVar
	Name      Ident
	Type      Type
	L         loc.Loc
}

type TypeVar

type TypeVar struct {
	Name string
	L    loc.Loc
}

func (TypeVar) Loc

func (tv TypeVar) Loc() loc.Loc

func (TypeVar) String

func (tv TypeVar) String() string

type UnionLit

type UnionLit struct {
	CaseVal CaseVal
	L       loc.Loc
}

func (*UnionLit) Loc

func (u *UnionLit) Loc() loc.Loc

type UnionType

type UnionType struct {
	Cases []CaseDef
	L     loc.Loc
}

func (*UnionType) Loc

func (t *UnionType) Loc() loc.Loc

type VarDef

type VarDef struct {
	Exp   bool
	Const bool
	Name  Ident
	Type  Type
	Expr  Expr // nil if unspecified
	L     loc.Loc
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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