Skip to main content

Crate varyk_syntax

Crate varyk_syntax 

Source
Expand description

varyk-syntax: spans, tokens, lexer, parser, and AST for Varyk.

This crate carries no semantic analysis, so a formatter or a language server can depend on it without pulling in the type checker or borrow analysis.

Structs§

Block
{ stmts...; tail }. The tail expression, if present, is the block’s value.
EnumDecl
enum Name { variants... } (spec 2.2), optionally pub. An enum has one or more variants; an empty { } is V0002, since the parser found a complete-looking declaration missing the one thing it must have.
EnumVariant
A variant of an enum: a unit variant (Point), a tuple variant (Circle(f64)), or a variant with named fields (Click { x: i32 }, M4 spec 2.5).
Expr
An expression node: its kind plus the span it spans in the source.
FieldDecl
A struct field: name: T, optionally pub (spec 3.4). Visibility follows the same rule as everything else (section 3.2): a private field is visible in the declaring module and its descendants, which includes the struct’s own methods.
FileId
Identifies a source file within a compilation. A small newtype over u32 so file ids stay cheap to copy and compare.
FixIt
A suggested edit attached to a SyntaxError: replace the text at span with replacement.
Function
fn name(params) -> ReturnType { body }, optionally pub. Inside an impl block the parameter list may start with a self receiver (self_mode), which is never a Param (spec 2.5).
Ident
A name plus the span it was written at.
ImplBlock
impl Name { fns... } (spec 2.5): a block of functions and methods for a struct or enum declared in the same file. Whether name actually names a struct or enum is the compiler’s resolve module’s job.
MatchArm
One arm of a match (spec 2.3): pattern => body, with an optional trailing comma the parser consumes but does not record.
ModDecl
mod name; (spec 4.5): declares a submodule resolved to name.vr or name.rs in the same directory. Resolving and merging the submodule’s items is the compiler’s resolve module’s job; this node only records the declaration.
Param
One parameter: name: T is a shared borrow, mut name: T is a mutable borrow (spec 4.2).
Path
A ::-separated path (spec 3.1, 3.3): an optional keyword prefix (crate, self, super) followed by name segments. What the segments (and any name that follows them, for a type or expression path) resolve to – a chain of modules, a type, a function, a variant – is decided by where the path appears and, ultimately, the compiler’s resolver, never the parser.
Program
A whole parsed source file: the top-level items it declares, in order.
SourceFile
A single source file: its id, path, full text, and a line index built once so byte offsets convert to line/column cheaply.
Span
A byte range [start, end) within a single source file.
StructDecl
struct Name { fields... }, optionally pub (spec 4.1). Whether a field is visible follows the same rule as everything else (spec 3.2): see FieldDecl::is_pub.
SyntaxError
A lexical or syntactic error, carrying a span, a message, and one of the diagnostic codes defined above.
Token
A single lexical token: its kind plus the span it came from.
TypeExpr
A named type: string, i32, User, and so on are all just names, resolved later by the compiler’s resolver. A type may carry a module path (m::User, shop::cart::Cart, spec 2.10, 3.1) and generic arguments (Vec<i32>, Result<User, string>, nested freely, spec 2.6); the parser only records them, and the resolver checks that the path, the name, and the argument count exist.
UseDecl
use path; or use path as name; (spec 3.3): introduces a local alias for whatever path names – a module, a struct, an enum, or a function – resolved and checked by the compiler’s resolver, never the parser.
VariantField
A named field of a variant: name: T. It has no visibility of its own: a variant’s fields are as visible as the enum, and Rust rejects pub on them.

Enums§

BinaryOp
Binary operators (spec 4.1), in Rust’s precedence order from loosest to tightest: ||, &&, the comparisons (non-associative), + -, then * / %.
ExprKind
ForHead
The head of a for loop (spec 2.4): an integer range, half-open (a..b) or inclusive (a..=b, M4 spec 2.11), parsed only here since an expression range exists nowhere else in Varyk, or an expression iterated element by element as a Vec.
Item
A top-level declaration (spec 4.1, 2.2, 2.5): a function, a struct, an enum, an impl block, or a module declaration. mod name; only declares a submodule; resolving it to the submodule’s own file and items is the compiler’s resolve module’s job.
Literal
The value of a literal pattern or of a range pattern’s end, with the raw text of a number as lexed.
PathStart
Where a path starts (spec 3.1, 3.3): one of the three keyword prefixes, or nothing (a plain module name declared in this file, or no module segment at all). The parser records whichever prefix is written; resolving Crate and Super to an actual module, and rejecting Super in the crate root (V0111), is the compiler’s resolver’s job.
Pattern
A pattern (spec 2.3, M4 spec 2.5), in a match arm, an if let, or a while let, nested to any depth. Not in Varyk, each V0001 from the parser: guards (pattern if cond), alternatives (a | b), rest patterns (..), and @ bindings.
SelfMode
Whether a function is a plain function, or a method with a self receiver (spec 2.5): self is a shared borrow, mut self a mutable borrow. There is no owned self in milestone 2.
Stmt
A statement: let, assignment, return, while, break, continue, or an expression used for its side effects (or as a block’s tail, distinguished by has_semi on Stmt::Expr so the type checker can tell a mid-block statement from a block’s value).
TokenKind
The kind of a lexical token. Keywords that are part of the Varyk surface (spec 4.1) each get their own variant; every other Rust keyword and reserved word, including the 2024-edition ones, lexes as TokenKind::ReservedKeyword carrying its text, so the parser can report it by name.
UnaryOp
Unary operators (spec 4.1). Unary binds tighter than any binary operator.
VariantFields
What a variant holds: nothing, values by position (Circle(f64); an empty Circle() is a Tuple of no types), or named fields.

Constants§

KEYWORDS
Varyk’s own keywords (spec 4.1), with the token each lexes to; true and false are the two bool literals. keyword_kind looks words up here, so this list and the lexer cannot differ.
RESERVED_KEYWORDS
Every other Rust keyword and reserved word, including the 2024-edition ones.
V0001
Unsupported construct, naming it.
V0002
Unexpected token or malformed syntax.
V0003
Bad string escape, or an unterminated string.
V0010
&x or &mut x written at a call site.
V0011
&T or &mut T written in a parameter type.
V0012
Lifetime syntax, such as <'a> or &'a T.

Functions§

lex
Lexes file into tokens and any syntax errors found along the way. Lexing never stops at the first error: an unknown character or a bad string is recorded and scanning continues after it.
parse
Parses a whole token stream for a single file into a Program plus every syntax error found. On the first V0002 (or an unrecoverable V0001, such as a reserved keyword where an item is expected), parsing stops and the items parsed so far are returned alongside the errors.
parse_source
Lexes file then parses it, merging the lexer’s errors first. If the lexer reported anything, parsing is skipped: a file with lexical errors has no reliable token stream to parse from, so its Program is empty and only the lexer’s errors are returned. The compiler’s resolve module calls this for every file it loads.