Documentation ¶
Index ¶
- Constants
- Variables
- func IsHardKeyword(identifier string) bool
- func Parse[T any](memoryGauge common.MemoryGauge, input []byte, parse func(*parser) (T, error), ...) (result T, errors []error)
- func ParseArgumentList(memoryGauge common.MemoryGauge, input []byte, config Config) (arguments ast.Arguments, errs []error)
- func ParseDeclarations(memoryGauge common.MemoryGauge, input []byte, config Config) (declarations []ast.Declaration, errs []error)
- func ParseDocstringPragmaArguments(docString string) []string
- func ParseDocstringPragmaSigners(docString string) []string
- func ParseExpression(memoryGauge common.MemoryGauge, input []byte, config Config) (expression ast.Expression, errs []error)
- func ParseProgram(memoryGauge common.MemoryGauge, code []byte, config Config) (program *ast.Program, err error)
- func ParseProgramFromFile(memoryGauge common.MemoryGauge, filename string, config Config) (program *ast.Program, code []byte, err error)
- func ParseProgramFromTokenStream(memoryGauge common.MemoryGauge, input lexer.TokenStream, config Config) (program *ast.Program, err error)
- func ParseStatements(memoryGauge common.MemoryGauge, input []byte, config Config) (statements []ast.Statement, errs []error)
- func ParseStatementsFromTokenStream(memoryGauge common.MemoryGauge, tokens lexer.TokenStream, config Config) (statements []ast.Statement, errs []error)
- func ParseTokenStream[T any](memoryGauge common.MemoryGauge, tokens lexer.TokenStream, ...) (result T, errs []error)
- func ParseType(memoryGauge common.MemoryGauge, input []byte, config Config) (ty ast.Type, errs []error)
- type Config
- type CustomDestructorError
- type Error
- type ExpressionDepthLimitReachedError
- type InvalidIntegerLiteralError
- type InvalidNumberLiteralKind
- type JuxtaposedUnaryOperatorsError
- type MissingCommaInParameterListError
- type ParseError
- type RestrictedTypeError
- type SyntaxError
- type SyntaxErrorWithSuggestedReplacement
- type TypeDepthLimitReachedError
Constants ¶
const ( KeywordIf = "if" KeywordElse = "else" KeywordWhile = "while" KeywordBreak = "break" KeywordContinue = "continue" KeywordReturn = "return" KeywordTrue = "true" KeywordFalse = "false" KeywordNil = "nil" KeywordLet = "let" KeywordVar = "var" KeywordFun = "fun" KeywordAs = "as" KeywordCreate = "create" KeywordDestroy = "destroy" KeywordFor = "for" KeywordIn = "in" KeywordEmit = "emit" KeywordAuth = "auth" KeywordAccess = "access" KeywordAll = "all" KeywordSelf = "self" KeywordInit = "init" KeywordContract = "contract" KeywordAccount = "account" KeywordImport = "import" KeywordFrom = "from" KeywordPre = "pre" KeywordPost = "post" KeywordEvent = "event" KeywordStruct = "struct" KeywordResource = "resource" KeywordInterface = "interface" KeywordEntitlement = "entitlement" KeywordMapping = "mapping" KeywordTransaction = "transaction" KeywordPrepare = "prepare" KeywordExecute = "execute" KeywordCase = "case" KeywordSwitch = "switch" KeywordDefault = "default" KeywordEnum = "enum" KeywordView = "view" KeywordAttachment = "attachment" KeywordAttach = "attach" KeywordRemove = "remove" KeywordTo = "to" KeywordRequire = "require" KeywordStatic = "static" KeywordNative = "native" KeywordPub = "pub" KeywordPriv = "priv" KeywordInclude = "include" KeywordTry = "try" KeywordCatch = "catch" KeywordFinally = "finally" KeywordGoto = "goto" KeywordConst = "const" KeywordExport = "export" KeywordThrow = "throw" KeywordThrows = "throws" KeywordRequires = "requires" KeywordWhere = "where" KeywordFinal = "final" KeywordInternal = "internal" KeywordTypealias = "typealias" KeywordType = "type" KeywordRepeat = "repeat" KeywordGuard = "guard" KeywordIs = "is" )
NOTE: ensure to update allKeywords when adding a new keyword
Variables ¶
var HardKeywords = filter( allKeywords, func(keyword string) bool { _, ok := softKeywordsTable.Lookup(keyword) return !ok }, )
HardKeywords are restricted from being used as identifiers in certain places. i.e: places where ambiguity can exist, such as composite declaration names, function names, etc. However, they are not restricted to be used as fields names, and many other places.
var SoftKeywords = []string{ KeywordFrom, KeywordAccount, KeywordAll, KeywordView, KeywordAttach, KeywordRemove, KeywordTo, KeywordType, }
SoftKeywords are keywords that can be used as identifiers anywhere, without any restriction or ambiguity.
Functions ¶
func IsHardKeyword ¶ added in v1.0.0
func Parse ¶ added in v0.25.0
func Parse[T any]( memoryGauge common.MemoryGauge, input []byte, parse func(*parser) (T, error), config Config, ) (result T, errors []error)
Parse creates a lexer to scan the given input string, and uses the given `parse` function to parse tokens into a result.
It can be composed with different parse functions to parse the input string into different results. See "ParseExpression", "ParseStatements" as examples.
func ParseArgumentList ¶ added in v0.25.0
func ParseDeclarations ¶ added in v0.25.0
func ParseDeclarations( memoryGauge common.MemoryGauge, input []byte, config Config, ) ( declarations []ast.Declaration, errs []error, )
func ParseDocstringPragmaArguments ¶ added in v0.25.0
ParseDocstringPragmaArguments parses the docstring and returns the values of all pragma arguments declarations.
A pragma arguments declaration has the form `pragma arguments <argument-list>`, where <argument-list> is a Cadence argument list.
The validity of the argument list is NOT checked by this function.
func ParseDocstringPragmaSigners ¶ added in v0.25.0
ParseDocstringPragmaSigners parses the docstring and returns the values of all pragma signers declarations.
A pragma signers declaration has the form `pragma signers <signers-list>`, where <signers-list> is a list of strings.
The validity of the argument list is NOT checked by this function.
func ParseExpression ¶
func ParseExpression( memoryGauge common.MemoryGauge, input []byte, config Config, ) ( expression ast.Expression, errs []error, )
func ParseProgram ¶
func ParseProgramFromFile ¶
func ParseProgramFromTokenStream ¶ added in v0.25.0
func ParseProgramFromTokenStream( memoryGauge common.MemoryGauge, input lexer.TokenStream, config Config, ) ( program *ast.Program, err error, )
func ParseStatements ¶ added in v0.25.0
func ParseStatementsFromTokenStream ¶ added in v0.39.0
func ParseStatementsFromTokenStream( memoryGauge common.MemoryGauge, tokens lexer.TokenStream, config Config, ) ( statements []ast.Statement, errs []error, )
func ParseTokenStream ¶ added in v0.25.0
func ParseTokenStream[T any]( memoryGauge common.MemoryGauge, tokens lexer.TokenStream, parse func(*parser) (T, error), config Config, ) ( result T, errs []error, )
Types ¶
type Config ¶ added in v0.30.0
type Config struct { // StaticModifierEnabled determines if the static modifier is enabled StaticModifierEnabled bool // NativeModifierEnabled determines if the native modifier is enabled NativeModifierEnabled bool // Deprecated: IgnoreLeadingIdentifierEnabled determines // if leading identifiers are ignored. // // Pre-Stable Cadence, identifiers preceding keywords were (incorrectly) ignored, // instead of being reported as invalid, e.g. `foo let bar: Int` was valid. // The new default behaviour is to report an error, e.g. for `foo` in the example above. // // This option exists so the old behaviour can be enabled to allow developers to update their code. IgnoreLeadingIdentifierEnabled bool // TypeParametersEnabled determines if type parameters are enabled TypeParametersEnabled bool }
type CustomDestructorError ¶ added in v1.0.0
func (*CustomDestructorError) EndPosition ¶ added in v1.0.0
func (e *CustomDestructorError) EndPosition(_ common.MemoryGauge) ast.Position
func (*CustomDestructorError) Error ¶ added in v1.0.0
func (e *CustomDestructorError) Error() string
func (*CustomDestructorError) IsUserError ¶ added in v1.0.0
func (*CustomDestructorError) IsUserError()
func (*CustomDestructorError) SecondaryError ¶ added in v1.0.0
func (e *CustomDestructorError) SecondaryError() string
func (*CustomDestructorError) StartPosition ¶ added in v1.0.0
func (e *CustomDestructorError) StartPosition() ast.Position
type Error ¶
func (Error) ChildErrors ¶
type ExpressionDepthLimitReachedError ¶ added in v0.25.0
ExpressionDepthLimitReachedError is reported when the expression depth limit was reached
func (ExpressionDepthLimitReachedError) EndPosition ¶ added in v0.25.0
func (e ExpressionDepthLimitReachedError) EndPosition(_ common.MemoryGauge) ast.Position
func (ExpressionDepthLimitReachedError) Error ¶ added in v0.25.0
func (e ExpressionDepthLimitReachedError) Error() string
func (ExpressionDepthLimitReachedError) IsUserError ¶ added in v0.25.0
func (ExpressionDepthLimitReachedError) IsUserError()
func (ExpressionDepthLimitReachedError) StartPosition ¶ added in v0.25.0
func (e ExpressionDepthLimitReachedError) StartPosition() ast.Position
type InvalidIntegerLiteralError ¶
type InvalidIntegerLiteralError struct { Literal string IntegerLiteralKind common.IntegerLiteralKind InvalidIntegerLiteralKind InvalidNumberLiteralKind ast.Range }
func (*InvalidIntegerLiteralError) Error ¶
func (e *InvalidIntegerLiteralError) Error() string
func (*InvalidIntegerLiteralError) IsUserError ¶ added in v0.25.0
func (*InvalidIntegerLiteralError) IsUserError()
func (*InvalidIntegerLiteralError) SecondaryError ¶
func (e *InvalidIntegerLiteralError) SecondaryError() string
type InvalidNumberLiteralKind ¶
type InvalidNumberLiteralKind uint
const ( InvalidNumberLiteralKindUnknown InvalidNumberLiteralKind = iota InvalidNumberLiteralKindLeadingUnderscore InvalidNumberLiteralKindTrailingUnderscore InvalidNumberLiteralKindUnknownPrefix InvalidNumberLiteralKindMissingDigits )
func (InvalidNumberLiteralKind) Description ¶
func (k InvalidNumberLiteralKind) Description() string
func (InvalidNumberLiteralKind) String ¶
func (i InvalidNumberLiteralKind) String() string
type JuxtaposedUnaryOperatorsError ¶
func (*JuxtaposedUnaryOperatorsError) EndPosition ¶
func (e *JuxtaposedUnaryOperatorsError) EndPosition(_ common.MemoryGauge) ast.Position
func (*JuxtaposedUnaryOperatorsError) Error ¶
func (e *JuxtaposedUnaryOperatorsError) Error() string
func (*JuxtaposedUnaryOperatorsError) IsUserError ¶ added in v0.25.0
func (*JuxtaposedUnaryOperatorsError) IsUserError()
func (*JuxtaposedUnaryOperatorsError) StartPosition ¶
func (e *JuxtaposedUnaryOperatorsError) StartPosition() ast.Position
type MissingCommaInParameterListError ¶ added in v0.25.0
func (*MissingCommaInParameterListError) EndPosition ¶ added in v0.25.0
func (e *MissingCommaInParameterListError) EndPosition(_ common.MemoryGauge) ast.Position
func (*MissingCommaInParameterListError) Error ¶ added in v0.25.0
func (e *MissingCommaInParameterListError) Error() string
func (*MissingCommaInParameterListError) IsUserError ¶ added in v0.25.0
func (*MissingCommaInParameterListError) IsUserError()
func (*MissingCommaInParameterListError) StartPosition ¶ added in v0.25.0
func (e *MissingCommaInParameterListError) StartPosition() ast.Position
type ParseError ¶
type ParseError interface { errors.UserError ast.HasPosition // contains filtered or unexported methods }
type RestrictedTypeError ¶ added in v1.0.0
func (*RestrictedTypeError) Error ¶ added in v1.0.0
func (e *RestrictedTypeError) Error() string
func (*RestrictedTypeError) IsUserError ¶ added in v1.0.0
func (*RestrictedTypeError) IsUserError()
type SyntaxError ¶
func NewSyntaxError ¶ added in v0.25.0
func NewSyntaxError(pos ast.Position, message string, params ...any) *SyntaxError
func (*SyntaxError) EndPosition ¶
func (e *SyntaxError) EndPosition(_ common.MemoryGauge) ast.Position
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
func (*SyntaxError) IsUserError ¶ added in v0.25.0
func (*SyntaxError) IsUserError()
func (*SyntaxError) StartPosition ¶
func (e *SyntaxError) StartPosition() ast.Position
type SyntaxErrorWithSuggestedReplacement ¶ added in v1.0.0
func NewSyntaxErrorWithSuggestedReplacement ¶ added in v1.0.0
func NewSyntaxErrorWithSuggestedReplacement(r ast.Range, message string, suggestedFix string) *SyntaxErrorWithSuggestedReplacement
func (*SyntaxErrorWithSuggestedReplacement) Error ¶ added in v1.0.0
func (e *SyntaxErrorWithSuggestedReplacement) Error() string
func (*SyntaxErrorWithSuggestedReplacement) IsUserError ¶ added in v1.0.0
func (*SyntaxErrorWithSuggestedReplacement) IsUserError()
func (*SyntaxErrorWithSuggestedReplacement) SuggestFixes ¶ added in v1.0.0
func (e *SyntaxErrorWithSuggestedReplacement) SuggestFixes(_ string) []errors.SuggestedFix[ast.TextEdit]
type TypeDepthLimitReachedError ¶ added in v0.25.0
func (TypeDepthLimitReachedError) EndPosition ¶ added in v0.25.0
func (e TypeDepthLimitReachedError) EndPosition(_ common.MemoryGauge) ast.Position
func (TypeDepthLimitReachedError) Error ¶ added in v0.25.0
func (e TypeDepthLimitReachedError) Error() string
func (TypeDepthLimitReachedError) IsUserError ¶ added in v0.25.0
func (TypeDepthLimitReachedError) IsUserError()
func (TypeDepthLimitReachedError) StartPosition ¶ added in v0.25.0
func (e TypeDepthLimitReachedError) StartPosition() ast.Position