mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
comments and error message improvements
This commit is contained in:
@@ -17,11 +17,12 @@ int32_t column;
|
||||
int32_t previousRow;
|
||||
int32_t previousColumn;
|
||||
bool textStarted = false;
|
||||
bool identifierStarted = false;
|
||||
bool cooldownStarted = false;
|
||||
bool sof;
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Noņem norādītos simbolus no simbolu virknes kreisās un labās pusēs.
|
||||
* Simboli tiek noņemti līdz tiek sastapts simbols, kas nav norādīts.
|
||||
*/
|
||||
void trimString(std::string *str, std::string trimChars) {
|
||||
|
||||
@@ -123,12 +124,14 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
for (size_t i = 0; i < content.size(); ++i) {
|
||||
char c = content[i];
|
||||
|
||||
// Apstrādā īpašos simbolus un tekstu.
|
||||
// Pavirza faila norādi un papildina buferi.
|
||||
if (c == '\n') {
|
||||
row += 1;
|
||||
column = 0;
|
||||
}
|
||||
if (c == '\\') {
|
||||
// Simbolus, kas abilst citām tekstvienībām, var ievadīt,
|
||||
// ja pirms tiem ieliek '\' simbolu.
|
||||
i += 1;
|
||||
if (i < content.size()) {
|
||||
buffer.push_back(content[i]);
|
||||
@@ -137,6 +140,7 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
} else {
|
||||
buffer.push_back(c);
|
||||
}
|
||||
// Iepriekšējā tekstvienības pozīcijas uzturēšana.
|
||||
if (!textStarted) {
|
||||
if (c == '\n') {
|
||||
previousRow += 1;
|
||||
@@ -150,7 +154,7 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
}
|
||||
}
|
||||
|
||||
// Emitē tekstvienības.
|
||||
// Izveido viena simbola tekstvienības, ja tāda ir sastapta.
|
||||
switch (c) {
|
||||
case '[': {
|
||||
tokenWithBuffer(
|
||||
@@ -161,13 +165,16 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
previousRow = row;
|
||||
previousColumn = column;
|
||||
textStarted = false;
|
||||
identifierStarted = true;
|
||||
|
||||
// Karodziņš, lai zinātu, kad ir jānosaka pārtraukuma
|
||||
// tekstvienību.
|
||||
cooldownStarted = true;
|
||||
} break;
|
||||
case ']': {
|
||||
if (!identifierStarted) {
|
||||
if (!cooldownStarted) {
|
||||
return {
|
||||
tokens,
|
||||
"Nevar beigt identifikatoru, ja tas nav iesākts",
|
||||
"Nevar beigt pārtraukuma norādīšanu, ja tas nav iesākts",
|
||||
tokens[i].row,
|
||||
tokens[i].column
|
||||
};
|
||||
@@ -180,7 +187,7 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
previousRow = row;
|
||||
previousColumn = column;
|
||||
textStarted = false;
|
||||
identifierStarted = false;
|
||||
cooldownStarted = false;
|
||||
} break;
|
||||
case '-': {
|
||||
tokenWithBuffer(
|
||||
@@ -255,9 +262,13 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
std::cout << "SECTION END: LEXER\n";
|
||||
}
|
||||
|
||||
// Leksiskā analīze ir veiksmīga - neatgriež kļūdu.
|
||||
return {tokens, ""};
|
||||
}
|
||||
|
||||
/*
|
||||
* Tekstvienības nosaukums latviešu valodā.
|
||||
*/
|
||||
std::string Token::toString(const TokenType* ttype) {
|
||||
switch (*ttype) {
|
||||
case TokenType::TextFragment: return "teksta fragments";
|
||||
@@ -275,6 +286,9 @@ std::string Token::toString(const TokenType* ttype) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tekstvienību reprezentējoša simbolu virkne atkļūdošanai.
|
||||
*/
|
||||
std::string Token::toString() const {
|
||||
std::string contentStr = content;
|
||||
static const std::regex nextLineExp("\n", std::regex_constants::ECMAScript);
|
||||
|
||||
Reference in New Issue
Block a user