parser

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 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 diagnostic code every reporter gives a parse error.

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 syntax, 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.

Types

type Diagnostic

type Diagnostic struct {
	Span    source.Span
	Message string
	// Code classifies a warning for the consumers that report it; errors carry
	// the "syntax" code their reporters give them.
	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.

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

Jump to

Keyboard shortcuts

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