Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Comments

Comments, like much of Spade’s syntax, are heavily inspired by that of Rust. It has a couple types of comments and they are properly integrated into the lexer to enable features such as nested multiline comments.

Types of Comment

Spade supports 4 types of comments:

  • Line comments (//)
  • Block comments (Starts with /*, ends with */)
  • Outer documentation comments (//!)
  • Inner documentation comments (///)

Note: One area where Spade deviates from Rust in this regard is in the lack of inclusion of block documentation comments.

Non-Documentation Comments

Non-documentation (standard line and block comments) are treated by spade as whitespace and have no semantic meaning.

Block comments support nested usage, meaning each /* must have a matching */, even if it is within another comment:

/*
* /* Inner comment */
*/

Documentation Comments

Documentation comments are treated as a form of attribute. They are used, as the name implies, to document items and modules. Content within them is treated as markdown.

//! This is top-level documentation applying to the module represented by this file


/// This is documentation on this type
struct MyType {
x: uint<8>,

/// Documentation on a specific field
y: bool,
}

impl MyType {
/// And this is documentation on a specific method
fn return_self(self) -> MyType {
self
}
}