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 unit variant (Point) or a tuple variant (Circle(f64)); fields is empty for a unit variant. Named-field variants (Circle { x: f64 }) are milestone 4 and never produce one of these: they are V0001.
Expr
An expression node: its kind plus the span it spans in the source.
FieldDecl
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).
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 (which makes every field public; field-level pub is milestone 2, spec 4.1).
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 an optional module segment (m::User, spec 2.10) and generic arguments (Vec<i32>, Result<User, string>, nested freely, spec 2.6); the parser only records them, and the resolver checks that the module, the name, and the argument count exist.
VariantPattern
A variant pattern (spec 2.3): name, or type_::name, or module::type_::name, each with an optional parenthesized list of sub-patterns. A single remaining segment always fills type_, never module: unlike ExprKind::Path, a pattern never calls anything, so there is no bare-module case to weigh it against. A pattern path longer than three segments is V0001.

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): a half-open integer range (a..b), parsed only here since ranges exist nowhere else in Varyk, or an expression iterated element by element as a Vec. ..= never produces a ForHead::Range: it is V0001, milestone 4.
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.
Pattern
A match pattern, one level deep (spec 2.3). Not in milestone 2, each V0001: nested patterns, literal patterns, guards (pattern if cond), alternatives (a | b), rest patterns (..), range 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).
SubPattern
A sub-pattern inside a variant pattern’s parentheses (spec 2.3): a name or _. Nothing else is one level deep.
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.

Constants§

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.