syntax

package
v0.146.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package syntax parses .gp source: Go grammar plus Go+'s extensions — type parameters on methods (v0.1.0), enum declarations and match statements (v0.2.0). It fronts a vendored fork of go/parser (see internal/syntax/parser); the *ast.File it produces is fully stock, with extension constructs occupying their source spans as placeholder nodes and the real structure exposed via Methods, Enums, and Matches.

Index

Constants

View Source
const (
	ComposeFn      = parser.ComposeFn
	ComposeKleisli = parser.ComposeKleisli
)

Composition operator kinds.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaseClause

type CaseClause = parser.CaseClause

Re-exported extension node types; see internal/syntax/parser/ext.go.

type ClassDecl

type ClassDecl = parser.ClassDecl

Re-exported extension node types; see internal/syntax/parser/ext.go.

type ClassMember

type ClassMember = parser.ClassMember

Re-exported extension node types; see internal/syntax/parser/ext.go.

type ComposeExpr

type ComposeExpr = parser.ComposeExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type ComposeKind

type ComposeKind = parser.ComposeKind

Re-exported extension node types; see internal/syntax/parser/ext.go.

type ConstructorPattern

type ConstructorPattern = parser.ConstructorPattern

Re-exported extension node types; see internal/syntax/parser/ext.go.

type DelegateField

type DelegateField = parser.DelegateField

Re-exported extension node types; see internal/syntax/parser/ext.go.

type EnumDecl

type EnumDecl = parser.EnumDecl

Re-exported extension node types; see internal/syntax/parser/ext.go.

type File

type File struct {
	Path      string
	Src       []byte
	Fset      *token.FileSet
	TokFile   *token.File
	AST       *ast.File // stock AST; enum bodies are BadExpr, matches BadStmt
	Methods   []*GenericMethod
	Enums     []*EnumDecl      // source order
	Classes   []*ClassDecl     // source order (v0.5.0)
	Instances []*InstanceDecl  // source order (v0.5.0)
	Delegates []*DelegateField // source order (v0.6.0)

	Quantities  []*QuantityParam  // source order (v0.7.0)
	Totals      []*TotalFunc      // source order (v0.7.0)
	Tails       []*TailFunc       // source order (v0.8.0)
	Refinements []*RefinementDecl // source order (v0.9.0)
	Matches     []*MatchStmt      // pre-order (nested matches follow their parent)

	// Pipes and Composes are in creation order (extensions nested in a
	// head/left operand precede their encloser); resolve placeholders by
	// pointer via PipeFor/ComposeFor, never by slice position.
	Pipes    []*PipeExpr
	Composes []*ComposeExpr

	// v0.4.0 typed-failure constructs, creation order.
	Tries       []*TryExpr
	IfExprs     []*IfExpr
	SwitchExprs []*SwitchExpr
	MatchExprs  []*MatchExpr
	// contains filtered or unexported fields
}

File is one parsed .gp file.

func ParseFile

func ParseFile(fset *token.FileSet, path string, src []byte) (*File, error)

ParseFile parses .gp source. Genuine syntax errors are returned as a scanner.ErrorList.

func (*File) ComposeFor

func (f *File) ComposeFor(bad *ast.BadExpr) (*ComposeExpr, bool)

ComposeFor resolves a placeholder expression to its composition.

func (*File) IfFor

func (f *File) IfFor(bad *ast.BadExpr) (*IfExpr, bool)

IfFor resolves a placeholder expression to its if expression.

func (*File) MatchExprFor

func (f *File) MatchExprFor(bad *ast.BadExpr) (*MatchExpr, bool)

MatchExprFor resolves a placeholder expression to its match expression.

func (*File) MatchFor

func (f *File) MatchFor(bad *ast.BadStmt) (*MatchStmt, bool)

MatchFor resolves a placeholder statement to its match statement.

func (*File) Offset

func (f *File) Offset(pos token.Pos) int

Offset converts a token.Pos within f to a byte offset in f.Src.

func (*File) OutermostExt

func (f *File) OutermostExt() []*ast.BadExpr

OutermostExt lists the expression-extension placeholders whose spans are not contained inside another extension expression's span — the set pass-1 lowering rewrites (nested extensions render recursively inside them). Ordered by source position.

func (*File) OutermostFlow

func (f *File) OutermostFlow() (pipes []*PipeExpr, composes []*ComposeExpr)

OutermostFlow lists the pipelines and compositions whose spans are not contained inside another flow extension's span — the ones pass-1 lowering must rewrite (nested flows render recursively inside them).

func (*File) PipeFor

