rantlr-core 0.1.0

Rantlr core: .gr lexer, parser, linter, and in-process runtime
Documentation
//! # rantlr-core
//!
//! Architecture
//!
//! ```text
//!  .gr source
//!       │
//!       ▼
//!  ┌─────────┐    Token stream + Spans     ┌──────────┐
//!  │  Lexer  │ ──────────────────────────► │  Parser  │
//!  └─────────┘                             └────┬─────┘
//!                                               │
//!                                               ▼
//!                                         ┌──────────┐
//!                                         │   AST    │  Grammar / Rule / TokenDecl
//!                                         └────┬─────┘
//!                          ┌───────────────────┼───────────────────┐
//!                          ▼                   ▼                   ▼
//!                     ┌────────┐         ┌──────────┐        ┌──────────┐
//!                     │ Linter │         │ rantlr-gen│       │ runtime  │
//!                     └────────┘         └──────────┘        └──────────┘
//! ```
//!
//! Design choices:
//! - Hand-written lexer + recursive-descent parser for clear diagnostics / auto-fixes.
//! - Keywords over operators: `rule`, `token`, `match`, `repeat`, `optional`.
//! - `repeat` / `optional` are first-class AST nodes (not desugared away).
//! - Built-in types (`Number`, `QuotedString`, …) are recognized as dedicated tokens.

pub mod ast;
pub mod diagnostic;
pub mod error;
pub mod fix_hint;
pub mod lexer;
pub mod linter;
pub mod parser;
pub mod runtime;
pub mod span;
pub mod token;

pub use ast::{
    ExampleDecl, Expr, Grammar, GrammarItem, ImportDecl, RuleDecl, TokenBody, TokenDecl,
};
pub use diagnostic::{Diagnostic, DiagnosticKind, Severity};
pub use error::{ErrorKind, RantlrError};
pub use fix_hint::FixHint;
pub use lexer::{lex, Lexer, LexerError};
pub use linter::{lint, lint_all};
pub use parser::parse;
pub use runtime::{
    analyze_and_parse, diagnose, parse_input, AnalyzeResult, DiagnosticJson, ParseTree,
};
pub use span::{BytePos, Span};
pub use token::{BuiltinType, Keyword, Token, TokenKind};

/// Parse a `.gr` grammar and run the smart linter.
pub fn analyze(source: &str) -> Result<Grammar, RantlrError> {
    let grammar = parse(source)?;
    lint(source, &grammar)?;
    Ok(grammar)
}