Skip to content

Commit

Permalink
ブロックを閉じるときに末尾のスペースを許容するように
Browse files Browse the repository at this point in the history
  • Loading branch information
abap34 committed Apr 21, 2024
1 parent ebc9167 commit f9f95ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace almo {

// 1行ずつ読み込み、judge_info に情報を追加していく
while (idx < (int)lines.size()) {
if (lines[idx] == ":::") break;
if (rtrim(lines[idx]) == ":::") break;
std::string key = lines[idx].substr(0, lines[idx].find("="));
std::string value = lines[idx].substr(lines[idx].find("=") + 1);
judge_info[key] = value;
Expand Down Expand Up @@ -298,7 +298,7 @@ namespace almo {
assert(idx < (int)lines.size());
std::string code;
while (idx < (int)lines.size()) {
if (lines[idx] == ":::") break;
if (rtrim(lines[idx]) == ":::") break;
code += lines[idx] + "\n";
idx++;
}
Expand All @@ -310,7 +310,7 @@ namespace almo {
assert(idx < (int)lines.size());
std::vector<std::string> libs;
while (idx < (int)lines.size()) {
if (lines[idx] == ":::") break;
if (rtrim(lines[idx]) == ":::") break;
libs.push_back(lines[idx]);
idx++;
}
Expand All @@ -322,7 +322,7 @@ namespace almo {
idx++;
std::string code;
while (idx < (int)lines.size()) {
if (lines[idx] == "```") break;
if (rtrim(lines[idx]) == "```") break;
code += lines[idx] + "\n";
idx++;
}
Expand All @@ -340,13 +340,13 @@ namespace almo {
idx++;
std::vector<std::string> text;

if (lines[idx] == ":::") {
if (rtrim(lines[idx]) == ":::") {
root.childs.push_back(scopes.top());
}
else {
while (idx < (int)lines.size()) {

if (lines[idx] == ":::") {
if (rtrim(lines[idx]) == ":::") {
// 一つぶん入れ子が終了
BlockParser parser = BlockParser();
Block contents = parser.processer(text);
Expand Down
9 changes: 8 additions & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,11 @@ std::string escape(const std::string &s) {
}
}
return o.str();
}
}


// 文字列を受け取り、末尾のスペースを削除する
std::string rtrim(std::string s) {
s.erase(s.find_last_not_of(" \n\r\t") + 1);
return s;
}

0 comments on commit f9f95ae

Please sign in to comment.