parser

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func BodyAdmitsBehaviorUsage(owner ast.Node) bool

BodyAdmitsBehaviorUsage reports whether owner’s body production admits a BehaviorUsageElement such as `satisfy`.

func BodyAdmitsMember

func BodyAdmitsMember(owner ast.Node, kw string) bool

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

func BodyIsCalculation(owner ast.Node) bool

BodyIsCalculation reports whether owner opens a calculation or case body, including constraint bodies, which use CalculationBody.

func BodyIsRequirement added in v0.9.2

func BodyIsRequirement(owner ast.Node) bool

BodyIsRequirement reports whether owner opens a requirement body.

func IsPrefixModifierKeyword added in v0.9.2

func IsPrefixModifierKeyword(kw string) bool

IsPrefixModifierKeyword reports whether kw is a feature/usage prefix modifier the parser reads before a declaration's kind keyword.

func MemberOwner

func MemberOwner(kw string) string

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

func ParseOneExpression(origin, text string) (ast.Node, bool)

ParseOneExpression parses text, read from origin, as exactly one expression; false for anything else: a diagnostic, a trailing remainder, or no expression at all.

func Reserves added in v0.10.0

func Reserves(kind source.Kind, keywordID string) bool

Reserves reports whether keywordID is reserved in a file of the given kind; the SysML-only words are names in KerML.

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 New

func New(sf *source.SourceFile) *Parser

New creates a Parser for the given source file.

func (*Parser) Offset

func (p *Parser) Offset() int

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

func (p *Parser) ParseExpression() ast.Node

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

Jump to

Keyboard shortcuts

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