trees

func trees(source: String) -> String

Scans, balances, and renders macro token trees in the validation format.

Unlike lex, this exposes delimiter nesting and reports mismatched, unexpected, or unclosed delimiters. Use capture_token_trees for the structured result.

View Source
pub func trees(source: String) -> String {
	let out: [Byte] = []
	append(buf: out, text: "trees:\n")
	let result = scan(source: source)
	if let .some(message) = result.error {
		append(buf: out, text: "token tree error: tokentree.lex ")
		append(buf: out, text: message)
		append(buf: out, text: "\n")
		return String.from_bytes(bytes: out)
	}
	let grouped = capture_token_trees(tokens: result.tokens)
	if let .some(error) = grouped.error {
		append(buf: out, text: "token tree error: ")
		append(buf: out, text: token_tree_error_line(error: error))
		append(buf: out, text: "\n")
		return String.from_bytes(bytes: out)
	}
	let view = source.utf8()
	render_trees(buf: out, view: view, list: grouped.trees, depth: 1)
	String.from_bytes(bytes: out)
}