Skip to main content

Crate dive_syntax

Crate dive_syntax 

Source
Expand description

dive-syntax: the TLA+ lexer and parser.

parse_module turns source text into a lossless concrete syntax tree (CST): the tree’s text is byte-identical to the input, including whitespace, comments (and the PlusCal algorithms inside them), the text before the module header and the text after the closing ====.

The parser accepts exactly what the pinned SANY parser accepts. That includes SANY’s syntactic restrictions, such as operator precedence conflicts (a * -b is rejected) and junction-list alignment. The one exception is pathologically deep nesting, which dive refuses with DIVE-S0040 instead of risking a stack overflow. It never panics, and it always produces a tree; after an error it recovers at the next module-level unit so editors keep working.

Semantic analysis (name resolution, arity, levels) is not done here; that is dive-sema.

§Example

use dive_syntax::{parse_module, ast::AstNode};

let src = "---- MODULE Counter ----\nVARIABLE x\nInit == x = 0\nNext == x' = x + 1\n====\n";
let parse = parse_module(src);
assert!(parse.is_ok());
assert_eq!(parse.syntax().to_string(), src); // lossless

let module = parse.module().expect("a module");
assert_eq!(module.name().as_deref(), Some("Counter"));
let defs: Vec<String> = module
    .operator_definitions()
    .filter_map(|d| d.name())
    .collect();
assert_eq!(defs, ["Init", "Next"]);

Re-exports§

pub use diagnostics::Code;
pub use diagnostics::Diagnostic;
pub use diagnostics::Severity;

Modules§

ast
Typed views over the concrete syntax tree.
diagnostics
Syntax diagnostics and their stable codes.
ops
Operator precedence and associativity.
tokens
Raw tokens of SANY’s SPEC lexical state.

Structs§

GreenNode
Internal node in the immutable tree. It has other nodes and tokens as children.
Parse
The result of parsing one source file.
TextRange
A range in text, represented as a pair of TextSize.
TextSize
A measure of text length. Also, equivalently, an index into text.

Enums§

SyntaxKind
The kind of a token or node in the concrete syntax tree.
TlaLanguage
The rowan language tag for TLA+.

Functions§

parse_module
Parses a TLA+ source file containing one top-level module.

Type Aliases§

SyntaxElement
A node or a token.
SyntaxNode
A node in the red (cursor) syntax tree.
SyntaxToken
A token in the red (cursor) syntax tree.