Add dashed arrow. (#69)

Bug:https://github.com/ArthurSonzogni/Diagon/issues/68
This commit is contained in:
Arthur Sonzogni
2023-08-27 10:55:16 +02:00
committed by GitHub
parent 81d56ea740
commit 469264d88f
11 changed files with 116 additions and 33 deletions
+19 -16
View File
@@ -58,26 +58,29 @@ int main(int, const char**) {
continue; continue;
} }
std::cout << " [RUN ] " << test.path() << std::endl;
std::string input = ReadFile(test.path() / "input"); std::string input = ReadFile(test.path() / "input");
std::string output = ReadFile(test.path() / "output");
std::string output_computed = translator->Translate(input, options); std::string output_computed = translator->Translate(input, options);
if (output_computed == output) { if (!std::filesystem::exists(test.path() / "output")) {
// std::cout << " [PASS] " << test.path() << std::endl; std::cout << " [RUN ] " << test.path() << std::endl;
} else { std::cout << " [Create output] " << std::endl;
std::cout << " [FAIL] " << test.path() << std::endl; std::cout << output_computed;
std::cout << "---[Output]------------------" << std::endl; std::ofstream(test.path() / "output") << output_computed;
std::cout << output_computed << std::endl; continue;
std::cout << "---[Expected]----------------" << std::endl;
std::cout << output << std::endl;
std::cout << "---------------------" << std::endl;
//std::ofstream(test.path() / "output") << output_computed;
result = EXIT_FAILURE;
} }
std::string output = ReadFile(test.path() / "output");
if (output_computed == output) {
continue;
}
std::cout << " [FAIL] " << test.path() << std::endl;
std::cout << "---[Output]------------------" << std::endl;
std::cout << output_computed << std::endl;
std::cout << "---[Expected]----------------" << std::endl;
std::cout << output << std::endl;
std::cout << "---------------------" << std::endl;
result = EXIT_FAILURE;
} }
} }
+1 -1
View File
@@ -90,7 +90,7 @@ void Screen::DrawHorizontalLine(int left, int right, int y, wchar_t c) {
void Screen::DrawVerticalLine(int top, int bottom, int x, wchar_t c) { void Screen::DrawVerticalLine(int top, int bottom, int x, wchar_t c) {
for (int y = top; y <= bottom; ++y) { for (int y = top; y <= bottom; ++y) {
lines_[y][x] = L''; lines_[y][x] = c;
} }
} }
+16 -15
View File
@@ -41,21 +41,19 @@ void Actor::Draw(Screen& screen, int height) {
void Message::Draw(Screen& screen) { void Message::Draw(Screen& screen) {
if (line_top == line_bottom) { if (line_top == line_bottom) {
screen.DrawHorizontalLine(line_left, line_right, line_top); screen.DrawHorizontalLine(line_left, line_right, line_top, dashed ? L'-' : L'');
} else if (direction == Direction::Right) {
screen.DrawHorizontalLine(line_left, line_left + offset, line_top, dashed ? L'-' : L'');
screen.DrawVerticalLine(line_top, line_bottom, line_left + offset, dashed ? L'|' : L'');
screen.DrawHorizontalLine(line_left + offset, line_right, line_bottom, dashed ? L'-' : L'');
screen.DrawPixel(line_left + offset, line_top, dashed ? L'.' : L'');
screen.DrawPixel(line_left + offset, line_bottom, dashed ? L'`' : L'');
} else { } else {
if (direction == Direction::Right) { screen.DrawHorizontalLine(line_right - offset, line_right, line_top, dashed ? L'-' : L'');
screen.DrawHorizontalLine(line_left, line_left + offset, line_top); screen.DrawVerticalLine(line_top, line_bottom, line_right - offset, dashed ? L'|' : L'');
screen.DrawVerticalLine(line_top, line_bottom, line_left + offset); screen.DrawHorizontalLine(line_left, line_right - offset, line_bottom, dashed ? L'-' : L'');
screen.DrawHorizontalLine(line_left + offset, line_right, line_bottom); screen.DrawPixel(line_right - offset, line_top, L'.');
screen.DrawPixel(line_left + offset, line_top, L''); screen.DrawPixel(line_right - offset, line_bottom, L'`');
screen.DrawPixel(line_left + offset, line_bottom, L'');
} else {
screen.DrawHorizontalLine(line_right - offset, line_right, line_top);
screen.DrawVerticalLine(line_top, line_bottom, line_right - offset);
screen.DrawHorizontalLine(line_left, line_right - offset, line_bottom);
screen.DrawPixel(line_right - offset, line_top, L'');
screen.DrawPixel(line_right - offset, line_bottom, L'');
}
} }
// Tip of the arrow. // Tip of the arrow.
@@ -464,6 +462,8 @@ void Sequence::AddMessageCommand(
message.from = GetText(message_command->text(0)); message.from = GetText(message_command->text(0));
message.to = GetText(message_command->text(1)); message.to = GetText(message_command->text(1));
message.dashed = message_command->arrow()->ARROW_LEFT_DASHED() != nullptr ||
message_command->arrow()->ARROW_RIGHT_DASHED() != nullptr;
if (message.from == message.to) { if (message.from == message.to) {
std::cerr << "Self messages are not supported yet. It has been ignored." std::cerr << "Self messages are not supported yet. It has been ignored."
@@ -473,7 +473,8 @@ void Sequence::AddMessageCommand(
return; return;
} }
if (message_command->arrow()->ARROW_LEFT()) { if (message_command->arrow()->ARROW_LEFT() ||
message_command->arrow()->ARROW_LEFT_DASHED()) {
std::swap(message.from, message.to); std::swap(message.from, message.to);
} }
+3 -1
View File
@@ -8,7 +8,9 @@ COMMENT: '/' '*' .*? '*' '/' -> channel(HIDDEN);
LINE_COMMENT: '/' '/' (~('\n'))* -> channel(HIDDEN); LINE_COMMENT: '/' '/' (~('\n'))* -> channel(HIDDEN);
ARROW_RIGHT: '->'; ARROW_RIGHT: '->';
ARROW_RIGHT_DASHED: '-->';
ARROW_LEFT: '<-'; ARROW_LEFT: '<-';
ARROW_LEFT_DASHED: '<--';
COMMA: ':'; COMMA: ':';
LOWER: '<'; LOWER: '<';
GREATER: '>'; GREATER: '>';
@@ -39,5 +41,5 @@ number: SPACE* NUMBER SPACE*;
comparison: LOWER | GREATER; comparison: LOWER | GREATER;
arrow: ARROW_LEFT | ARROW_RIGHT; arrow: ARROW_LEFT | ARROW_RIGHT | ARROW_LEFT_DASHED | ARROW_RIGHT_DASHED;
// vim: filetype=ANTLR // vim: filetype=ANTLR
+1
View File
@@ -42,6 +42,7 @@ struct Message {
std::wstring to; std::wstring to;
int id = -1; int id = -1;
std::vector<std::wstring> messages; std::vector<std::wstring> messages;
bool dashed = false;
Direction direction = Direction::Right; Direction direction = Direction::Right;
+4
View File
@@ -0,0 +1,4 @@
A --> B: Make me a sandwitch
B --> A: No
A --> B: Sudo make me a sandwitch
B --> A: Okay
+18
View File
@@ -0,0 +1,18 @@
┌─┐ ┌─┐
│A│ │B│
└┬┘ └┬┘
│ │
│ Make me a sandwitch │
│----------------------->│
│ │
│ No │
│<-----------------------│
│ │
│Sudo make me a sandwitch│
│----------------------->│
│ │
│ Okay │
│<-----------------------│
┌┴┐ ┌┴┐
│A│ │B│
└─┘ └─┘
@@ -0,0 +1,8 @@
1) A-->B: message 1
2) A-->B: message 2
3) A-->B: message 3
4) A-->B: message 4
5) A-->B: message 5
A: 1<2<3<4<5
B: 2<1<5<4<3
@@ -0,0 +1,24 @@
┌─┐ ┌─┐
│A│ │B│
└┬┘ └┬┘
│ │
│--. │
│message 2│
│-------->│
│ | │
│message 1│
│ `----->│
│ │
│----. │
│--. | │
│message 5│
│-------->│
│ | | │
│message 4│
│ `----->│
│ | │
│message 3│
│ `--->│
┌┴┐ ┌┴┐
│A│ │B│
└─┘ └─┘
+6
View File
@@ -0,0 +1,6 @@
1) A --> B : message 1
2) A --> B : message 2
3) A <-- B : message 3
A: 1<2
B: 1>2
+16
View File
@@ -0,0 +1,16 @@
┌─┐ ┌─┐
│A│ │B│
└┬┘ └┬┘
│ │
│--. │
│message 2│
│-------->│
│ | │
│message 1│
│ `----->│
│ │
│message 3│
│<--------│
┌┴┐ ┌┴┐
│A│ │B│
└─┘ └─┘