token-lang 0.2.0

Token type definitions - the shared seam between lexer and parser.
Documentation

Installation

[dependencies]
token-lang = "0.2"

Usage

A language defines its own token kind; token-lang pairs it with a Span and lets generic code classify the stream.

use token_lang::{Span, Token, TokenKind};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Kind {
    Ident,
    Plus,
    Whitespace,
    Eof,
}

impl TokenKind for Kind {
    fn is_trivia(&self) -> bool {
        matches!(self, Kind::Whitespace)
    }
    fn is_eof(&self) -> bool {
        matches!(self, Kind::Eof)
    }
}

let tokens = [
    Token::new(Kind::Ident, Span::new(0, 1)),
    Token::new(Kind::Whitespace, Span::new(1, 2)),
    Token::new(Kind::Plus, Span::new(2, 3)),
    Token::new(Kind::Eof, Span::empty(3)),
];

// A parser skips trivia and stops at the end — without knowing the language.
let significant = tokens.iter().filter(|t| !t.is_trivia() && !t.is_eof()).count();
assert_eq!(significant, 2);

See docs/API.md for the full surface.

Status

Status: pre-1.0, in active development. The v0.2.0 release lands the core — the Token type and the TokenKind seam. The public API is being finalized across the 0.x series and frozen at 1.0.0; see the ROADMAP and docs/API.md.

Contributing

See dev/DIRECTIVES.md for engineering standards and the definition of done. Before a PR: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean.