Skip to content

fix(ast): correct tree indentation, render use statements, print source-syntax operators - #15

Open
Boreas618 wants to merge 2 commits into
mainfrom
fix/ast-tree-printer
Open

fix(ast): correct tree indentation, render use statements, print source-syntax operators#15
Boreas618 wants to merge 2 commits into
mainfrom
fix/ast-tree-printer

Conversation

@Boreas618

Copy link
Copy Markdown
Contributor

AST-layer unification fixes from the cross-layer audit:

  • Inverted indent flags: three DisplayAsTree impls pushed !is_last for child indent levels while the trait's own contract (and the 19 other sites) push is_last — vertical connectors broke under Program/FnDecl/FnDef.
  • use statements were invisible: Program::fmt_tree only iterated elements; use_stmts now render first, with a new DisplayAsTree for UseStmt.
  • Layer-crossing vocabulary: ArithBiOp/ComOp Display printed LLVM mnemonics (sdiv/sgt); the AST now prints TeaLang source syntax. All consumers of these impls (tree dump, error messages) are cosmetic — IR printing uses its own op types.

Verified: cargo test 30/30 green.

Comment thread src/ast/display.rs
///
/// The LLVM IR mnemonics (`add`, `sdiv`, …) are printed by the IR layer's
/// own `ArithBinOp` Display impl in `ir::stmt`; all consumers of this impl
/// (the AST tree dump and `ir::Error` messages) are cosmetic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments should be clean-slate. don't need to specially mention "The LLVM IR mnemonics...", applicable also to another change.

Comment thread src/ast/tree.rs
let mut new_indent = indent_levels.to_vec();
new_indent.push(!is_last);
let last_index = self.elements.len().saturating_sub(1);
new_indent.push(is_last);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why !is_last to is_last?

…ce-syntax operators

Fix three inverted tree-indent flags in the AST tree printer
(Program, FnDecl, FnDef pushed !is_last into the child indentation
context, contradicting the DisplayAsTree contract and the 19 other
sites that push is_last). This broke vertical connector continuity in
--emit ast dumps for nested subtrees; all three now push is_last.

Render use statements in the AST dump. Program::fmt_tree previously
iterated only elements and silently dropped use_stmts. A new leaf-style
DisplayAsTree impl for UseStmt prints 'UseStmt <module_path>', and
Program::fmt_tree now emits use_stmts before elements, marking only the
final child overall as is_last.

Remove the IR-vocabulary leak from AST Display: ArithBiOp and ComOp
printed LLVM mnemonics (sdiv, sgt, ...) instead of TeaLang source
syntax. All consumers of these impls are cosmetic -- the AST tree dump
(IfStmt/WhileStmt/ReturnStmt condition headers) and ir::Error messages
-- while IR emission uses the IR layer's own ArithBinOp/CmpPredicate
Display impls in ir::stmt. They now print + - * / and == != > >= < <=.
- removed 10 narrations (§5.1): per-branch connector explainers in
  tree_indent, restatements of adjacent code or of the enclosing doc
  comment in Program::fmt_tree, VarDecl, FnDecl, VarDef, FnCall Display
- rewrote 1 restatement into the last_index derivation in
  Program::fmt_tree (§2.2)
- trimmed 1 filler clause from the tree.rs module doc (§8.2)
- no divider banners, non-spec annotation tags, or commented-out code
  present in these files
@Boreas618
Boreas618 force-pushed the fix/ast-tree-printer branch from 5f3464c to 116dddb Compare August 1, 2026 10:59
@Boreas618
Boreas618 changed the base branch from assign3 to main August 1, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant