lang

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenIllegal    = syntax.TokenIllegal
	TokenEOF        = syntax.TokenEOF
	TokenNewline    = syntax.TokenNewline
	TokenMetadata   = syntax.TokenMetadata
	TokenIdentifier = syntax.TokenIdentifier
	TokenString     = syntax.TokenString
	TokenLBrace     = syntax.TokenLBrace
	TokenRBrace     = syntax.TokenRBrace
	TokenComma      = syntax.TokenComma
	TokenColon      = syntax.TokenColon
	TokenAssign     = syntax.TokenAssign
	TokenQuestion   = syntax.TokenQuestion
	TokenArrow      = syntax.TokenArrow
	TokenText       = syntax.TokenText
)
View Source
const ManifestSchemaVersion = 1

ManifestSchemaVersion is the current gowdk manifest JSON schema version.

Variables

View Source
var MetadataKeywords = syntax.MetadataKeywords

MetadataKeywords and IsMetadataKeyword re-export the single source of truth the lexer and formatter share.

Functions

func CheckFiles

func CheckFiles(config gowdk.Config, paths []string) (CheckResult, Diagnostics)

CheckFiles parses and validates .gwdk files.

func CheckFilesWithOptions added in v0.3.0

func CheckFilesWithOptions(config gowdk.Config, paths []string, options CheckOptions) (CheckResult, Diagnostics)

CheckFilesWithOptions parses and validates .gwdk files with explicit project context for checks that need to inspect sibling Go code.

func Format

func Format(source []byte) []byte

Format normalizes whitespace for top-level .gwdk metadata and blocks. Brace depth is tracked with the parser's string/comment-aware scanner so braces inside string literals, comments, and template literals do not skew indentation (for example `title "a { b"` or `// note about }`).

func IsMetadataKeyword added in v0.3.0

func IsMetadataKeyword(value string) bool

IsMetadataKeyword reports whether value is a top-level metadata keyword.

func Lex

func Lex(source string) ([]Token, Diagnostics)

Lex tokenizes .gwdk source for tooling, mapping each leaf-level LexError into a rich lang.Diagnostic (the error severity, redaction, and JSON marshaling stay in lang).

func RedactMessage added in v0.2.7

func RedactMessage(message string) string

RedactMessage masks values that commonly carry credentials so a diagnostic quoting .gwdk source content (attribute values, expressions, route or store literals) does not echo a hardcoded secret into terminal output, check --json payloads, or LSP diagnostics.

It is deliberately conservative and mirrors the runtime panic-log policy: it favours over-masking a suspicious token over letting a real secret through.

Types

type CheckOptions added in v0.3.0

type CheckOptions struct {
	ProjectRoot string
}

CheckOptions controls validation behavior that depends on project context.

type CheckResult added in v0.2.8

type CheckResult struct {
	IR       gwdkir.Program
	Bindings []source.BackendBinding
}

CheckResult is the validated program produced by CheckFiles: the IR with discovered standalone Go endpoints and backend handler bindings attached, plus the flat binding record list for the manifest JSON report.

type Completion

type Completion struct {
	Label  string
	Detail string
}

Completion describes one language completion shared by editor integrations.

func Completions

func Completions() []Completion

Completions returns the core .gwdk language keywords known to editor tools.

type ConstructKind added in v0.3.0

type ConstructKind string

ConstructKind groups language constructs by surface.

const (
	ConstructBlock     ConstructKind = "block"
	ConstructKeyword   ConstructKind = "metadata-keyword"
	ConstructDirective ConstructKind = "g-directive"
	ConstructEndpoint  ConstructKind = "endpoint"
)

type ConstructStability added in v0.3.0

type ConstructStability struct {
	Name           string
	Kind           ConstructKind
	Tier           StabilityTier
	DiagnosticCode string
}

ConstructStability is the stability record for one language construct. For planned and deprecated constructs DiagnosticCode names the diagnostic emitted when the construct is used.

func ConstructStabilities added in v0.3.0

func ConstructStabilities() []ConstructStability

ConstructStabilities returns the code-level source of truth for per-construct stability tiers. The published table in docs/language/stability.md is verified against it by TestStabilityTableMatchesRegistry. Metadata keywords are derived from MetadataKeywords so the two cannot drift.

type Diagnostic

type Diagnostic struct {
	File       string            `json:"file"`
	Code       string            `json:"code,omitempty"`
	Pos        Position          `json:"pos"`
	Range      *Range            `json:"range,omitempty"`
	Severity   string            `json:"severity"`
	Fix        *diagnostics.Fix  `json:"fix,omitempty"`
	Message    string            `json:"message"`
	Suggestion string            `json:"suggestion,omitempty"`
	Related    []RelatedLocation `json:"related,omitempty"`
}

Diagnostic describes a language-tool finding.

func (Diagnostic) MarshalJSON added in v0.2.7

