Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,44 @@ namespace diannex
{
pos++;
count++;
if (input.at(pos) == '\n')
if (pos < len && input.at(pos) == '\n')
{
tempLine++;
tempCol = 0;
}
else
tempCol++;
}
std::string exprStr = input.substr(startPos, count);

// Parse expression and add to nodes
std::vector<Token> tokens;
Lexer::LexString(exprStr, parser->context, tokens, line, col);
ParseResult parsed = Parser::ParseTokensExpression(parser->context, &tokens, line, col);
if (parsed.errors.size() != 0)
parser->errors.insert(parser->errors.end(), parsed.errors.begin(), parsed.errors.end());
char lastChar;

if (pos >= len)
lastChar = input.at(len - 1);
else
lastChar = input.at(pos);

if (lastChar == '}')
{
nodeList->push_back(parsed.baseNode);
parsed.doDelete = false;
}
std::string exprStr = input.substr(startPos, count);

// Parse expression and add to nodes
std::vector<Token> tokens;
Lexer::LexString(exprStr, parser->context, tokens, line, col);
ParseResult parsed = Parser::ParseTokensExpression(parser->context, &tokens, line, col);
if (parsed.errors.size() != 0)
parser->errors.insert(parser->errors.end(), parsed.errors.begin(), parsed.errors.end());
else
{
nodeList->push_back(parsed.baseNode);
parsed.doDelete = false;
}

// Also add the proper string representation
ss << "${" << interpCount++ << "}";
line = tempLine;
col = tempCol + 1;
// Also add the proper string representation
ss << "${" << interpCount++ << "}";
line = tempLine;
col = tempCol + 1;
}
else
parser->errors.push_back({ ParseError::ErrorType::ExpectedTokenButEOF, (uint32_t) tempLine, (uint32_t) tempCol, "}" });
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int main(int argc, char** argv)
("D,privname", "Name of output private translation file", cxxopts::value<std::string>(), "(default: \"out\")")
("d,privdir", "Directory to output private translation files", cxxopts::value<std::string>(), "(default: \"./translations\")")
("C,compress", "Whether or not to use compression")
("I,nointerpolate", "Whether string interpolation should be disabled")
("files", "File(s) to compile", cxxopts::value<std::vector<std::string>>()->default_value(""));


Expand Down Expand Up @@ -424,7 +425,8 @@ int main(int argc, char** argv)
project.options.translationPrivateName = result["privname"].count() == 1 ? result["privname"].as<std::string>() : "out";
project.options.translationPrivateOutDir = result["privdir"].count() == 1 ? result["privdir"].as<std::string>() : "./translations";
project.options.compression = result["compress"].count() == 1 ? result["compress"].as<bool>() : false;
loaded = true;
project.options.interpolationEnabled = result["nointerpolate"].count() == 0;
loaded = true;
}

if (!loaded)
Expand Down Expand Up @@ -756,4 +758,4 @@ int main(int argc, char** argv)
std::cout << "Took " << duration.count() << " milliseconds." << rang::fg::reset << std::endl;

return 0;
}
}
Loading