minor improvements

This commit is contained in:
vrd
2023-03-18 18:28:52 +02:00
parent e603913539
commit e5fa0f19fc
2 changed files with 36 additions and 17 deletions
+35 -12
View File
@@ -63,20 +63,37 @@ namespace /* internal */
const char* end;
TokenType type;
};
using TokenIt = vector<token>::const_iterator;
/* internal data */
unsigned line = 1;
pair<person_id, person_id> prev_parents(Nobody, Nobody);
/* state */
/* void state_neutral(char* it_data); */
void state_person(TokenIt& it, TokenIt end);
/* void state_person_attribute() */
/* result */
Tree* cur_tree;
/* state */
void state_neutral(const vector<token>& tokens);
void state_person(TokenIt& it, TokenIt end);
EventTime state_date(TokenIt& it);
/* helpers */
vector<token> tokenize(const MappedFile f);
string parseName(TokenIt& it, TokenIt end); /* construct name from tokens */
/* find a person's id in the tree based on his name and index
* among same named */
person_id findPerson(const string& name, U32 same_name_index);
U32 sameNamedIndex(TokenIt& it);
Sex parseSex(TokenIt& it, TokenIt end);
I32 processDatePart(const char*& it_date, const char* end_date);
pair<person_id, person_id> processParents(TokenIt& it, TokenIt end);
vector<person_id> parseSpouses(TokenIt& it, TokenIt end); /* return the spouse IDs */
bool isNum(char c);
TokenType findType(token t);
U32 calcNumber(token t); /* calculate the value of a NUMBER token */
void expect_newline(TokenIt& it); /* expect that the iterator points a newline */
/* errors */
[[noreturn]]void err_unexpected_end()
{
endwin();
@@ -233,7 +250,6 @@ namespace /* internal */
err_unexpected_token(*it);
}
/* construct name from tokens */
string parseName(TokenIt& it, TokenIt end)
{
if(it->type != STRING)
@@ -249,8 +265,6 @@ namespace /* internal */
return name;
}
/* find a person's id in the tree based on his name and index
* among same named */
person_id findPerson(const string& name, U32 same_name_index)
{
vector<person_id> same_named = cur_tree->findId(name);
@@ -312,23 +326,32 @@ namespace /* internal */
{
I32 sign = 1;
I32 val = 0;
bool unknown = false;
for(; it_date < end_date; ++it_date)
{
switch(*it_date)
{
case '-':
if(unknown)
err_unexpected_char(*it_date); /* todo */
sign = -1;
break;
case '0' ... '9':
if(unknown)
err_unexpected_char(*it_date); /* todo */
val = val*10 + (*it_date - '0');
break;
case '.':
if(val == 0)
err_unexpected_char('.');
else if(unknown)
return EventTime::UNKNOWN_DATE;
else
return sign * val;
break;
/* case '?': todo */
case '?':
unknown = true;
break;
default:
err_unexpected_char(*it_date);
}
+1 -5
View File
@@ -1,7 +1,5 @@
Parser:
- one pass rather then preprocess
--help
help - based on user config
findRelative
@@ -30,9 +28,7 @@ Compilation
- coordinate types for large trees
Backend
- file operatons check if file exists
- move to SQLlite
- create tree backup
Refactoring
- comment style /*