{"modulePath":"github.com/Open-MBEE/OpenSysML","version":"v0.13.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package parser\n\n## Constants\n\n```go\nconst CodeSyntax = \"syntax\"\n```\nCodeSyntax is the code an error is reported under when its reporter gave it none: the general ill-formed-parse finding.\n\n## Functions\n\n```go\nfunc AsDiagnostics(errors, warnings []Diagnostic) []diag.Diagnostic\n```\nAsDiagnostics 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.\n\n```go\nfunc BodyAdmitsBehaviorUsage(owner ast.Node) bool\n```\nBodyAdmitsBehaviorUsage reports whether owner’s body production admits a BehaviorUsageElement such as \\`satisfy\\`.\n\n```go\nfunc BodyAdmitsMember(owner ast.Node, kw string) bool\n```\nBodyAdmitsMember reports whether the body of owner — a Definition or Usage; a package or the document root opens a package body, anything else a plain namespace body — offers the member keyword kw introduces; as for MemberOwner, kw may be a notation.\n\n```go\nfunc BodyIsCalculation(owner ast.Node) bool\n```\nBodyIsCalculation reports whether owner opens a calculation or case body, including constraint bodies, which use CalculationBody.\n\n```go\nfunc BodyIsRequirement(owner ast.Node) bool\n```\nBodyIsRequirement reports whether owner opens a requirement body.\n\n```go\nfunc IsPrefixModifierKeyword(kw string) bool\n```\nIsPrefixModifierKeyword reports whether kw is a feature/usage prefix modifier the parser reads before a declaration's kind keyword.\n\n```go\nfunc MemberOwner(kw string) string\n```\nMemberOwner 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.\n\n```go\nfunc ParseOneExpression(origin, text string) (ast.Node, bool)\n```\nParseOneExpression parses text, read from origin, as exactly one expression; false for anything else: a diagnostic, a trailing remainder, or no expression at all.\n\n```go\nfunc Reserves(kind source.Kind, keywordID string) bool\n```\nReserves reports whether keywordID is reserved in a file of the given kind. Xtext reserves a literal within the grammar that declares it, and the two grammars share only KerMLExpressions.xtext, so a word only the other grammar spells is a name here; a source of unknown kind reserves both sets.\n\n## Types\n\n```go\ntype Diagnostic struct {\n\tSpan    source.Span\n\tMessage string\n\t// Code classifies the diagnostic for the consumers that report it: every\n\t// warning carries one, and an error one only when it is a specific\n\t// finding; ErrorCode gives an error's reporting code.\n\tCode string\n\t// Fixes are the unambiguous edits resolving the diagnostic, offered by an\n\t// editor as quick fixes.\n\tFixes []diag.Fix\n}\n```\nDiagnostic 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.\n\n```go\nfunc (d Diagnostic) ErrorCode() string\n```\nErrorCode is the code an error is reported under: its own when it has one, else CodeSyntax.\n\n```go\ntype Parser struct {\n\n\t// Diagnostics are syntax errors: input the parser could not read as\n\t// well-formed SysML.\n\tDiagnostics []Diagnostic\n\t// Warnings are findings on input that parsed into the tree the author\n\t// intended but is not well-formed SysML, such as a reserved keyword written\n\t// as a declaration name.\n\tWarnings []Diagnostic\n\t// contains filtered or unexported fields\n}\n```\nParser 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).\n\n```go\nfunc New(sf *source.SourceFile) *Parser\n```\nNew creates a Parser for the given source file.\n\n```go\nfunc (p *Parser) Offset() int\n```\nOffset 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.\n\n```go\nfunc (p *Parser) ParseExpression() ast.Node\n```\nParseExpression parses a full expression (conditional at the lowest level).\n\n```go\nfunc (p *Parser) ParseFile() *ast.RootNamespace\n```\nParseFile parses the whole source as a RootNamespace (brace-less member list).\n\n```go\nfunc (p *Parser) ParseMultiplicity() *ast.Multiplicity\n```\nParseMultiplicity parses one multiplicity beginning with \\`\\[\\` (SysML.xtext:878, 887; formal/2026-03-02).\n\n```go\ntype Scanner struct {\n\t// contains filtered or unexported fields\n}\n```\nScanner reads a file's tokens as the parser does. The lexer tokenizes the union of both languages' keywords; a keyword the file's own grammar does not reserve — a KerML-only literal such as \\`step\\` in a \\`.sysml\\` file, a SysML-only one such as \\`action\\` in \\`.kerml\\` — is the name it is there, so the Scanner hands it on as an Identifier. The one exception is a named declaration of the other notation: \\`step s;\\` in a \\`.sysml\\` file keeps its keyword, so the declaration parses and the notation pass can report it, where \\`step \\\u003c= bound\\`, \\`step : Real;\\`, \\`step { }\\` and \\`(step)\\` read the name. The rule is the same for every consumer of the token stream (parser, semantic tokens), so they classify a word alike.\n\n```go\nfunc NewScanner(sf *source.SourceFile) *Scanner\n```\nNewScanner returns a Scanner over sf.\n\n```go\nfunc (s *Scanner) Next() lexer.Token\n```\nNext returns the next token, trivia included; EOF is returned repeatedly.\n\n```go\ntype SyntaxError struct {\n\tName     string\n\tMessages []string\n\t// Diags are the diagnostics behind Messages, for a caller that reports them\n\t// with their spans. Empty when the input is not notation, since a Turtle\n\t// reader reports a message and no span.\n\tDiags []Diagnostic\n\t// File is what Diags' spans point into; nil when Diags is empty.\n\tFile *source.SourceFile\n}\n```\nSyntaxError 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.\n\n```go\nfunc SyntaxErrorOf(name string, file *source.SourceFile, diags []Diagnostic) *SyntaxError\n```\nSyntaxErrorOf 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.\n\n```go\nfunc (e *SyntaxError) Error() string\n```\n\n","path":"github.com/Open-MBEE/OpenSysML/internal/syntax/parser","name":"parser","synopsis":"","isRedistributable":true}
