identity

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 11 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

Overview

Package identity computes the effective repository identity of the symbols of an analyzed model: the id of an element's IdentityMetadata::ElementId annotation when it carries one, the normative UUID of a named standard library element, the id derived from its qualified name otherwise, plus the project scope its nearest enclosing ProjectRef declares. It is a side table keyed by symbol; the AST is never touched.

Index

Constants

View Source
const (
	ElementIdFQN  = "IdentityMetadata::ElementId"
	ProjectRefFQN = "IdentityMetadata::ProjectRef"
)

FQNs of the identity metadata definitions in the bundled library.

View Source
const ExtensionPrefix = "https://github.com/Open-MBEE/OpenSysML-Extensions-Library/"

ExtensionPrefix is the URL the OpenSysML extension-library package ids hash under: the libraries' upstream home, as the OMG libraries hash under their specification URL. Not the pilot's choice: loaded as a library directory, the pilot hashes any library under the SysML specification URL.

View Source
const Separator = "::"

Separator joins the segments of a qualified name.

Variables

View Source
var NamespaceOID = mustParse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")

NamespaceOID is the RFC 4122 name space for OIDs, under which the pilot and toolkit mint the ids of references that resolved to no library element.

View Source
var NamespaceURL = mustParse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")

NamespaceURL is the RFC 4122 name space for URLs, the root of every library id.

Functions

func DerivedID

func DerivedID(namespace, name string) string

DerivedID is uuid5(namespace, name), namespace spelled as a uuid5-derived id.

func ElementID

func ElementID(lang Language, qualifiedName string) string

ElementID is the fixed id of the library element with the given qualified name (segments as declared, the first its library package); "" for none. Normative for a KerML or SysML element, this implementation's for an OpenSysML one.

func ElementIdAbout

func ElementIdAbout(path, id string) string

ElementIdAbout renders a standalone ElementId annotation naming its element by the qualified path that resolves to it where the annotation is written.

func ElementIdInline

func ElementIdInline(id string) string

ElementIdInline renders an ElementId annotation for the body of the element it identifies.

func EscapeName

func EscapeName(name string) string

EscapeName spells a name as the pilot's qualified names do: an ASCII identifier or `$` as is, anything else single-quoted with control and quote characters escaped.

func LibraryVersion

func LibraryVersion(model *semantics.Model, res *resolve.Resolver, name string) string

LibraryVersion is the bundled library document the named indexed document is a version of, judged against the library the index holds apart from it: over a base, a copy indexed under a library file's own name is judged against that file.

func NamespaceOf

func NamespaceOf(name string) string

NamespaceOf is the uuid5 id namespace minted under the URL name space for name — the root a document's uuid element ids derive under.

func OwningMembershipID

func OwningMembershipID(lang Language, qualifiedName string) string

OwningMembershipID is the fixed id of the OwningMembership owning the library element with the given qualified name, a library package included.

func ProjectRefAbout

func ProjectRefAbout(path, projectID string) string

ProjectRefAbout renders a standalone ProjectRef annotation naming the namespace it binds by qualified path.

func ProjectRefInline

func ProjectRefInline(projectID string) string

ProjectRefInline renders a ProjectRef annotation for the body of the namespace it binds.

func Root

func Root(sym *symbols.Symbol) *symbols.Symbol

Root is the outermost declaration enclosing sym, sym itself at a root; a ProjectRef written there binds sym's whole document subtree.

func RootPackageNames

func RootPackageNames(root *ast.RootNamespace) (names []string, ok bool)

RootPackageNames lists the declared names of the parsed document's roots when every one is a package; ok is false for no document or a root that is not one.

func UnresolvedElementID

func UnresolvedElementID(qualifiedName string) string

UnresolvedElementID is the id an interchange document mints for a name that resolved to nothing: uuid5(NamespaceOID, "unresolved:"+qualifiedName).

Types

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Catalog indexes the normative ids of the bundled library by id: a version-5 UUID cannot be reversed, only looked up. Elements are indexed by name too; roots holds every library document's top-level packages, id or none, and kinds each document's language.

func LibraryCatalog

func LibraryCatalog(idx *symbols.Index) *Catalog

LibraryCatalog is the catalog of the library idx holds, shared by every overlay that shows its base's library documents as the base does.

func LibraryCatalogWithOpenSysML added in v0.11.0

func LibraryCatalogWithOpenSysML(idx *symbols.Index) *Catalog

LibraryCatalogWithOpenSysML combines normative and OpenSysML extension IDs for graph and API-JSON serialization without changing the normative catalog.

func OpenSysMLLibraryCatalog added in v0.11.0