func (diagnostic Diagnostic) MarshalJSON() ([]byte, error)

MarshalJSON redacts secret-bearing source content from the message and suggestion before serialization so check --json and other JSON sinks never emit a hardcoded secret quoted from .gwdk source.

func (Diagnostic) String

func (diagnostic Diagnostic) String() string

type DiagnosticReport

type DiagnosticReport struct {
	Version     int         `json:"version"`
	Diagnostics Diagnostics `json:"diagnostics"`
}

DiagnosticReport is the JSON shape consumed by editor integrations.

type Diagnostics

type Diagnostics []Diagnostic

Diagnostics is a collection that implements error.

func CheckJSON

func CheckJSON(config gowdk.Config, paths []string) ([]byte, Diagnostics)

CheckJSON returns editor-friendly JSON diagnostics for parsed files.

func CheckJSONWithOptions added in v0.3.0

func CheckJSONWithOptions(config gowdk.Config, paths []string, options CheckOptions) ([]byte, Diagnostics)

CheckJSONWithOptions returns editor-friendly JSON diagnostics for parsed files with explicit project context.

func CheckSource

func CheckSource(config gowdk.Config, path string, source []byte) (gwdkir.Page, Diagnostics)

CheckSource parses and validates one in-memory .gwdk source buffer.

func ManifestJSON

func ManifestJSON(config gowdk.Config, paths []string) ([]byte, Diagnostics)

ManifestJSON returns the manifest JSON report for parsed and validated files. The report shape is derived from the compiler IR.

func ManifestJSONWithOptions added in v0.3.0

func ManifestJSONWithOptions(config gowdk.Config, paths []string, options CheckOptions) ([]byte, Diagnostics)

ManifestJSONWithOptions returns the manifest JSON report with explicit project context.

func ParseBuildFiles

func ParseBuildFiles(paths []string) (gwdkanalysis.Sources, Diagnostics)

ParseBuildFiles parses explicit page and component files for build commands.

func ParseComponentSource

func ParseComponentSource(path string, source []byte) (gwdkir.Component, Diagnostics)

ParseComponentSource parses one in-memory .cmp.gwdk source buffer.

func ParseFile

func ParseFile(path string) (gwdkir.Page, Diagnostics)

ParseFile reads and parses one .gwdk file.

func ParseFiles

func ParseFiles(paths []string) (gwdkanalysis.Sources, Diagnostics)

ParseFiles parses multiple .gwdk files into IR source records.

func ParseLayoutSource

func ParseLayoutSource(path string, source []byte) (gwdkir.Layout, Diagnostics)

ParseLayoutSource parses one in-memory .layout.gwdk source buffer.

func ParseSource

func ParseSource(path string, source []byte) (gwdkir.Page, Diagnostics)

ParseSource parses one .gwdk source buffer.

func SiteMapJSON

func SiteMapJSON(config gowdk.Config, paths []string) ([]byte, Diagnostics)

SiteMapJSON returns the JSON site map for parsed and validated files.

func SiteMapJSONWithOptions added in v0.3.0

func SiteMapJSONWithOptions(config gowdk.Config, paths []string, options CheckOptions) ([]byte, Diagnostics)

SiteMapJSONWithOptions returns the JSON site map with explicit project context.

func (Diagnostics) Error

func (diagnostics Diagnostics) Error() string

func (Diagnostics) HasErrors

func (diagnostics Diagnostics) HasErrors() bool

HasErrors reports whether any diagnostic is an error.

type FileKind

type FileKind string

FileKind identifies the current source file category.

const (
	FileKindPage      FileKind = "page"
	FileKindComponent FileKind = "component"
	FileKindLayout    FileKind = "layout"
	FileKindAsset     FileKind = "asset"
)

func ClassifySource

func ClassifySource(path string, source []byte) FileKind

ClassifySource classifies a .gwdk source file using current file-kind rules.

type OutlineKind added in v0.3.0

type OutlineKind string

OutlineKind classifies a top-level .gwdk declaration for a document outline.

const (
	OutlineKindPackage   OutlineKind = "package"
	OutlineKindMetadata  OutlineKind = "metadata"
	OutlineKindImport    OutlineKind = "import"
	OutlineKindUse       OutlineKind = "use"
	OutlineKindBlock     OutlineKind = "block"
	OutlineKindEndpoint  OutlineKind = "endpoint"
	OutlineKindComponent OutlineKind = "component"
	OutlineKindPage      OutlineKind = "page"
)

type OutlineSymbol added in v0.3.0

type OutlineSymbol struct {
	Kind   OutlineKind
	Name   string
	Detail string
	Span   source.SourceSpan
}

OutlineSymbol is one entry in a document outline.

func Outline added in v0.3.0

func Outline(src string) []OutlineSymbol

