syntax

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package syntax parses .gpp source: Go grammar plus G++'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 added in v0.2.0

type CaseClause = parser.CaseClause

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

type ClassDecl added in v0.5.0

type ClassDecl = parser.ClassDecl

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

type ClassMember added in v0.5.0

type ClassMember = parser.ClassMember

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

type ComposeExpr added in v0.3.0

type ComposeExpr = parser.ComposeExpr

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

type ComposeKind added in v0.4.0

type ComposeKind = parser.ComposeKind

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

type ConstructorPattern added in v0.2.0

type ConstructorPattern = parser.ConstructorPattern

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

type DelegateField added in v0.6.0

type DelegateField = parser.DelegateField

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

type EnumDecl added in v0.2.0

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)
	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 .gpp file.

func ParseFile

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

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

func (*File) ComposeFor added in v0.3.0

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

ComposeFor resolves a placeholder expression to its composition.

func (*File) IfFor added in v0.4.0

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

IfFor resolves a placeholder expression to its if expression.

func (*File) MatchExprFor added in v0.4.0

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

MatchExprFor resolves a placeholder expression to its match expression.

func (*File) MatchFor added in v0.2.0

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 added in v0.4.0

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 added in v0.3.0

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 added in v0.3.0

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

PipeFor resolves a placeholder expression to its pipeline.

func (*File) SwitchExprFor added in v0.4.0

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

SwitchExprFor resolves a placeholder expression to its switch expression.

func (*File) TryFor added in v0.4.0

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 added in v0.2.0

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 added in v0.4.0

type IfExpr = parser.IfExpr

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

type InstanceDecl added in v0.5.0

type InstanceDecl = parser.InstanceDecl

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

type InstanceMember added in v0.5.0

type InstanceMember = parser.InstanceMember

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

type MatchExpr added in v0.4.0

type MatchExpr = parser.MatchExpr

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

type MatchExprArm added in v0.4.0

type MatchExprArm = parser.MatchExprArm

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

type MatchStmt added in v0.2.0

type MatchStmt = parser.MatchStmt

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

type PatNode added in v0.2.0

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 added in v0.2.0

func (n PatNode) String() string

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

type PatText added in v0.2.0

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 `//gpp:pattern <verbatim>` lines that thread pattern structure through the resolution fixpoint).

func ParsePatternText added in v0.2.0

func ParsePatternText(text string) (PatText, error)

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

type Pattern added in v0.2.0

type Pattern = parser.Pattern

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

type PipeExpr added in v0.3.0

type PipeExpr = parser.PipeExpr

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

type PipeStage added in v0.3.0

type PipeStage = parser.PipeStage

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

type QuantityParam added in v0.7.0

type QuantityParam = parser.QuantityParam

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

type SwitchExpr added in v0.4.0

type SwitchExpr = parser.SwitchExpr

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

type SwitchExprArm added in v0.4.0

type SwitchExprArm = parser.SwitchExprArm

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

type TotalFunc added in v0.7.0

type TotalFunc = parser.TotalFunc

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

type TryExpr added in v0.4.0

type TryExpr = parser.TryExpr

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

type Variant added in v0.2.0

type Variant = parser.Variant

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

type WildcardPattern added in v0.2.0

type WildcardPattern = parser.WildcardPattern

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

Directories

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

Jump to

Keyboard shortcuts

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