func OpenSysMLLibraryCatalog(idx *symbols.Index) *Catalog

OpenSysMLLibraryCatalog catalogs the bundled OpenSysML extension elements separately from elements whose IDs are verified by the normative library XMI.

func (*Catalog) DocumentKind

func (c *Catalog) DocumentKind(doc string) source.Kind

DocumentKind is the language the named library document is written in.

func (*Catalog) DocumentRootedAt

func (c *Catalog) DocumentRootedAt(roots []LibraryRoot) string

DocumentRootedAt is the library document declaring every root as a top-level package under its name and its id, or with its package keywords where none is stated; "" when the roots are not one library document's.

func (*Catalog) Element

func (c *Catalog) Element(id string) (*LibraryElement, bool)

Element is the library element whose normative id is id.

func (*Catalog) ElementForSymbol added in v0.11.0

func (c *Catalog) ElementForSymbol(sym *symbols.Symbol) (*LibraryElement, bool)

ElementForSymbol is the catalogued library element declared by sym.

func (*Catalog) ElementNamed

func (c *Catalog) ElementNamed(fqn string) (*LibraryElement, bool)

ElementNamed is the library element whose qualified name is fqn.

func (*Catalog) Elements

func (c *Catalog) Elements() []*LibraryElement

Elements lists the catalogued elements in library walk order.

func (*Catalog) NamesEveryRoot

func (c *Catalog) NamesEveryRoot(root *ast.RootNamespace) bool

NamesEveryRoot reports whether every root of the parsed document is a package named as a library document's top-level package: the cheap test a document must pass before DocumentRootedAt is worth asking, and one a user file rarely does.

func (*Catalog) OwningMembership

func (c *Catalog) OwningMembership(id string) (*LibraryElement, bool)

OwningMembership is the library element whose owning membership has normative id id.

func (*Catalog) RootNamed

func (c *Catalog) RootNamed(fqn string) (*LibraryElement, bool)

RootNamed is the top-level package of a library document named fqn; its ID is "" when the document's tier has no normative language. A name more than one library document declares at its top names no single document, so it is not found.

func (*Catalog) VersionOf

func (c *Catalog) VersionOf(model *semantics.Model, res *resolve.Resolver, name string) string

VersionOf is the catalogued library document the named indexed document is a version of (see DocumentRootedAt); a root's id is the one an annotation declares, since an unannotated package states none. The document must be indexed unmarked, so its roots read as the user's declarations, and in the library document's language, which is what its text was parsed as.

type Declaration

type Declaration struct {
	// ID is the annotation's evaluated id; meaningful when Declared.
	ID string
	// Declared reports the id evaluated to a constant string.
	Declared bool
	// About marks an `about`-form annotation stated away from the element.
	About bool
	// Node is the annotating node itself, so a consumer that absorbs the
	// annotation into identity can identify it in the tree.
	Node ast.Node
	// Span locates the annotating node, for diagnostics.
	Span source.Span
	// Scope is where the annotating node is declared; for an `about`-form
	// annotation that may be another document than the element's.
	Scope *symbols.Scope
}

Declaration is one ElementId annotation of an element, whether written inline (`@ElementId {...}`) or from elsewhere (`metadata : ElementId about x;`).

type Info

type Info struct {
	Symbol *symbols.Symbol
	// FQN is the symbol's qualified name, which the derived id encodes.
	FQN string
	// EffectiveID is the annotated id when declared, the fixed id of a bundled
	// library element otherwise, the derived id failing both.
	EffectiveID string
	// Source is which of the four EffectiveID is.
	Source Source
	// Language is the library a fixed id is minted under; zero otherwise.
	Language Language
	// Annotated reports an ElementId annotation on the element.
	Annotated bool
	// Declared reports that the annotation's id evaluated to a constant
	// string; when false the derived id stands.
	Declared bool
	// DeclaredID is the evaluated ElementId id, possibly empty.
	DeclaredID string
	// AnnotationSpan locates the ElementId annotation, for diagnostics.
	AnnotationSpan source.Span
	// Declarations lists every ElementId annotation of the element, inline
	// ones first, `about`-form ones after.
	Declarations []Declaration
	// Scope is the nearest enclosing ProjectRef binding; nil when unbound.
	Scope *Scope
}

Info is one symbol's identity: its effective id, where it came from, and the project scope it resolves against.

func Of

func Of(model *semantics.Model, res *resolve.Resolver, sym *symbols.Symbol) (*Info, bool)

Of computes the identity of one symbol without building a whole table; ok is false for a symbol that has no qualified name to derive an id from.

