{"modulePath":"github.com/Open-MBEE/OpenSysML","version":"v0.13.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package source\n\nPackage source provides source file management and text indexing for the SysML v2 parser, and the notation's text forms that every layer above it reads and writes.\n\nThis package defines SourceFile, which represents a single input file (either .sysml or .kerml), along with Span and Position types for tracking locations in source text. LineIndex provides efficient line/column lookups for error reporting and IDE features.\n\nIt also holds the KerML and SysML keyword sets and the helpers that read and write notation text without a parse: names (NameText, QualifiedNameText), string values (StringValue, StringText) and comment bodies (CommentBody).\n\nAll source locations are represented as byte offsets; LineIndex converts between offsets and user-facing line:column positions on demand.\n\nPackage source owns file content and byte-offset span types.\n\n## Functions\n\n```go\nfunc AdmittedEscapes() string\n```\nAdmittedEscapes spells the escape sequences the lexer admits, in table order.\n\n```go\nfunc CommentBody(raw string) string\n```\nCommentBody is the body a REGULAR\\_COMMENT gives its Comment, Documentation or TextualRepresentation (KerML 1.1 §8.2.3.3.2 Note 1): the delimiters come off, then the white space after \\`/\\*\\` up to and including the first line terminator; each later line loses its initial white space, then a \\`\\*\\`, then one space. All other text, line breaks and white space stay as entered. A \\`\\\\r\\\\n\\` or \\`\\\\r\\` line terminator reads as \\`\\\\n\\`.\n\n```go\nfunc CommentBodyOffsets(raw string) (body string, offsets []int)\n```\nCommentBodyOffsets is CommentBody with provenance: offsets\\[i] is the index in raw of the byte body\\[i] came from, and offsets\\[len(body)] the index just past the last body byte, so a span inside the body maps back onto raw.\n\n```go\nfunc CommentProse(raw string) string\n```\nCommentProse reads a comment or note token as display prose: the \\`/\\* \\*/\\`, \\`/\\*\\* \\*/\\`, \\`//\\* \\*/\\` or \\`//\\` delimiters come off, as does each line's indentation and the \\`\\*\\` margin a block comment runs down its left edge. Lines keep their breaks.\n\n```go\nfunc CommentText(body, indent string) (string, bool)\n```\nCommentText writes a REGULAR\\_COMMENT whose CommentBody is body, its later lines opening with the \\` \\* \\` margin under indent. False for a body no comment carries: \\`\\*/\\` would close it, and \\`\\\\r\\` is not a line break it reads back.\n\n```go\nfunc Dir(name string) string\n```\nDir is the directory of a source file's name when IsFile, else \"\".\n\n```go\nfunc DominantNewline(content []byte) string\n```\nDominantNewline reports the line ending text written into content should use: CRLF only when content already uses it more than bare LF.\n\n```go\nfunc EscapeLetter(c byte) (letter byte, ok bool)\n```\nEscapeLetter is the letter that, after a backslash, names c; ok is false for a character no admitted escape names.\n\n```go\nfunc FileNamed(doc string, _ Span) string\n```\nFileNamed is the Locate for documents named after the file they hold: the name itself when IsFile, else \"\".\n\n```go\nfunc IsEscapeChar(c byte) bool\n```\nIsEscapeChar reports whether c may follow a backslash in a STRING\\_VALUE or UNRESTRICTED\\_NAME: Table 4's letters and the pilot grammar's \\`r\\`.\n\n```go\nfunc IsFile(name string) bool\n```\nIsFile reports whether a source file's name is a path on disk rather than empty, a \\`\\\u003cplaceholder\u003e\\` such as standard input's, or a URI.\n\n```go\nfunc IsIdentCont(c byte) bool\n```\nIsIdentCont reports whether c may continue a basic name: a letter, digit or \\`\\_\\`.\n\n```go\nfunc IsIdentStart(c byte) bool\n```\nIsIdentStart reports whether c may open a basic name: a letter or \\`\\_\\`.\n\n```go\nfunc IsIdentifier(s string) bool\n```\nIsIdentifier reports whether s can be written as a basic name (KerML §8.2.2); a name that cannot needs the quotes of an unrestricted name.\n\n```go\nfunc IsKeyword(s string) bool\n```\nIsKeyword reports whether s is a KerML or SysML keyword, and so cannot be used where a plain identifier is expected in either language.\n\n```go\nfunc IsKeywordIn(s string, kind Kind) bool\n```\nIsKeywordIn reports whether s is reserved by one language's grammar.\n\n```go\nfunc IsStandardEscapeChar(c byte) bool\n```\nIsStandardEscapeChar reports whether backslash-c is an escape sequence of KerML §8.2.2.3 Table 4, which §8.2.2.5 gives STRING\\_VALUE too.\n\n```go\nfunc Keywords() []string\n```\nKeywords returns a copy of the KerML+SysML keyword list, for tooling (e.g. LSP completion). The returned slice is safe to mutate.\n\n```go\nfunc MemberPathOf(names []string) string\n```\nMemberPathOf writes the segments of a member path, outermost first, joined by '.', each quoted on its own like a qualified name segment.\n\n```go\nfunc MemberPathSegments(text string) ([]string, bool)\n```\nMemberPathSegments reads a member path — \\`.\\`-joined basic or 'quoted' names, a bare name being a one-segment path — into its names, unquoted and decoded; false when malformed.\n\n```go\nfunc MetadataPathSegments(path string) (definition []string, feature string, ok bool)\n```\nMetadataPathSegments splits a metadata path into the metadata definition's segments and the feature name.\n\n```go\nfunc NameText(name string) string\n```\nNameText writes a name as the notation spells it: one that is no basic name is quoted as an unrestricted name with its escapes written (KerML §8.2.2), so it parses back.\n\n```go\nfunc QualifiedNameOf(names []string) string\n```\nQualifiedNameOf writes names, outermost first, as one qualified name, each quoted on its own; a name may hold \\`::\\`, so the text is read back exactly.\n\n```go\nfunc QualifiedNameSegments(text string) ([]string, bool)\n```\nQualifiedNameSegments reads a qualified name back into its names, \\`'x::y'\\` one and \\`x::y\\` two, quotes dropped and escapes decoded; false for malformed text.\n\n```go\nfunc QualifiedNameText(fqn string) string\n```\nQualifiedNameText writes a qualified name segment by segment, since each segment is a name of its own and is quoted on its own. An empty name is written as it stands.\n\n```go\nfunc ReferenceEndNames(text string) string\n```\nReferenceEndNames rewrites a typing's references — \\`, \\` apart, each a qualified name or feature chain, \\`$::\\` led or \\`~\\` conjugated — by the name each ends in, \\`~\\` kept; text that does not read as such is returned as it is.\n\n```go\nfunc ReferenceQualifiedNames(text string) [][]string\n```\nReferenceQualifiedNames reads a typing's references — \\`, \\` apart, \\`$::\\` led or \\`~\\` conjugated — into each one's names; a feature chain, or text that does not read as references, contributes none.\n\n```go\nfunc ReplaceFile(source, target string) error\n```\nReplaceFile renames source over target, atomically where the platform allows. Where the platform refuses a rename over what is at target, it retries after removing that; any other failure — the source missing, another device — leaves the target as it was. A target that is a link is replaced, never followed.\n\n```go\nfunc StandardEscapes() string\n```\nStandardEscapes spells the escape sequences of KerML §8.2.2.3 Table 4.\n\n```go\nfunc StandardStringText(value string) string\n```\nStandardStringText is StringText writing Table 4's escapes alone: U+000D, which only the extension \\`\\\\r\\` names, stands as it is, so the literal passes a strict check.\n\n```go\nfunc StandardUnrestrictedNameText(value string) string\n```\nStandardUnrestrictedNameText is UnrestrictedNameText writing Table 4's escapes alone.\n\n```go\nfunc StringText(value string) string\n```\nStringText writes a value as the double-quoted STRING\\_VALUE token that StringValue reads back to it, escaping the quote, the backslash and the control characters KerML §8.2.2 names; everything else stands as it is.\n\n```go\nfunc StringValue(raw string) string\n```\nStringValue reads the text a STRING\\_VALUE token spells: the quotes come off and the backslash escapes KerML §8.2.2 defines stand for the characters they name. A backslash before anything else (rejected by the scanner) stands for that character itself, and a token the scanner reported unterminated has only its opening quote to come off.\n\n```go\nfunc Unescape(raw string) string\n```\nUnescape reads the backslash escapes KerML §8.2.2 defines as the characters they name; a backslash before anything else stands for that character itself, and text with no backslash stands as it is.\n\n```go\nfunc UnrestrictedNameText(value string) string\n```\nUnrestrictedNameText writes raw text as the quoted unrestricted name whose value is that text, escaping the quote, the backslash and the control characters.\n\n## Types\n\n```go\ntype Kind int\n```\nKind is the language a source is parsed as. The two languages share a lexer but not a grammar: KerML notation in a SysML file is diagnosed.\n\n```go\nconst (\n\t// KindUnknown is a name with neither model extension.\n\tKindUnknown Kind = iota\n\t// KindSysML is a `.sysml` file, whose grammar is SysML.xtext.\n\tKindSysML\n\t// KindKerML is a `.kerml` file, whose grammar is KerML.xtext.\n\tKindKerML\n)\n```\n\n```go\nfunc KindOf(name string) Kind\n```\nKindOf reports the language of a file name by its extension.\n\n```go\nfunc (k Kind) String() string\n```\nString returns the language's name.\n\n```go\ntype LineIndex struct {\n\t// contains filtered or unexported fields\n}\n```\nLineIndex maps byte offsets to 1-based line/column positions. lineStarts\\[i] is the byte offset where line (i+1) begins.\n\n```go\nfunc NewLineIndex(content []byte) *LineIndex\n```\nNewLineIndex builds the index of content's line starts.\n\n```go\nfunc (li *LineIndex) OffsetAt(p Pos) int\n```\nOffsetAt returns the byte offset for a 1-based line/col, -1 for a line the content does not have or a column outside that line.\n\n```go\nfunc (li *LineIndex) PosAt(offset int) Pos\n```\nPosAt returns the 1-based line/col for a byte offset. Col counts bytes from the line start + 1.\n\n```go\nfunc (li *LineIndex) Splice(content []byte, start, end, inserted int)\n```\nSplice updates the index in place for an edit that replaced bytes \\[start, end) by inserted bytes; content is the text after it. Rebuild a shared index instead.\n\n```go\ntype Locate func(doc string, span Span) string\n```\nLocate answers the file on disk a span of the named document was read from, or \"\" for text that came from no file: a buffer, standard input, a library.\n\n```go\ntype Lookup func(doc string, span Span) string\n```\nLookup answers the text a span of the named document covers, or \"\" for a document it does not hold.\n\n```go\nfunc TextOf(files map[string]*SourceFile, next Lookup) Lookup\n```\nTextOf answers spans from files by document name, shadowing next; a name not among files goes to next, \"\" when next is nil.\n\n```go\ntype Pos struct {\n\tLine int\n\tCol  int\n}\n```\nPos is a 1-based line/column location.\n\n```go\ntype SourceFile struct {\n\t// contains filtered or unexported fields\n}\n```\nSourceFile owns the raw bytes of one source file.\n\n```go\nfunc New(name string, content []byte) *SourceFile\n```\nNew creates a SourceFile from a name and its raw bytes.\n\n```go\nfunc NewWithKind(name string, content []byte, kind Kind) *SourceFile\n```\nNewWithKind creates a source file whose language is explicit rather than inferred from its name. This is used for inline KerML content.\n\n```go\nfunc (sf *SourceFile) Bytes() []byte\n```\nBytes returns the raw content (do not mutate).\n\n```go\nfunc (sf *SourceFile) Kind() Kind\n```\nKind reports the language of this file.\n\n```go\nfunc (sf *SourceFile) Len() int\n```\nLen returns the byte length of the content.\n\n```go\nfunc (sf *SourceFile) Lines() *LineIndex\n```\nLines returns the cached line index for this file, building it on first use. Col is a byte column (1-based). LSP requires UTF-16 code-unit columns; that conversion is an LSP-layer concern (Plan 06), not the source package.\n\n```go\nfunc (sf *SourceFile) Name() string\n```\nName returns the file name.\n\n```go\nfunc (sf *SourceFile) Text(sp Span) string\n```\nText returns the substring covered by the span from one cached copy of the content, \"\" for a span that does not lie within it.\n\n```go\ntype Span struct {\n\tOffset int\n\tLen    int\n}\n```\nSpan is a byte range within a SourceFile: \\[Offset, Offset+Len).\n\n```go\nfunc (s Span) Contains(other Span) bool\n```\nContains reports whether other lies within s.\n\n```go\nfunc (s Span) End() int\n```\nEnd returns the exclusive end offset.\n\n","path":"github.com/Open-MBEE/OpenSysML/internal/syntax/source","name":"source","synopsis":"Package source provides source file management and text indexing for the SysML v2 parser, and the notation's text forms that every layer above it reads and writes.","isRedistributable":true}
