Sway Language Grammar v0.66.5
Sway is a domain-specific programming language for implementing smart contracts on blockchain platforms, most notably for the Fuel Virtual Machine (Fuel VM).
Parser Grammar
module
On top level, Sway allows module kind and definitions of submodule, storage, contracts, traits, libraries, structs, enums and constants. (AST: Module)
submodule
The mod
keyword registers a submodule, making its items (such as functions and structs) accessible from the parent library. If used at the top level it will refer to a file in the src folder and in other cases in a folder named after the library in which it is defined. (AST: Submodule)
use
Provides several utility types and methods we can use in our contract. (AST: ItemUse)
use-tree
Path of a types or methods to be imported. (AST: UseTree)
struct
Definition of a struct. Can occur at top-level within a source unit or within a contract, library or interface. (AST: ItemStruct)
type-field
Definition of TypeField. (AST: TypeField)
type-name
Definition of TypeName. (AST: Ty)
enum
Definition of an enum. Can occur at top-level within a source unit or within a contract, library or interface. (AST: ItemEnum)
traits
Definition of traits. Can be used for abi and trait.(AST: Traits)
trait-item
Define an item of an trait. (AST: ItemTraitItem).
abi
ABI stands for Application Binary Interface.(AST: ItemAbi, doc: The ABI Declaration).
const
Define constant items. (AST: ItemConst)
configurable
Configurable constants are special constants that behave like regular constants in the sense that they cannot change during program execution, but they can be configured after the Sway program has been built. (AST: ItemConfigurable, doc: Configurable Constants)
type-alias
Definition of type-alias. To declare a type alias to give an existing type another name. (AST: ItemTypeAlias)
fn
Functions in Sway are declared with the fn keyword. (AST: ItemFn, doc: Functions)
fn-signature
fn-signature declares signature for function. (AST: FnSignature, doc: Functions)
generic-params
Generic types are a way to refer to types in general, meaning without specifying a single type. (AST: GenericParams, doc: Generic Types).
where-clause
Where clause can be used to specify the required traits for the generic argument. (AST: WhereClause, doc: Trait Constraints).
code-block-contents
A CodeBlockContents represents the body of a code block, which contains a sequence of statements and expressions. (AST: CodeBlockContents, doc: Functions).
fn-arg
A fn-arg represents function arguments. (AST: FnArg, doc: Functions).
pattern
A pattern is a construct used to match and destructure data. (AST: Pattern, doc: match expressions).
trait
A trait opts a type into a certain type of behavior or functionality that can be shared among types. This allows for easy reuse of code and generic programming. (AST: ItemTrait, doc: Declaring a Trait).
impl
Implement inherent or trait functionality. (AST: ItemImpl, doc: Implementing a Trait)
storage
In smart contract development, persistent storage (storage) is used to store values that persist after the contract exits, unlike regular memory values that disappear. (AST: ItemStorage, doc: Declaring storage)
storage-entry
Define storage entry. (AST: StorageEntry, doc: Declaring storage)
expr
Define types of expressions. (AST: Expr, doc: If Expressions)