Skip to content

Commit

Permalink
Merge pull request #138 from abap34/bug/#137
Browse files Browse the repository at this point in the history
DivBlock のパースの不具合を修正
  • Loading branch information
abap34 authored Jun 21, 2024
2 parents 1cec61d + 99e197e commit 3100fc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Reader {
return lines[row].substr(col);
}
void move_next_line(){
assert(row < (int)(lines.size()));
row++;
col = 0;
}
Expand Down
8 changes: 6 additions & 2 deletions src/syntax/DivBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct DivBlockSyntax : public BlockSyntax {
std::vector<std::string> text;

while (!read.is_eof()){
// Invariant : scopes.size() >= 1
if (rtrim(read.get_row()) == ":::"){
Markdown inner_md;
MarkdownParser parser(text, read.meta_data);
Expand All @@ -61,6 +62,7 @@ struct DivBlockSyntax : public BlockSyntax {

if (scopes.size() == 1u){
ast.add_child(scopes.top());
scopes.pop();
break;
}
scopes.pop();
Expand All @@ -86,23 +88,25 @@ struct DivBlockSyntax : public BlockSyntax {
text.emplace_back(read.get_row());
read.move_next_line();
}
while (true){
// scopes.empty() iff completed DivBlock
while (!scopes.empty()){
Markdown inner_md;
MarkdownParser parser(text, read.meta_data);
parser.process(inner_md);
auto inner_md_ptr = std::make_shared<Markdown>(inner_md);
scopes.top()->add_child(inner_md_ptr);

text = {};
read.move_next_line();

if (scopes.size() == 1u){
ast.add_child(scopes.top());
scopes.pop();
break;
}
scopes.pop();
continue;
}
assert(scopes.empty());
}
};

Expand Down

0 comments on commit 3100fc5

Please sign in to comment.