Scaffold Rust M0 interpreter crate and document local setup.

Add clap-based CLI that loads .mq.md and fails loudly until eval exists; pin deps for Cargo 1.81 and verify with an integration test.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-04 11:19:32 +08:00
1 parent 27a289217f
commit 63d7866d06
12 files changed
+661 -2

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
//! Diagnostics with file/line/column.
//! Expanded in M1+.
use std::fmt;
#[derive(Debug, Clone)]
pub struct Span {
pub line: u32,
pub col: u32,
}
impl fmt::Display for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.line, self.col)
}
}
+11
View File
@@ -0,0 +1,11 @@
//! Line classification and tokenization (no Flex).
//! Implementation arrives in M1.
#![allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineKind {
Comment,
Code,
Blank,
}
+30
View File
@@ -0,0 +1,30 @@
//! Marqdo reference interpreter (Phase I scaffolding).
//!
//! Pipeline (see `doc/roadmap/interpreter.md`):
//! load → line classify / lex → parse → sema → tree-walk eval.
pub mod diagnostics;
pub mod lex;
pub mod parse;
use std::path::Path;
use anyhow::{bail, Context, Result};
/// Run a `.mq.md` program. Phase I: not yet implemented beyond scaffolding.
pub fn run_file(path: &Path) -> Result<i32> {
let source = std::fs::read_to_string(path)
.with_context(|| format!("failed to read {}", path.display()))?;
if source.is_empty() {
bail!("{} is empty", path.display());
}
// Placeholder: real lex/parse/eval lands in subsequent milestones.
eprintln!(
"marqdo: loaded {} ({} bytes); interpreter not implemented yet (M0 scaffold)",
path.display(),
source.len()
);
bail!("evaluation not implemented — see doc/roadmap/interpreter.md (M1+)")
}
+43
View File
@@ -0,0 +1,43 @@
use std::path::PathBuf;
use std::process::ExitCode;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(name = "marqdo", version, about = "Marqdo interpreter — run .mq.md programs")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
/// Execute a Marqdo source file (defaults to ./index.mq.md)
Run {
/// Path to a `.mq.md` file
#[arg(value_name = "FILE")]
file: Option<PathBuf>,
},
}
fn main() -> ExitCode {
match try_main() {
Ok(code) => ExitCode::from(code as u8),
Err(err) => {
eprintln!("error: {err:#}");
ExitCode::from(1)
}
}
}
fn try_main() -> Result<i32> {
let cli = Cli::parse();
match cli.command {
Commands::Run { file } => {
let path = file.unwrap_or_else(|| PathBuf::from("index.mq.md"));
marqdo::run_file(&path)?;
Ok(0)
}
}
}
+9
View File
@@ -0,0 +1,9 @@
//! Recursive-descent parser → AST (no Bison).
//! Implementation arrives in M1–M2.
#![allow(dead_code)]
#[derive(Debug, Default)]
pub struct Module {
// Filled by parser in later milestones.
}