Skip to main content

Crate rantlr_core

Crate rantlr_core 

Source
Expand description

§rantlr-core

Architecture

 .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.

Re-exports§

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

Modules§

ast
Grammar AST shapes produced by the parser and consumed by linter / codegen.
diagnostic
error
fix_hint
Structured auto-fix payloads for the linter / playground / LSP.
lexer
Hand-written lexer for the .gr grammar language.
linter
Grammar linter — catches constructs that break recursive-descent / PEG engines.
parser
Recursive-descent parser: Token stream → Grammar AST.
rule_graph
Rule call graph for playground visualization.
runtime
In-process interpreter: run a validated Grammar against test input. Powers the Tauri playground without requiring generated host-language code.
span
Source locations used by every stage (lexer → parser → linter → LSP).
token

Functions§

analyze
Parse a .gr grammar and run the smart linter.