Documentation
¶
Index ¶
- Constants
- func AsDiagnostics(errors, warnings []Diagnostic) []diag.Diagnostic
- func BodyAdmitsBehaviorUsage(owner ast.Node) bool
- func BodyAdmitsMember(owner ast.Node, kw string) bool
- func BodyIsCalculation(owner ast.Node) bool
- func BodyIsRequirement(owner ast.Node) bool
- func IsPrefixModifierKeyword(kw string) bool
- func MemberOwner(kw string) string
- func ParseOneExpression(origin, text string) (ast.Node, bool)
- func Reserves(kind source.Kind, keywordID string) bool
- type Diagnostic
- type Parser
- type SyntaxError
Constants ¶
const CodeSyntax = "syntax"
CodeSyntax is the code an error is reported under when its reporter gave it none: the general ill-formed-parse finding.
Variables ¶
This section is empty.
Functions ¶
func AsDiagnostics ¶ added in v0.9.2
func AsDiagnostics(errors, warnings []Diagnostic) []diag.Diagnostic
AsDiagnostics presents a parse's errors and warnings as the diagnostics the analysis passes take and every frontend reports: an error is an error coded by ErrorCode, a warning keeps the code the parser gave it, and both name syntax as their source and carry the parser's fixes. The errors come first.
func BodyAdmitsBehaviorUsage ¶ added in v0.9.2
BodyAdmitsBehaviorUsage reports whether owner’s body production admits a BehaviorUsageElement such as `satisfy`.
func BodyAdmitsMember ¶
BodyAdmitsMember reports whether the body of owner — a Definition or Usage; any other node, the document root included, opens a plain namespace body — offers the member keyword kw introduces; as for MemberOwner, kw may be a notation.
func BodyIsCalculation ¶ added in v0.9.2
BodyIsCalculation reports whether owner opens a calculation or case body, including constraint bodies, which use CalculationBody.
func BodyIsRequirement ¶ added in v0.9.2
BodyIsRequirement reports whether owner opens a requirement body.
func IsPrefixModifierKeyword ¶ added in v0.9.2
IsPrefixModifierKeyword reports whether kw is a feature/usage prefix modifier the parser reads before a declaration's kind keyword.
func MemberOwner ¶
MemberOwner names the body kind that alone offers the member keyword kw introduces ("requirement or case" for `subject`), or "" when every body does. kw may be the whole notation of a member (`entry action`); its first word decides.
func ParseOneExpression ¶
ParseOneExpression parses text, read from origin, as exactly one expression; false for anything else: a diagnostic, a trailing remainder, or no expression at all.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Span source.Span
Message string
// Code classifies the diagnostic for the consumers that report it: every
// warning carries one, and an error one only when it is a specific
// finding; ErrorCode gives an error's reporting code.
Code string
// Fixes are the unambiguous edits resolving the diagnostic, offered by an
// editor as quick fixes.
Fixes []diag.Fix
}
Diagnostic is a parser-emitted syntax error. It is unified with the pass/validation diagnostic model in Plan 4; kept local here to avoid a premature cross-package dependency.
func (Diagnostic) ErrorCode ¶ added in v0.10.0
func (d Diagnostic) ErrorCode() string
ErrorCode is the code an error is reported under: its own when it has one, else CodeSyntax.
type Parser ¶
type Parser struct {
// Diagnostics are syntax errors: input the parser could not read as
// well-formed SysML.
Diagnostics []Diagnostic
// Warnings are findings on input that parsed into the tree the author
// intended but is not well-formed SysML, such as a reserved keyword written
// as a declaration name.
Warnings []Diagnostic
// contains filtered or unexported fields
}
Parser is a hand-written recursive-descent parser over a lexer token stream. It buffers non-trivia tokens for lookahead and collects diagnostics; it always produces a tree (ErrorNodes for bad input).
func (*Parser) Offset ¶
Offset returns the source offset of the next unconsumed token, which is where a caller parsing a sequence of productions continues from. A node's span is not that position: a parenthesized expression's span is its contents.
func (*Parser) ParseExpression ¶
ParseExpression parses a full expression (conditional at the lowest level).
func (*Parser) ParseFile ¶
func (p *Parser) ParseFile() *ast.RootNamespace
ParseFile parses the whole source as a RootNamespace (brace-less member list).
func (*Parser) ParseMultiplicity ¶ added in v0.9.2
func (p *Parser) ParseMultiplicity() *ast.Multiplicity
ParseMultiplicity parses one multiplicity beginning with `[` (SysML.xtext:878, 887; formal/2026-03-02).
type SyntaxError ¶ added in v0.10.0
type SyntaxError struct {
Name string
Messages []string
// Diags are the diagnostics behind Messages, for a caller that reports them
// with their spans. Empty when the input is not notation, since a Turtle
// reader reports a message and no span.
Diags []Diagnostic
// File is what Diags' spans point into; nil when Diags is empty.
File *source.SourceFile
}
SyntaxError reports that the input could not be read as its format. It lists every syntax error rather than only the first, so one conversion attempt shows everything that needs fixing.
func SyntaxErrorOf ¶ added in v0.10.0
func SyntaxErrorOf(name string, file *source.SourceFile, diags []Diagnostic) *SyntaxError
SyntaxErrorOf reports a document's parser diagnostics as a SyntaxError, or nil when there are none: a graph built from a tree the parser could not read whole would silently miss what it skipped.
func (*SyntaxError) Error ¶ added in v0.10.0
func (e *SyntaxError) Error() string