package main import "core:fmt" import "core:os" import "core:strings" read_stdin :: proc() -> []string { data, err := os.read_entire_file_from_file(os.stdin, context.allocator) content := string(data) return strings.split_lines(content) } print_token :: proc(token: Token, depth: int = 0) { indent := strings.repeat(" ", depth, context.temp_allocator) type_str := "" switch token.type { case TokenType.Root: type_str = "Root" case TokenType.Text: type_str = "Text" case TokenType.Italics: type_str = "Italics" case TokenType.Bold: type_str = "Bold" case TokenType.BreakLine: type_str = "BreakLine" case TokenType.Header: type_str = "Header" case TokenType.Paragraph: type_str = "Paragraph" case TokenType.Blockquote: type_str = "Blockquote" } value_str := "" switch v in token.value { case string: value_str = v case int: value_str = fmt.aprintf("%d", v, allocator = context.temp_allocator) } if value_str != "" { fmt.printf("%s%s(%s)", indent, type_str, value_str) } else { fmt.printf("%s%s", indent, type_str) } fmt.println() for child in token.children { print_token(child, depth + 1) } } main :: proc() { lines := read_stdin() parsed := parse(lines) print_token(parsed) }