func (*Info) Fixed added in v0.11.0

func (i *Info) Fixed() bool

Fixed reports an effective id a bundled library fixes for the element: the norm's for a standard library element, this implementation's for an extension's.

func (*Info) Normative

func (i *Info) Normative() bool

Normative reports an effective id the norm fixes for the element.

func (*Info) OwningMembershipID

func (i *Info) OwningMembershipID() string

OwningMembershipID is the fixed id of the membership owning a bundled library element; "" for any other, whose membership id derives from its own.

type Language

type Language uint8

Language is the half of the standard library an element belongs to, which picks the prefix its library package's id is minted under.

const (
	// KerML is the Kernel libraries: Kernel Semantic, Data Type and Function.
	KerML Language = iota + 1
	// SysML is the Systems and Domain libraries.
	SysML
	// OpenSysML is this implementation's own extension libraries, whose ids it
	// fixes the same way under their upstream URL.
	OpenSysML
)

func LibraryLanguage

func LibraryLanguage(tier symbols.LibraryTier) (Language, bool)

LibraryLanguage is the library a bundled tier's ids are fixed under: Kernel is KerML, Systems and Domain are SysML, this implementation's extensions are OpenSysML; an unplaced library tier and the workspace are none.

func (Language) Prefix

func (l Language) Prefix() string

Prefix is the URL the language's library package ids hash under.

func (Language) String

func (l Language) String() string

type LibraryElement

type LibraryElement struct {
	Symbol             *symbols.Symbol
	FQN                string
	Language           Language
	ID                 string
	OwningMembershipID string
}

LibraryElement is one named element of a bundled library and the ids fixed for it and for the membership that owns it: the norm's for the standard library, this implementation's for its extension libraries.

type LibraryRoot

type LibraryRoot struct {
	QName, ID string
	// Pkg reports a root written as a package; Library and Standard are its keywords.
	Pkg, Library, Standard bool
}

LibraryRoot is one root of a document, as library recognition reads it: its qualified name, the id it states ("" for none), and how it is declared.

type Scope

type Scope struct {
	ProjectID string
	Branch    string
	Org       string
	// Symbol is the namespace carrying the ProjectRef annotation.
	Symbol *symbols.Symbol
	// Declarations lists every ProjectRef annotation of the namespace, inline
	// ones first, `about`-form ones after. The first supplies the binding.
	Declarations []ScopeDeclaration
}

Scope is one ProjectRef annotation's project binding. Two scopes name the same project when org and projectId agree; branch selects a version of one project, never another identity, so it plays no part in equality.

func (*Scope) Key

func (s *Scope) Key() string

Key names the project a scope binds to, for scope-equality grouping.

type ScopeDeclaration

type ScopeDeclaration struct {
	ProjectID string
	Branch    string
	Org       string
	// Node is the annotating node itself, so a consumer that absorbs the
	// annotation into provenance can identify it in the tree.
	Node ast.Node
	// Span locates the annotating node, for diagnostics.
	Span source.Span
	// Scope is where the annotating node is declared.
	Scope *symbols.Scope
}

ScopeDeclaration is one ProjectRef annotation of a namespace, whether written inline or from elsewhere with an `about` clause.

func (ScopeDeclaration) Key

func (d ScopeDeclaration) Key() string

Key names the project a declaration binds to; branch selects a version of one project, never another identity, so it plays no part.

type Source

type Source uint8

Source is where an element's effective id comes from.

const (
	// SourceDerived is the encoding of the qualified name, the default.
	SourceDerived Source = iota
	// SourceNormative is the UUID the norm fixes for a named standard library element.
	SourceNormative
	// SourceDeclared is the id an ElementId annotation declares.
	SourceDeclared
	// SourceExtension is the UUID this implementation fixes for a named element
	// of its own extension libraries, derived as a normative id under their URL.
	SourceExtension
)

func (Source) Fixed added in v0.11.0

func (s Source) Fixed() bool

Fixed reports an id a bundled library fixes: normative or extension.

func (Source) String

func (s Source) String() string

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is the identity side table of one analyzed scope tree.

func Build

func Build(model *semantics.Model, res *resolve.Resolver, roots ...*symbols.Scope) *Table

Build computes the identity side table of every named symbol under the given roots, in root order.

func (*Table) Info

func (t *Table) Info(sym *symbols.Symbol) (*Info, bool)

Info returns the identity of sym, if the table holds it.

func (*Table) Symbols

func (t *Table) Symbols() []*symbols.Symbol

Symbols returns the table's symbols in deterministic walk order.

Jump to

Keyboard shortcuts

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