mitex-rs / mitex

LaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
https://mitex-rs.github.io/mitex/tools/underleaf.html
Apache License 2.0
240 stars 8 forks source link

Architecture.md #146

Open Enter-tainer opened 3 months ago

Enter-tainer commented 3 months ago

mitex's design of spliting spec and parser/lexer is very clever and impressive. It however make it harder for people to understand what's happening. It would be better we can have a doc explaining what will happen when you type #mi(...)

Enter-tainer commented 3 months ago

I'm reading mitex's code currently and maybe I will write one.

Myriad-Dreamin commented 3 months ago

The existing snapshots of lexer, parser, and converter would help you understand correctly, by simulating execution in your mind and compared with the snapshots.

btw, you can also make your owned testpoint in bug_playground functions:

https://github.com/mitex-rs/mitex/blob/8e5045ac836e31f4c0b7e185052a1145e2d8b809/crates/mitex-parser/tests/ast.rs#L41-L47

For example you write a snapshot assertion:

/// Convenient function to launch/debug a test case 
#[test] 
fn bug_playground() {
  assert_debug_snapshot!(parse(r#"\frac{ a }{ b }"#), @"");
} 

You can generate the snapshot fastly by cargo insta test --accept. You can also launch debugging by code lenses over bug_playground function to dive in execution:

image