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
- type CaseClause
- type ClassDecl
- type ClassMember
- type ComposeExpr
- type ComposeKind
- type ConstructorPattern
- type DelegateField
- type EnumDecl
- type File
- func (f *File) ComposeFor(bad *ast.BadExpr) (*ComposeExpr, bool)
- func (f *File) IfFor(bad *ast.BadExpr) (*IfExpr, bool)
- func (f *File) MatchExprFor(bad *ast.BadExpr) (*MatchExpr, bool)
- func (f *File) MatchFor(bad *ast.BadStmt) (*MatchStmt, bool)
- func (f *File) Offset(pos token.Pos) int
- func (f *File) OutermostExt() []*ast.BadExpr
- func (f *File) OutermostFlow() (pipes []*PipeExpr, composes []*ComposeExpr)
- func (f *File) PipeFor(bad *ast.BadExpr) (*PipeExpr, bool)
- func (f *File) SwitchExprFor(bad *ast.BadExpr) (*SwitchExpr, bool)
- func (f *File) TryFor(bad *ast.BadExpr) (*TryExpr, bool)
- type GenericMethod
- type IfExpr
- type InstanceDecl
- type InstanceMember
- type MatchExpr
- type MatchExprArm
- type MatchStmt
- type PatNode
- type PatText
- type Pattern
- type PipeExpr
- type PipeStage
- type QuantityParam
- type SwitchExpr
- type SwitchExprArm
- type TotalFunc
- type TryExpr
- type Variant
- type WildcardPattern
Constants ¶
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
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
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 ¶
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) MatchExprFor ¶ added in v0.4.0
MatchExprFor resolves a placeholder expression to its match expression.
func (*File) MatchFor ¶ added in v0.2.0
MatchFor resolves a placeholder statement to its match statement.
func (*File) OutermostExt ¶ added in v0.4.0
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) SwitchExprFor ¶ added in v0.4.0
func (f *File) SwitchExprFor(bad *ast.BadExpr) (*SwitchExpr, bool)
SwitchExprFor resolves a placeholder expression to its switch expression.
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.
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
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
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.
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
ParsePatternText parses "c := Circle(r)", "Add(Lit(a), _)", "_", "opt.Some(v)".
type PipeExpr ¶ added in v0.3.0
Re-exported extension node types; see internal/syntax/parser/ext.go.
type PipeStage ¶ added in v0.3.0
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
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.