Outline parses the top-level declaration structure of .gwdk source into a flat document outline. It is a recursive-descent pass over the shared tokenizer — the first consumer of the ADR 0010 parser direction — and recovers from unrecognized lines by skipping to the next line, so a malformed line never hides the rest of the outline. Block ranges span to the matching close brace, counted over tokens (string literals are single tokens, so braces inside strings never miscount).

type Position

type Position = syntax.Position

Token and position types are aliases, so lang.Token and syntax.Token are the same type and values cross the boundary without conversion.

type Range

type Range = syntax.Range

Token and position types are aliases, so lang.Token and syntax.Token are the same type and values cross the boundary without conversion.

type RelatedLocation added in v0.3.0

type RelatedLocation struct {
	File    string   `json:"file,omitempty"`
	Pos     Position `json:"pos"`
	Range   *Range   `json:"range,omitempty"`
	Message string   `json:"message,omitempty"`
}

RelatedLocation is a secondary source location attached to a diagnostic, such as the first declaration that a conflict diagnostic also points at.

type SiteMap

type SiteMap struct {
	Pages     []SiteMapPage     `json:"pages"`
	Routes    []SiteMapRoute    `json:"routes,omitempty"`
	Endpoints []SiteMapEndpoint `json:"endpoints,omitempty"`
}

SiteMap is an editor-facing route and file map.

func BuildSiteMapFromIR added in v0.2.6

func BuildSiteMapFromIR(config gowdk.Config, ir gwdkir.Program) SiteMap

BuildSiteMapFromIR converts stable compiler IR into the editor-facing site map.

type SiteMapBlocks

type SiteMapBlocks struct {
	Paths   bool     `json:"paths"`
	Build   bool     `json:"build"`
	Load    bool     `json:"load"`
	View    bool     `json:"view"`
	Actions []string `json:"actions,omitempty"`
	APIs    []string `json:"apis,omitempty"`
}

SiteMapBlocks records which top-level source blocks are present.

type SiteMapEndpoint added in v0.1.5

type SiteMapEndpoint struct {
	Kind          compiler.EndpointKind       `json:"kind"`
	Method        string                      `json:"method"`
	Route         string                      `json:"route"`
	PageID        string                      `json:"pageId"`
	Symbol        string                      `json:"symbol,omitempty"`
	Package       string                      `json:"package,omitempty"`
	BindingStatus source.BackendBindingStatus `json:"bindingStatus,omitempty"`
	Signature     source.BackendSignatureKind `json:"signature,omitempty"`
	InputType     string                      `json:"inputType,omitempty"`
}

SiteMapEndpoint describes one generated action/API endpoint graph entry.

type SiteMapPage

type SiteMapPage struct {
	ID            string           `json:"id"`
	Route         string           `json:"route"`
	Source        string           `json:"source"`
	Render        gowdk.RenderMode `json:"render"`
	Layouts       []string         `json:"layouts,omitempty"`
	Guard         []string         `json:"guard,omitempty"`
	DynamicParams []string         `json:"dynamicParams,omitempty"`
	Blocks        SiteMapBlocks    `json:"blocks"`
}

SiteMapPage describes one movable page file and its route identity.

type SiteMapRoute added in v0.1.5

type SiteMapRoute struct {
	Kind    compiler.RouteKind `json:"kind"`
	Method  string             `json:"method"`
	Route   string             `json:"route"`
	PageID  string             `json:"pageId"`
	Handler string             `json:"handler,omitempty"`
}

SiteMapRoute describes one generated route graph entry.

type StabilityTier added in v0.3.0

type StabilityTier string

StabilityTier is the per-construct stability classification, mirroring the Stability field the diagnostics registry records for diagnostic codes.

const (
	// TierStable: accepted today and not expected to change shape within 0.x
	// without a deprecation step.
	TierStable StabilityTier = "stable"
	// TierPartial: accepted for a narrower slice than the final contract.
	TierPartial StabilityTier = "partial"
	// TierPlanned: not accepted yet; using it is rejected with DiagnosticCode.
	TierPlanned StabilityTier = "planned"
	// TierDeprecated: previously accepted spelling, now rejected with
	// DiagnosticCode.
	TierDeprecated StabilityTier = "deprecated"
)

type Token

type Token = syntax.Token

Token and position types are aliases, so lang.Token and syntax.Token are the same type and values cross the boundary without conversion.

type TokenKind

type TokenKind = syntax.TokenKind

Token and position types are aliases, so lang.Token and syntax.Token are the same type and values cross the boundary without conversion.

type TopLevel added in v0.3.0

type TopLevel = syntax.TopLevel

Token and position types are aliases, so lang.Token and syntax.Token are the same type and values cross the boundary without conversion.

func ParseTopLevel added in v0.3.0

func ParseTopLevel(src string) TopLevel

ParseTopLevel runs the recursive-descent declaration parser.

Jump to

Keyboard shortcuts

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