From 987d3ce9e2221c103b2f23136d898c266b1edc4d Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Mon, 22 Aug 2022 22:35:53 +0800 Subject: [PATCH] :rocket: change indentation of `nasal_ast::print` & add new function `nasal_ast::tree`. --- nasal_ast.h | 28 +++++++++++++++++----------- nasal_parse.h | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/nasal_ast.h b/nasal_ast.h index 00c42d4..c114d89 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -137,7 +137,8 @@ public: nasal_ast(const u32 l=0,const u32 t=ast_null):_line(l),_type(t),_num(0){} nasal_ast(const nasal_ast&); nasal_ast(nasal_ast&&); - void print(u32,bool); + void tree(); + void print(u32,bool,std::vector&); void clear(); nasal_ast& operator=(const nasal_ast&); @@ -207,10 +208,15 @@ void nasal_ast::clear() _child.clear(); } -void nasal_ast::print(u32 depth,bool last=false) +void nasal_ast::tree() { - static std::vector intentation={}; - for(auto& i:intentation) + std::vector tmp; + print(0,false,tmp); +} + +void nasal_ast::print(u32 depth,bool last,std::vector& indent) +{ + for(auto& i:indent) std::cout<