Skip to main content

Crate elenchus_parser

Crate elenchus_parser 

Source
Expand description

elenchus-parser — parses the English-like elenchus DSL into an AST.

Style mirrors vsm-parser: zero-copy over &str, nom + nom_locate for line/column tracking, and human-friendly syntax diagnostics. Syntax is line/keyword-oriented (not S-expressions) so small models cannot trip on parentheses or indentation.

Grammar (see docs/SPEC.md, “Grammar (EBNF)”):

  • statements are newline-terminated; indentation is cosmetic, not significant;
  • keywords are ALWAYS CAPS (ASCII); identifiers are content (case-sensitive, verbatim, any-script letters — e.g. условие, 名前);
  • block boundaries (PREMISE/RULE bodies) are found by keywords, never by indent.

On error, parse returns Diagnostics: every syntax error from one pass, each rendered as a caret block with the keyword’s correct syntax (see diag and [syntax]).

The crate is split into focused modules — ast (the tree), keywords (the single keyword table: spellings, roles, syntax cards), diag (error rendering), and grammar (the nom parser + recovering driver) — re-exported here as a flat public surface.

§Example

use elenchus_parser::{Statement, parse};

// One statement per line; the result is a flat list of `Statement`s.
let program = parse("FACT socrates is human\nCHECK socrates\n").unwrap();
assert_eq!(program.statements.len(), 2);
assert!(matches!(program.statements[0], Statement::Fact(_)));

Re-exports§

pub use ast::Atom;
pub use ast::Body;
pub use ast::Conn;
pub use ast::ListOp;
pub use ast::Literal;
pub use ast::Located;
pub use ast::Program;
pub use ast::Span;
pub use ast::Statement;
pub use diag::Diagnostic;
pub use diag::Diagnostics;
pub use keywords::Card;
pub use keywords::KEYWORDS;
pub use keywords::Keyword;
pub use keywords::card_for;
pub use keywords::is_reserved;
pub use keywords::kw;

Modules§

ast
The abstract syntax tree: the typed shape a .vrf source parses into.
diag
Human-facing syntax diagnostics: the owned, renderable result of a failed parse.
keywords
The single source of truth for the language’s keywords.

Functions§

parse
Parse a full .vrf source into a Program, collecting every syntax error.