Documentation ¶
Index ¶
- Variables
- func Lookup(id *Identifier) (*Declaration, *EnumReference, *Error)
- func ParseExpression(s string) (Expression, *Error)
- func ParseType(s string) (*Type, *Error)
- type AllocExpression
- type AppendExpression
- type ArrayLiteral
- type ArrayType
- type AssertExpression
- type AssignmentExpression
- type BinaryExpression
- type Binding
- type BindingExpression
- type BoolLiteral
- type CallExpression
- type CastExpression
- type CompoundExpression
- type ConstantDeclaration
- type ControlExpression
- type DeclAttr
- type Declaration
- type DeferExpression
- type DeleteExpression
- type EnumReference
- type EnumType
- type EnumValue
- type Error
- type ErrorPropExpression
- type Expression
- type FieldAccessExpression
- type File
- type FloatLiteral
- type ForExpression
- type FunctionAttrType
- type FunctionDeclaration
- type FunctionType
- type GlobalDeclaration
- type IConstType
- type Identifier
- type IfExpression
- type Import
- type ImportMember
- type IndexingExpression
- type InsertExpression
- type IntLiteral
- type LengthExpression
- type MatchCase
- type MatchExpression
- type Module
- type ModuleCache
- type ModuleConflictError
- type ModuleError
- type NullLiteral
- type OffsetExpression
- type Parameter
- type Position
- type Range
- type RuneLiteral
- type SizeExpression
- type SlicingExpression
- type StringLiteral
- type StructField
- type StructFieldValue
- type StructLiteral
- type StructType
- type SwitchCase
- type SwitchExpression
- type TaggedUnionType
- type Token
- type TokenType
- type Tokens
- func (t *Tokens) DocComment() []string
- func (t *Tokens) EOF() bool
- func (t *Tokens) Fail(tok Token, msg string)
- func (t *Tokens) Get(typ TokenType) (Token, bool)
- func (t *Tokens) GetRaw(raw string) bool
- func (t *Tokens) GetString(first Token) string
- func (t *Tokens) Last() Token
- func (t *Tokens) Must(typ TokenType, msg string) Token
- func (t *Tokens) MustRaw(raw string, msg string)
- func (t *Tokens) Next() Token
- func (t *Tokens) Ok() bool
- func (t *Tokens) Peek() Token
- func (t *Tokens) Sync() bool
- type Tuple
- type TupleType
- type Type
- type TypeData
- type TypeDeclaration
- type TypeStorage
- type UnaryExpression
- type Unit
- type VoidLiteral
Constants ¶
This section is empty.
Variables ¶
var ( TypeInt = &Type{Storage: StorageInt} TypeUint = &Type{Storage: StorageUint} TypeSize = &Type{Storage: StorageSize} TypeUintptr = &Type{Storage: StorageUintptr} TypeChar = &Type{Storage: StorageChar} TypeI8 = &Type{Storage: StorageI8} TypeI16 = &Type{Storage: StorageI16} TypeI32 = &Type{Storage: StorageI32} TypeI64 = &Type{Storage: StorageI64} TypeU8 = &Type{Storage: StorageU8} TypeU16 = &Type{Storage: StorageU16} TypeU32 = &Type{Storage: StorageU32} TypeU64 = &Type{Storage: StorageU64} TypeF32 = &Type{Storage: StorageF32} TypeF64 = &Type{Storage: StorageF64} TypeRune = &Type{Storage: StorageRune} TypeBool = &Type{Storage: StorageBool} TypeVoid = &Type{Storage: StorageVoid} TypeStr = &Type{Storage: StorageStr} TypeNull = &Type{Storage: StorageNull} TypeFConst = &Type{Storage: StorageFConst} TypeRConst = &Type{Storage: StorageRConst} TypeValist = &Type{Storage: StorageValist} )
Functions ¶
func Lookup ¶
func Lookup(id *Identifier) (*Declaration, *EnumReference, *Error)
Lookup searches for a currently visible declaration for the identifier. If the identifier references an enum value, the first return value will be the enum's type declaration, and the second return value will describe the value. Otherwise the second return value is nil.
func ParseExpression ¶
func ParseExpression(s string) (Expression, *Error)
Types ¶
type AllocExpression ¶
type AllocExpression struct { Token Token Init Expression Cap Expression Expand bool Free bool }
func (*AllocExpression) Range ¶
func (a *AllocExpression) Range() Range
type AppendExpression ¶
type AppendExpression struct { Token Token Target Expression Value Expression Len Expression Expand bool Static bool }
func (*AppendExpression) Range ¶
func (a *AppendExpression) Range() Range
type ArrayLiteral ¶
type ArrayLiteral struct {
Start, End Token
Members []Expression
Expand bool
}
func (*ArrayLiteral) Range ¶
func (a *ArrayLiteral) Range() Range
type ArrayType ¶
type ArrayType struct { Elem *Type Size Expression Unbounded bool ContextDefined bool }
type AssertExpression ¶
type AssertExpression struct { Token Token Assert Expression Message string Static bool }
func (*AssertExpression) Range ¶
func (a *AssertExpression) Range() Range
type AssignmentExpression ¶
type AssignmentExpression struct { Target Expression Operator Token Value Expression }
func (*AssignmentExpression) Range ¶
func (a *AssignmentExpression) Range() Range
type BinaryExpression ¶
type BinaryExpression struct {
L, R Expression
Operator Token
}
func (*BinaryExpression) Range ¶
func (b *BinaryExpression) Range() Range
type Binding ¶
type Binding struct { Names []Token Type *Type Value Expression Attr *DeclAttr Iterator bool }
type BindingExpression ¶
func (*BindingExpression) Range ¶
func (b *BindingExpression) Range() Range
type BoolLiteral ¶
type BoolLiteral struct{ Token }
type CallExpression ¶
type CallExpression struct { Func Expression Args []Expression Unwrap bool }
func (*CallExpression) Range ¶
func (c *CallExpression) Range() Range
type CastExpression ¶
type CastExpression struct { Value Expression Cast Token Type *Type }
func (*CastExpression) Range ¶
func (c *CastExpression) Range() Range
type CompoundExpression ¶
type CompoundExpression struct {
Start, End Token
Label Token
Expressions []Expression
}
func (*CompoundExpression) Range ¶
func (c *CompoundExpression) Range() Range
type ConstantDeclaration ¶
type ConstantDeclaration struct { Type *Type Value Expression }
type ControlExpression ¶
type ControlExpression struct { Control Token Label Token Expression Expression }
func (*ControlExpression) Range ¶
func (c *ControlExpression) Range() Range
type Declaration ¶
type Declaration struct { Comment []string Export bool Name *Identifier Ignore bool Data interface{} }
type DeferExpression ¶
type DeferExpression struct { Token Expression }
func (*DeferExpression) Range ¶
func (d *DeferExpression) Range() Range
type DeleteExpression ¶
type DeleteExpression struct { Token Token Target Expression Static bool }
func (*DeleteExpression) Range ¶
func (d *DeleteExpression) Range() Range
type EnumReference ¶
An EnumReference describes a member of an enum.
type EnumType ¶
type EnumType struct { Storage TypeStorage Members []EnumValue }
type EnumValue ¶
type EnumValue struct { Name Token Value Expression }
type Error ¶
func ResolveType ¶
type ErrorPropExpression ¶
type ErrorPropExpression struct { Value Expression Operator Token }
func (*ErrorPropExpression) Range ¶
func (e *ErrorPropExpression) Range() Range
type Expression ¶
type Expression interface {
Range() Range
}
type FieldAccessExpression ¶
type FieldAccessExpression struct { Prefix Expression Name Token Index int }
func (*FieldAccessExpression) Range ¶
func (f *FieldAccessExpression) Range() Range
type FloatLiteral ¶
type ForExpression ¶
type ForExpression struct { Token Binding *BindingExpression Condition Expression Afterthought Expression Body Expression }
type FunctionAttrType ¶
type FunctionAttrType int
const ( FunctionNormal FunctionAttrType = iota FunctionInit FunctionFini FunctionTest )
type FunctionDeclaration ¶
type FunctionDeclaration struct { Prototype FunctionType Body Expression Symbol string Attr FunctionAttrType }
type FunctionType ¶
type FunctionType struct { NoReturn bool Parameters []Parameter Varargs bool CVarargs bool Result *Type }
func (*FunctionType) Print ¶
func (f *FunctionType) Print(w io.StringWriter, name string)
func (*FunctionType) String ¶
func (f *FunctionType) String() string
type GlobalDeclaration ¶
type GlobalDeclaration struct { Const bool Type *Type Value Expression Symbol string }
type IConstType ¶
type Identifier ¶
func (*Identifier) Last ¶
func (i *Identifier) Last() Token
func (*Identifier) Print ¶
func (i *Identifier) Print(w io.StringWriter)
func (*Identifier) Range ¶
func (i *Identifier) Range() Range
func (*Identifier) String ¶
func (i *Identifier) String() string
type IfExpression ¶
type IfExpression struct { Token Condition Expression Then Expression Else Expression }
type Import ¶
type Import struct { Alias string Module Identifier All bool Members []ImportMember }
type ImportMember ¶
type IndexingExpression ¶
type IndexingExpression struct { Prefix Expression Index Expression }
func (*IndexingExpression) Range ¶
func (i *IndexingExpression) Range() Range
type InsertExpression ¶
type InsertExpression struct { Token Token Target Expression Value Expression Expand bool Static bool }
func (*InsertExpression) Range ¶
func (i *InsertExpression) Range() Range
type IntLiteral ¶
type LengthExpression ¶
type LengthExpression struct { Token Token Expression Expression }
func (*LengthExpression) Range ¶
func (l *LengthExpression) Range() Range
type MatchCase ¶
type MatchCase struct { Names []Token Type *Type Result []Expression }
type MatchExpression ¶
type MatchExpression struct { Token Value Expression Cases []MatchCase }
type Module ¶
type Module struct { // fully-qualified name, e.g. "encoding::utf8" Name string // file system path, e.g. "/usr/src/hare/stdlib/encoding/utf8" // or empty if the module was not found Path string Declarations map[string]*Declaration Exports map[string]*Declaration // The last I/O error encountered while loading the module. This hints at a // misconfigured hare installation or HAREPATH. // The module can still be used even if this error is set, but it is likely // missing declarations. LoadError *ModuleError // The last error caused by ambiguos tags. This may be resolved after adding // or removing files. // The module can still be used even if this error is set, but it is likely // missing declarations. TagError *ModuleConflictError // all files currently included in the module CurrentSources map[string]*Unit Cache *ModuleCache // contains filtered or unexported fields }
Module represents a hare module. Fields should be treated as read-only.
func (*Module) HasErrors ¶
HasErrors returns true if any errors were encountered while loading the module. The module can still be used even in the presence of errors, but it is likely missing declarations.
func (*Module) ParseErrors ¶
ParseError returns all parse errors encountered in this module. The module can still be used even in the presence of errors, but it is likely missing declarations.
func (*Module) Reload ¶
func (m *Module) Reload()
Reload discards all cached files and loads the module from the file system.
func (*Module) RemoveFile ¶
RemoveFile removes a file from the module. This should be called e.g. after a file was deleted.
func (*Module) StripInternals ¶
func (m *Module) StripInternals()
StripInternals removes all unexported declarations and function bodies from the module.
This reduces memory usage for modules that are only needed to resolve identifiers in other modules. Module internals will be restored if files are added or removed.
type ModuleCache ¶
type ModuleCache struct { // The current working directory. If set, it is examined first while // searching for modules. WorkingDir string // The current tags, without the '+'; e.g. ["linux", "x86_64"] Tags []string // The current HAREPATH. Harepath []string OnLoad func(*Module) // contains filtered or unexported fields }
A ModuleCache can store and lookup modules.
The ModuleCache contains information neccessary for finding modules and files, such as HAREPATH and tags; these must not be changed after modules are loaded.
func (*ModuleCache) Get ¶
func (c *ModuleCache) Get(name string) *Module
Get looks up a module from its fully-qualified name. Returns nil if no module was found.
func (*ModuleCache) GetUnit ¶
func (c *ModuleCache) GetUnit(name string) *Unit
GetUnit looks up a unit from a file name. If the file does not exist, it returns an empty unit.
func (*ModuleCache) GuessWorkingDir ¶
func (c *ModuleCache) GuessWorkingDir(file string)
GuessWorkingDir tries to find a likely working dir based on a path inside it.
func (*ModuleCache) ModuleForFile ¶
func (c *ModuleCache) ModuleForFile(name string) *Module
ModuleForFile takes a file path and returns the module that this file belongs to.
Returns nil if the file does not belong to any visible module (either because it is not on the HAREPATH or because it is shadowed by another module with higher priority).
func (*ModuleCache) SetDefaultHarepath ¶
func (c *ModuleCache) SetDefaultHarepath()
SetDefaultHarepath sets the harepath according to environment variables.
func (*ModuleCache) SetDefaultTags ¶
func (c *ModuleCache) SetDefaultTags()
SetDefaultTags initializes the tags with default values.
type ModuleConflictError ¶
func (*ModuleConflictError) Error ¶
func (e *ModuleConflictError) Error() string
type ModuleError ¶
func (*ModuleError) Error ¶
func (e *ModuleError) Error() string
func (*ModuleError) Unwrap ¶
func (e *ModuleError) Unwrap() error
type NullLiteral ¶
type NullLiteral struct{ Token }
type OffsetExpression ¶
type OffsetExpression struct { Token Token FieldAccessExpression }
func (*OffsetExpression) Range ¶
func (o *OffsetExpression) Range() Range
type RuneLiteral ¶
type SizeExpression ¶
func (*SizeExpression) Range ¶
func (s *SizeExpression) Range() Range
type SlicingExpression ¶
type SlicingExpression struct { Prefix Expression Start, End Expression }
func (*SlicingExpression) Range ¶
func (s *SlicingExpression) Range() Range
type StringLiteral ¶
type StructField ¶
type StructField struct { Offset Expression Name Token Type *Type Identifier *Identifier }
type StructFieldValue ¶
type StructFieldValue struct { Name Token Type *Type Value Expression }
type StructLiteral ¶
type StructLiteral struct { Type *Identifier Fields []StructFieldValue Fill bool }
func (*StructLiteral) Range ¶
func (s *StructLiteral) Range() Range
type StructType ¶
type StructType struct { Union bool Fields []StructField }
func (*StructType) Print ¶
func (s *StructType) Print(w io.StringWriter, lines bool, prefix string)
type SwitchCase ¶
type SwitchCase struct { Options []Expression Result []Expression }
type SwitchExpression ¶
type SwitchExpression struct { Token Value Expression Cases []SwitchCase }
type TaggedUnionType ¶
type TaggedUnionType struct {
Types []*Type
}
type Tokens ¶
type Tokens struct { Src []Token // contains filtered or unexported fields }
func (*Tokens) DocComment ¶
type Tuple ¶
type Tuple struct {
Start, End Token
Content []Expression
}
type Type ¶
type Type struct { Storage TypeStorage Const bool Error bool Alias *Identifier Data TypeData Range Range Size int Align int // contains filtered or unexported fields }
func (*Type) Print ¶
func (t *Type) Print(w io.StringWriter)
type TypeDeclaration ¶
type TypeDeclaration struct {
Type *Type
}
type TypeStorage ¶
type TypeStorage int
const ( StorageVoid TypeStorage = iota StorageNull StorageInt StorageI8 StorageI16 StorageI32 StorageI64 StorageUint StorageU8 StorageU16 StorageU32 StorageU64 StorageSize StorageUintptr StorageF32 StorageF64 StorageRune StorageChar StorageBool StorageStr StorageRConst StorageFConst StorageValist StorageIConst StoragePointer StorageNPointer StorageArray StorageSlice StorageStruct StorageTagged StorageTuple StorageEnum StorageFn StorageAlias )
type UnaryExpression ¶
type UnaryExpression struct { Value Expression Operator Token }
func (*UnaryExpression) Range ¶
func (u *UnaryExpression) Range() Range
type Unit ¶
type Unit struct { File *File // the module this unit is part of, may be nil Module *Module Imports []Import Declarations []*Declaration Errors []*Error }
Unit represents a hare compilation unit.
func (*Unit) ParseLines ¶
func (*Unit) ParseTokens ¶
type VoidLiteral ¶
type VoidLiteral struct{ Token }