Documentation ¶
Overview ¶
Package tokens contains the core symbol and token types for referencing resources and related entities.
Index ¶
- Constants
- Variables
- func IsName(s string) bool
- func IsQName(s string) bool
- func ValidateProjectName(s string) error
- type ClassMemberName
- type Module
- type ModuleMember
- type ModuleMemberName
- type ModuleName
- type Name
- type Package
- type PackageName
- type QName
- type Token
- func (tok Token) Delimiters() int
- func (tok Token) HasModule() bool
- func (tok Token) HasModuleMember() bool
- func (tok Token) Module() Module
- func (tok Token) ModuleMember() ModuleMember
- func (tok Token) Name() Name
- func (tok Token) Package() Package
- func (tok Token) Simple() bool
- func (tok Token) String() string
- type Type
- type TypeName
Constants ¶
const QNameDelimiter = "/"
QNameDelimiter is what delimits Namespace and Name parts.
const TokenDelimiter string = ":" // the character delimiting portions of a qualified token.
Variables ¶
var ( QNameRegexp = regexp.MustCompile(QNameRegexpPattern) QNameRegexpPattern = "(" + NameRegexpPattern + "\\" + QNameDelimiter + ")*" + NameRegexpPattern )
var (
NameRegexp = regexp.MustCompile(NameRegexpPattern)
)
var NameRegexpPattern = nameFirstCharRegexpPattern + nameRestCharRegexpPattern
Functions ¶
func ValidateProjectName ¶ added in v3.72.0
ValidateProjectName validates that the given string is a valid project name. The string must meet the following criteria:
- must be non-empty
- must be at most 100 characters
- must contain only alphanumeric characters, hyphens, underscores, and periods (see IsName)
Returns a descriptive error if the string is not a valid project name.
Types ¶
type ClassMemberName ¶
type ClassMemberName Name
ClassMemberName is a simple name representing the class member's identifier.
func (ClassMemberName) Name ¶
func (nm ClassMemberName) Name() Name
func (ClassMemberName) String ¶
func (nm ClassMemberName) String() string
type Module ¶
type Module Token
Module is a token representing a module. It uses the following subset of the token grammar:
Module = <Package> ":" <ModuleName>
Note that a module name of "." means "current module", to simplify emission and lookups.
func NewModuleToken ¶
func NewModuleToken(pkg Package, nm ModuleName) Module
func (Module) Name ¶
func (tok Module) Name() ModuleName
type ModuleMember ¶
type ModuleMember Token
ModuleMember is a token representing a module's member. It uses the following grammar. Note that this is not ambiguous because member names cannot contain slashes, and so the "last" slash in a name delimits the member:
ModuleMember = <Module> "/" <ModuleMemberName>
func NewModuleMemberToken ¶
func NewModuleMemberToken(mod Module, nm ModuleMemberName) ModuleMember
func ParseModuleMember ¶
func ParseModuleMember(s string) (ModuleMember, error)
ParseModuleMember attempts to turn the string s into a module member, returning an error if it isn't a valid one.
func (ModuleMember) Module ¶
func (tok ModuleMember) Module() Module
func (ModuleMember) Name ¶
func (tok ModuleMember) Name() ModuleMemberName
func (ModuleMember) Package ¶
func (tok ModuleMember) Package() Package
func (ModuleMember) String ¶
func (tok ModuleMember) String() string
type ModuleMemberName ¶
type ModuleMemberName Name
ModuleMemberName is a simple name representing the module member's identifier.
func (ModuleMemberName) String ¶
func (nm ModuleMemberName) String() string
type ModuleName ¶
type ModuleName QName
ModuleName is a qualified name referring to an imported module from a package.
func (ModuleName) String ¶
func (nm ModuleName) String() string
type Name ¶
type Name string
Name is an identifier. It conforms to NameRegexpPattern.
type Package ¶
type Package Token
Package is a token representing just a package. It uses a much simpler grammar:
Package = <PackageName>
Note that a package name of "." means "current package", to simplify emission and lookups.
func NewPackageToken ¶
func NewPackageToken(nm PackageName) Package
func (Package) Name ¶
func (tok Package) Name() PackageName
type PackageName ¶
type PackageName QName
PackageName is a qualified name referring to an imported package.
func (PackageName) String ¶
func (nm PackageName) String() string
type QName ¶
type QName string
QName is a qualified identifier. The "/" character optionally delimits different pieces of the name. Each element conforms to NameRegexpPattern. For example, "pulumi/pulumi/stack".
func IntoQName ¶ added in v3.21.0
IntoQName converts an arbitrary string into a QName, converting the string to a valid QName if necessary. The conversion is deterministic, but also lossy.
type Token ¶
type Token string
Token is a qualified name that is capable of resolving to a symbol entirely on its own. Most uses of tokens are typed based on the context, so that a subset of the token syntax is permissible (see the various typedefs below). However, in its full generality, a token can have a package part, a module part, a module-member part, and a class-member part. Obviously tokens that are meant to address just a module won't have the module-member part, and tokens addressing module members won't have the class-member part, etc.
Token's grammar is as follows:
Token = <Identifier> | <QualifiedToken> | <DecoratedType> Identifier = <Name> QualifiedToken = <PackageName> [ ":" <ModuleName> [ ":" <ModuleMemberName> [ ":" <ClassMemberName> ] ] ] PackageName = ... similar to <QName>, except dashes permitted ... ModuleName = <QName> ModuleMemberName = <Name> ClassMemberName = <Name>
A token may be a simple identifier in the case that it refers to a built-in symbol, like a primitive type, or a variable in scope, rather than a qualified token that is to be bound to a symbol through package/module resolution.
Notice that both package and module names may be qualified names (meaning they can have "/"s in them; see QName's comments), and that module and class members must use unqualified, simple names (meaning they have no delimiters). The specialized token kinds differ only in what elements they require as part of the token string.
Finally, a token may also be a decorated type. This is for built-in array, map, pointer, and function types:
DecoratedType = "*" <Token> | "[]" <Token> | "map[" <Token> "]" <Token> | "(" [ <Token> [ "," <Token> ]* ] ")" <Token>?
Notice that a recursive parsing process is required to extract elements from a <DecoratedType> token.
func (Token) Delimiters ¶
func (Token) HasModuleMember ¶
func (Token) ModuleMember ¶
func (tok Token) ModuleMember() ModuleMember
ModuleMember extracts the module member portion from the token, assuming one exists.
type Type ¶
type Type Token
Type is a token representing a type. It is either a primitive type name, reference to a module class, or decorated:
Type = <Name> | <ModuleMember> | <DecoratedType>
func NewTypeToken ¶
func ParseTypeToken ¶
ParseTypeToken interprets an arbitrary string as a Type, returning an error if the string is not a valid Type.
func (Type) DisplayName ¶ added in v3.64.0
DisplayName returns a simpler, user-readable version of this type name.
{package}:{module path truncated to the last slash}:{type name}
If not possible, it will return the string representation of the type.