cyrilic attributes

This commit is contained in:
vrd
2023-04-25 22:28:05 +03:00
parent 81fc94d472
commit 75fa6d7da5
+64 -25
View File
@@ -37,7 +37,10 @@ namespace /* internal */
enum TokenType enum TokenType
{ {
ATTRIBUTE, ATR_BIRTH,
ATR_DEATH,
ATR_PARENTS,
ATR_SPOUSES,
STRING, STRING,
/* DATE, */ /* DATE, */
NUMBER, NUMBER,
@@ -113,9 +116,9 @@ namespace /* internal */
[[noreturn]]void err_expected(const char* what, token instead) [[noreturn]]void err_expected(const char* what, token instead)
{ {
endwin(); endwin();
cerr << "Line " << line << ": Expected " << what << "got"; cerr << "Line " << line << ": Expected " << what << " got ";
cerr.write(instead.begin, instead.size()); cerr.write(instead.begin, instead.size());
cerr << "instead\n"; cerr << " instead\n";
cerr.flush(); cerr.flush();
exit(1); exit(1);
} }
@@ -212,10 +215,43 @@ namespace /* internal */
type = NEW_LINE; type = NEW_LINE;
} }
} }
else if(t.size() == 2) else if(t.end[-1] == ':')
{ {
if(t.begin[1] == ':') switch(t.begin[0])
type = ATTRIBUTE; {
case 'b':
type = ATR_BIRTH;
break;
case 'd':
type = ATR_DEATH;
break;
case 'p':
type = ATR_PARENTS;
break;
case 's':
type = ATR_SPOUSES;
break;
default:
U16 cyr = ((U8)t.begin[0] << 8) | (U8)t.begin[1]; /* assuming char signed? */
switch(cyr) /* check for cyrilic attribure */
{
case 'д':
type = ATR_BIRTH;
break;
case 'п':
type = ATR_DEATH;
break;
case 'р':
type = ATR_PARENTS;
break;
case 'с':
type = ATR_SPOUSES;
break;
default:
err_illegal_attribute(t);
}
}
} }
} }
return type; return type;
@@ -309,9 +345,19 @@ namespace /* internal */
err_expected("sex", *it); err_expected("sex", *it);
++it; ++it;
} }
else if(it->size() == 2)
{
U16 cyr = ((U8)it->begin[0] << 8) | (U8)it->begin[1]; /* assuming char signed? */
if(cyr == 'М')
res = M;
else if(cyr == 'Ж')
res = F;
else
err_expected("sex", *it);
++it;
}
else else
err_expected("sex", *it); err_expected("sex", *it);
} }
else else
err_unexpected_token(*it); err_unexpected_token(*it);
@@ -494,24 +540,17 @@ namespace /* internal */
{ {
switch(it->type) switch(it->type)
{ {
case ATTRIBUTE: case ATR_BIRTH:
switch(it->begin[0]) birth = state_date(it); /* todo check for redefinition */
{ break;
case 'b': case ATR_DEATH:
birth = state_date(it); /* todo check for redefinition */ death = state_date(it);
break; break;
case 'd': case ATR_PARENTS:
death = state_date(it); parents = processParents(it, end);
break; break;
case 'p': case ATR_SPOUSES:
parents = processParents(it, end); spouses = parseSpouses(it, end);
break;
case 's':
spouses = parseSpouses(it, end);
break;
default:
err_illegal_attribute(*it);
}
break; break;
case NEW_LINE: case NEW_LINE:
++line; ++line;