Expand description
Parser and AST for the QCode text format.
QCode has a textual surface syntax, which is how much of the toolchain’s
test suite is written and what the qcode! macro accepts. This crate turns
that text into a syntax tree and nothing more: it performs no name
resolution, no typing, and no lowering, so it depends on neither the IR nor
the rest of the toolchain.
Most users want qcode instead, and its qcode::lower::lower_str,
which parses and lowers into a live module. Reach for this crate when a
tool needs the syntax itself — a formatter, a linter, an editor, or
anything reporting source spans back to a human. It is also what
wazabin_qcode_macro uses to validate QCode literals at compile time.
§Example
use wazabin_qcode_parser::{ast::ProgramKind, qcode_from_str};
let program = qcode_from_str("%sum = i64 0x2 + 0x3;").expect("valid QCode");
match program.kind {
ProgramKind::Statements(statements) => assert_eq!(statements.len(), 1),
ProgramKind::Functions { .. } => panic!("this source declares no functions"),
}A syntax error carries its location rather than just a message:
use wazabin_qcode_parser::qcode_from_str;
assert!(qcode_from_str("%sum = i64 0x2 +;").is_err());Modules§
Structs§
Functions§
- parse_
program - qcode_
from_ str - Parse QCode source into a
ast::Program.