From e603913539d10ea9df7822ed3f0d16f3f2c23c6f Mon Sep 17 00:00:00 2001 From: Venelin Date: Fri, 17 Mar 2023 09:45:59 +0200 Subject: [PATCH] drop preprocesing --- src/parser.cpp | 51 +++++++++++++++++++------------------------------- todo.txt | 15 ++++++--------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 7432377..643578f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -66,7 +66,6 @@ namespace /* internal */ using TokenIt = vector::const_iterator; - char* end_data_; /* past the end pointer */ unsigned line = 1; pair prev_parents(Nobody, Nobody); @@ -507,36 +506,15 @@ namespace /* internal */ } } - alloced removeComments(MappedFile file) /* todo - drop */ - { - alloced res(file.len); - - char* itres = res.data; - char* end = file.data + file.len; - for(char* it = file.data; it < end; ++it) - { - if(*it == '#') - { - while(++it != end && *it != '\n'); /* skip comment */ - *itres++ = '\n'; /* add \n */ - } - else - { - *itres = *it; - ++itres; - } - } - end_data_ = itres; - return res; - } - - vector tokenize(const char* data_begin, const char* data_end) + vector tokenize(const MappedFile f) { vector tokens; tokens.reserve(256); - const char* token_begin = data_begin; + const char* token_begin = f.data; + const char* end = f.data + f.len; - for(const char* it = data_begin; it < data_end; ++it) + const char* it = f.data; + for(; it < end; ++it) { switch(*it) { @@ -555,15 +533,25 @@ namespace /* internal */ case '\n': if(token_begin < it) tokens.emplace_back(token_begin, it); - tokens.emplace_back(it, it+1); - token_begin = it+1; + tokens.emplace_back(it, it+1); /* add the , or \n as a token */ + token_begin = it + 1; + break; + case '#': + if(token_begin < it) + tokens.emplace_back(token_begin, it); + while(++it < end && *it != '\n'); /* skip comment */ + token_begin = it; + --it; break; /* case '0' ... '9': */ default: break; } } - tokens.emplace_back(NEW_LINE); + if(token_begin < it) + tokens.emplace_back(token_begin, it); + + tokens.emplace_back(NEW_LINE); /* add newlines at the end for easier parsing */ tokens.emplace_back(NEW_LINE); return tokens; } @@ -578,8 +566,7 @@ Tree parseTftFile(const char* path) cur_tree = &result; MappedFile mapedfile = mapfile(file); - alloced preprocessed = removeComments(mapedfile); - vector tokens = tokenize(preprocessed.data, end_data_); + vector tokens = tokenize(mapedfile); state_neutral(tokens); diff --git a/todo.txt b/todo.txt index f8c1935..6fb3291 100644 --- a/todo.txt +++ b/todo.txt @@ -1,34 +1,31 @@ Parser: -- clean wh -- tokens? +- one pass rather then preprocess --help -help - lowercase +help - based on user config findRelative findRelation - extend -Draw distinct regions of a tree -Draw spouses' relatives if main has none? - Combine trees on the command line -Zooming - Visualization: +- zooming - horizontal navigation between cousins - color on different consoles - screen resize - empty tree - half children and main tree - distincs tree regions -- info bar Compilation - static and dynamic ncurses ? +- info bar +- tree visualizer component +- distinct regions of a tree - same person can be displayed twice - coordinate types for large trees