Documentation ¶
Overview ¶
Package tokens contains the core symbol and token types for referencing resources and related entities.
Index ¶
- Constants
- Variables
- func IsArrayType(tok Type) bool
- func IsFunctionType(tok Type) bool
- func IsMapType(tok Type) bool
- func IsName(s string) bool
- func IsPackageName(s string) bool
- func IsPointerType(tok Type) bool
- func IsQName(s string) bool
- type Accessibility
- type ArrayType
- type ByName
- type ClassMember
- type ClassMemberName
- type Function
- type FunctionType
- type MapType
- type Module
- type ModuleMember
- type ModuleMemberName
- type ModuleName
- type Name
- type Package
- type PackageName
- type PointerType
- type QName
- type Token
- func (tok Token) ClassMember() ClassMember
- func (tok Token) Delimiters() int
- func (tok Token) HasClassMember() bool
- 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
- func (tok Type) Array() bool
- func (tok Type) Decorated() bool
- func (tok Type) Function() bool
- func (tok Type) Map() bool
- func (tok Type) Member() ModuleMember
- func (tok Type) Module() Module
- func (tok Type) Name() TypeName
- func (tok Type) Package() Package
- func (tok Type) Pointer() bool
- func (tok Type) Primitive() bool
- func (tok Type) String() string
- type TypeName
- type Variable
Constants ¶
const ( EntryPointFunction ModuleMemberName = ".main" // the special package entrypoint function. ModuleInitFunction ModuleMemberName = ".init" // the special module initialization function. ClassConstructorFunction ClassMemberName = ".ctor" // the special class instance constructor function. ClassInitFunction ClassMemberName = ".init" // the special class initialization function. )
Special function names.
const ( PointerTypeDecors = PointerTypePrefix + "%v" PointerTypePrefix = "*" )
const ( ArrayTypeDecors = ArrayTypePrefix + "%v" ArrayTypePrefix = "[]" )
const ( MapTypeDecors = MapTypePrefix + "%v" + MapTypeSeparator + "%v" MapTypePrefix = "map[" MapTypeSeparator = "]" )
const ( FunctionTypeDecors = FunctionTypePrefix + "%v" + FunctionTypeSeparator + "%v" FunctionTypePrefix = "(" FunctionTypeParamSeparator = "," FunctionTypeSeparator = ")" )
const QNameDelimiter = "/"
QNameDelimiter is what delimits Namespace and Name parts.
const TokenDelimiter string = ":" // the character delimiting portions of a qualified token.
Variables ¶
var NameRegexp = regexp.MustCompile(NameRegexpPattern)
var NameRegexpPattern = "[A-Za-z_.][A-Za-z0-9_.]*"
var PackageNameRegexp = regexp.MustCompile(PackageNameRegexpPattern)
var PackageNameRegexpPattern = "(" + PackagePartRegexpPattern + "\\" + QNameDelimiter + ")*" + PackagePartRegexpPattern
var PackagePartRegexpPattern = "[A-Za-z_.][A-Za-z0-9_.-]*"
var QNameRegexp = regexp.MustCompile(QNameRegexpPattern)
var QNameRegexpPattern = "(" + NameRegexpPattern + "\\" + QNameDelimiter + ")*" + NameRegexpPattern
Functions ¶
func IsArrayType ¶
IsArrayType returns true if the given type token represents an encoded pointer type.
func IsFunctionType ¶
IsFunctionType returns true if the given type token represents an encoded pointer type.
func IsPackageName ¶
IsPackageName checks whether a string is a legal Name.
func IsPointerType ¶
IsPointerType returns true if the given type token represents an encoded pointer type.
Types ¶
type Accessibility ¶
type Accessibility string
Accessibility determines the visibility of a class member.
const ( PublicAccessibility Accessibility = "public" PrivateAccessibility Accessibility = "private" ProtectedAccessibility Accessibility = "protected" )
Accessibility modifiers.
type ArrayType ¶
type ArrayType struct { Tok Type // the full array type token. Elem Type // the element portion of the array type token. }
ArrayType is a type token that decorates an element type token to turn it into an array: `"[]" <Elem>`.
func ParseArrayType ¶
ParseArrayType removes the array decorations from a token and returns its underlying type.
type ByName ¶
type ByName []Token
ByName implements sort.Interface to allow an array of tokens to be sorted based on string order.
type ClassMember ¶
type ClassMember Token
ClassMember is a token representing a class's member. It uses the following grammar. Unlike ModuleMember, this cannot use a slash for delimiting names, because we use often ClassMember and ModuleMember interchangeably:
ClassMember = <ModuleMember> "." <ClassMemberName>
func NewClassMemberToken ¶
func NewClassMemberToken(class Type, nm ClassMemberName) ClassMember
func (ClassMember) Class ¶
func (tok ClassMember) Class() Type
func (ClassMember) Module ¶
func (tok ClassMember) Module() Module
func (ClassMember) Name ¶
func (tok ClassMember) Name() ClassMemberName
func (ClassMember) Package ¶
func (tok ClassMember) Package() Package
func (ClassMember) String ¶
func (tok ClassMember) String() string
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 Function ¶
type Function Token
Function is a token representing a variable (module method or class method). Its grammar is as follows:
Variable = <ModuleMember> | <ClassMember>
type FunctionType ¶
type FunctionType struct { Tok Type // the full map type token. Parameters []Type // the parameter parts of the type token. Return *Type // the (optional) return part of the type token. }
FunctionType is a type token that decorates a set of optional parameter and return tokens to turn them into a function type: `(" [ <Param1> [ "," <ParamN> ]* ] ")" [ <Return> ]`).
func ParseFunctionType ¶
func ParseFunctionType(tok Type) FunctionType
ParseFunctionType removes the function decorations from a token and returns its underlying type.
type MapType ¶
type MapType struct { Tok Type // the full map type token. Key Type // the key portion of the map type token. Elem Type // the element portion of the map type token. }
MapType is a type token that decorates a key and element type token to turn them into a map:
`"map[" <Key> "]" <Elem>`.
func ParseMapType ¶
ParseMapType removes the map decorations from a token and returns its underlying type.
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.
const (
DefaultModule ModuleName = ".default" // used to reference the default module.
)
Special module names.
func (ModuleName) String ¶
func (nm ModuleName) String() string
type Name ¶
type Name string
Name is an identifier. It conforms to the regex [A-Za-z_.][A-Za-z0-9_]*.
const ( ThisVariable Name = ".this" // the current object (for class methods). SuperVariable Name = ".super" // the parent class object (for class methods). )
Special variable names.
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 string
PackageName is a qualified name referring to an imported package. It is similar to a QName, except that it permits dashes "-" as is commonplace with packages of various kinds.
func (PackageName) String ¶
func (nm PackageName) String() string
type PointerType ¶
type PointerType struct { Tok Type // the full pointer type token. Elem Type // the element portion of the pointer type token. }
PointerType is a type token that decorates an element type token turn it into a pointer: `"*" <Elem>`.
func ParsePointerType ¶
func ParsePointerType(tok Type) PointerType
ParsePointerType removes the pointer decorations from a token and returns its underlying type.
type QName ¶
type QName string
QName is a qualified identifier. The "/" character optionally delimits different pieces of the name. Each element conforms to the Name regex [A-Za-z_][A-Za-z0-9_]*. For example, "pulumi/pulumi/stack".
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) ClassMember ¶
func (tok Token) ClassMember() ClassMember
ClassMember extracts the class member portion from the token, assuming one exists.
func (Token) Delimiters ¶
func (Token) HasClassMember ¶
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 NewArrayTypeToken ¶
NewArrayTypeToken creates a new array type token from an element type.
func NewFunctionTypeToken ¶
NewFunctionTypeToken creates a new function type token from parameter and return types.
func NewMapTypeToken ¶
NewMapTypeToken creates a new map type token from an element type.
func NewPointerTypeToken ¶
NewPointerTypeToken creates a new array type token from an element type.
func NewTypeToken ¶
func (Type) Member ¶
func (tok Type) Member() ModuleMember
type TypeName ¶
type TypeName Name
TypeName is a simple name representing the type's name, without any package/module qualifiers.
func NewArrayTypeName ¶
NewArrayTypeName creates a new array type name from an element type.
func NewFunctionTypeName ¶
NewFunctionTypeName creates a new function type token from parameter and return types.
func NewMapTypeName ¶
NewMapTypeName creates a new map type name from an element type.
func NewPointerTypeName ¶
NewPointerTypeName creates a new array type name from an element type.