capture_macro_input

func capture_macro_input(source_id: Int, source: String, encoded: String) -> MacroInput?

Decode the parser-recorded canonical token records supplied by the macro service ABI. This does not inspect token spelling or run the lexer again.

View Source
pub func capture_macro_input(source_id: Int, source: String, encoded: String) -> MacroInput? {
	if encoded.utf8().count() == 0 { return .none }
	let tokens: [Token]
	if let .some(decoded) = decode_token_records(encoded: encoded) { tokens = decoded } else { return .none }
	let captured = capture_token_trees(tokens: tokens)
	if captured.trees.count != 1 { return .none }
	for tree in captured.trees {
		match tree {
			.group(group) -> return .some(MacroInput(source_id: source_id, source: source, tree: .group(group))),
			_ -> return .none
		}
	}
	.none
}