Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Appendix A: Keywords to Sway book #4992

Merged
merged 20 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@
- [forc explore](./forc/plugins/forc_explore.md)
- [forc fmt](./forc/plugins/forc_fmt.md)
- [forc lsp](./forc/plugins/forc_lsp.md)
- [Appendix](./appendix/index.md)
- [Keywords](./appendix/keywords.md)
5 changes: 5 additions & 0 deletions docs/book/src/appendix/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Appendix

The following sections contain reference material you may find useful in your Sway journey.

- [Keywords](./keywords.md)
88 changes: 88 additions & 0 deletions docs/book/src/appendix/keywords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# [Appendix A: Keywords](#appendix-a-keywords)
sarahschwartz marked this conversation as resolved.
Show resolved Hide resolved

The following list contains keywords that are reserved for current or
future use by the Sway language. As such, they cannot be used as
identifiers. Identifiers are names of functions, variables,
parameters, modules, constants, attributes, types or
traits, ect.

## [Keywords Currently in Use](#keywords-currently-in-use)

The following is a list of keywords currently in use, with their
functionality described.

- `as` - rename items in `use` statements, eg `use type::a as alias_name`
- [`abi`](https://fuellabs.github.io/sway/master/book/sway-program-types/smart_contracts.html#the-abi-declaration) - defines a smart contract ABI in a syntactcally similar way to traits
- [`break`](https://fuellabs.github.io/sway/v0.44.0/book/basics/control_flow.html#break-and-continue) - exit a loop immediately
- [`const`](https://fuellabs.github.io/sway/v0.44.0/book/basics/constants.html) - define constant items
- [`continue`](https://fuellabs.github.io/sway/v0.44.0/book/basics/control_flow.html#break-and-continue) - continue to the next loop iteration
- `else` - used in conjunction with `if` conditions for control flow constructs
- [`enum`](https://fuellabs.github.io/sway/v0.44.0/book/basics/structs_tuples_and_enums.html#enums) - define an enumeration
- `false` - Boolean false literal
- [`fn`](https://fuellabs.github.io/sway/master/book/basics/functions.html)- define a function or the function pointer type
- [`if`](https://fuellabs.github.io/sway/v0.44.0/book/basics/control_flow.html#if-expressions) - branch based on the result of a conditional expression
- `impl` - implement inherent or trait functionality
Braqzen marked this conversation as resolved.
Show resolved Hide resolved
- `let` - bind a variable
- [`match`](https://fuellabs.github.io/sway/v0.44.0/book/basics/control_flow.html#match-expressions) - exhaustfully match a value to patterns
- `mod` - define a module
- `mut` - denote mutability in references, or pattern bindings
- `pub` - denote public visibility of Sway data structures, traits, or modules
- `ref` - bind by reference
- `return` - return early from a function
- `Self` - a type alias for the type we are defining or implementing
- `self` - method subject
- [`struct`](https://fuellabs.github.io/sway/v0.44.0/book/basics/structs_tuples_and_enums.html#structs) - define a structure
- [`trait`](https://fuellabs.github.io/sway/master/book/advanced/traits.html#declaring-a-trait) - define a trait
- `true` - Boolean true literal
- [`type`](https://fuellabs.github.io/sway/master/book/advanced/advanced_types.html?search=#creating-type-synonyms-with-type-aliases) - define a type alias or associated type
- `use` - bring symbols into scope
- `where` - specifies traits for generic types
- [`while`](https://fuellabs.github.io/sway/v0.44.0/book/basics/control_flow.html#while) - loop conditionally based on the result of an expression

## [Keywords Reserved for Possible Future Use](#keywords-reserved-for-possible-future-use)
Braqzen marked this conversation as resolved.
Show resolved Hide resolved

- `abstract`
- `async`
- `await`
- `become`
- `box`
- `do`
- `dyn`
- `extern`
- `for`
- `in`
- `loop`
- `macro`
- `move`
- `override`
- `priv`
- `static`
- `super`
- `try`
- `typeof`
- `unsafe`
- `unsized`
- `virtual`
- `yield`

## [Special Keywords](#special-keywords)

### [Program Keywords](#program-keywords)

Keywords associated with defining the type of Sway program to compile

- [`contract`](https://fuellabs.github.io/sway/master/book/sway-program-types/smart_contracts.html) - analogous to a deployed API with some database state
- [`library`](https://fuellabs.github.io/sway/master/book/sway-program-types/libraries.html) - Sway code that defines new common behavior
- [`predicate`](https://fuellabs.github.io/sway/master/book/sway-program-types/predicates.html) - programs that return a Boolean value and which represent ownership of some resource upon execution to true
- [`script`](https://fuellabs.github.io/sway/master/book/sway-program-types/scripts.html) - a runnable bytecode on the chain, which executes once to preform a task

### [Attribute Keywords](#attribute-keywords)

Keywords associated with defining the funcitonallity of attributes

- [`allow`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#allow) - overrides checks that would otherwise result in errors or warnings
- [`doc`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#doc) - specifies documentation
- [`inline`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#inline) - suggests that a copy of the attributed function should be placed in the caller, rather than generating code to call the function where it is defined
- [`payable`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#payable) - implies method is payable for compile time
- [`storage`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#storage) - declaration that contains a list of stored variables
- [`test`](https://fuellabs.github.io/sway/master/book/reference/attributes.html#test) - marks a function to be executed as a test
Loading