func (f *File) PipeFor(bad *ast.BadExpr) (*PipeExpr, bool)

PipeFor resolves a placeholder expression to its pipeline.

func (*File) SwitchExprFor

func (f *File) SwitchExprFor(bad *ast.BadExpr) (*SwitchExpr, bool)

SwitchExprFor resolves a placeholder expression to its switch expression.

func (*File) TryFor

func (f *File) TryFor(bad *ast.BadExpr) (*TryExpr, bool)

TryFor resolves a placeholder expression to its try suffix.

type GenericMethod

type GenericMethod struct {
	Decl *ast.FuncDecl // TypeParams present natively (fork keeps them)

	RecvName     string   // receiver identifier as written; "" if absent
	RecvTypeName string   // base named type, e.g. "Stack"
	RecvPointer  bool     // *Stack[T] receiver
	RecvTParams  []string // receiver type parameter names, e.g. ["T"]

	// LBrack and RBrack are byte offsets in Src of the method's type
	// parameter brackets.
	LBrack, RBrack int
}

GenericMethod is a method declaration carrying its own type parameters.

func NewMethod

func NewMethod(fd *ast.FuncDecl) (*GenericMethod, error)

NewMethod builds method info for an ordinary (non-generic) method declaration, e.g. an enum method that lowers like a generic method with zero method type parameters.

type IfExpr

type IfExpr = parser.IfExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type InstanceDecl

type InstanceDecl = parser.InstanceDecl

Re-exported extension node types; see internal/syntax/parser/ext.go.

type InstanceMember

type InstanceMember = parser.InstanceMember

Re-exported extension node types; see internal/syntax/parser/ext.go.

type MatchExpr

type MatchExpr = parser.MatchExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type MatchExprArm

type MatchExprArm = parser.MatchExprArm

Re-exported extension node types; see internal/syntax/parser/ext.go.

type MatchStmt

type MatchStmt = parser.MatchStmt

Re-exported extension node types; see internal/syntax/parser/ext.go.

type PatNode

type PatNode struct {
	Wild    bool   // `_`
	Qual    string // qualifier before '.', e.g. "lib" or "Option"; "" if bare
	Name    string // constructor (or binder) name
	HasArgs bool   // distinguishes None from None()
	Args    []PatNode
}

PatNode is one node of a textual pattern tree.

func (PatNode) String

func (n PatNode) String() string

String renders a PatNode back to pattern text (for witness diagnostics).

type PatText

type PatText struct {
	Binder string // whole-value binder name; "" if absent
	Root   PatNode
	Alts   []PatNode // additional alternatives of a multi-pattern arm (v0.12.0)
}

PatText is a match pattern re-parsed from carrier text (the `//goplus:pattern <verbatim>` lines that thread pattern structure through the resolution fixpoint).

func ParsePatternText

func ParsePatternText(text string) (PatText, error)

ParsePatternText parses "c := Circle(r)", "Add(Lit(a), _)", "_", "opt.Some(v)".

type Pattern

type Pattern = parser.Pattern

Re-exported extension node types; see internal/syntax/parser/ext.go.

type PipeExpr

type PipeExpr = parser.PipeExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type PipeStage

type PipeStage = parser.PipeStage

Re-exported extension node types; see internal/syntax/parser/ext.go.

type QuantityParam

type QuantityParam = parser.QuantityParam

Re-exported extension node types; see internal/syntax/parser/ext.go.

type RefinementDecl added in v0.22.0

type RefinementDecl = parser.RefinementDecl

Re-exported extension node types; see internal/syntax/parser/ext.go.

type SwitchExpr

type SwitchExpr = parser.SwitchExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type SwitchExprArm

type SwitchExprArm = parser.SwitchExprArm

Re-exported extension node types; see internal/syntax/parser/ext.go.

type TailFunc added in v0.21.0

type TailFunc = parser.TailFunc

Re-exported extension node types; see internal/syntax/parser/ext.go.

type TotalFunc

type TotalFunc = parser.TotalFunc

Re-exported extension node types; see internal/syntax/parser/ext.go.

type TryExpr

type TryExpr = parser.TryExpr

Re-exported extension node types; see internal/syntax/parser/ext.go.

type Variant

type Variant = parser.Variant

Re-exported extension node types; see internal/syntax/parser/ext.go.

type WildcardPattern

type WildcardPattern = parser.WildcardPattern

Re-exported extension node types; see internal/syntax/parser/ext.go.

Directories

Path Synopsis
Go+ extension nodes and entry points.
Go+ extension nodes and entry points.

Jump to

Keyboard shortcuts

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