mirror of
https://github.com/ArthurSonzogni/Diagon.git
synced 2026-08-29 08:34:44 +08:00
Add dashed arrow. (#69)
Bug:https://github.com/ArthurSonzogni/Diagon/issues/68
This commit is contained in:
@@ -58,28 +58,31 @@ int main(int, const char**) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << " [RUN ] " << test.path() << std::endl;
|
||||
std::string input = ReadFile(test.path() / "input");
|
||||
std::string output = ReadFile(test.path() / "output");
|
||||
|
||||
std::string output_computed = translator->Translate(input, options);
|
||||
|
||||
if (!std::filesystem::exists(test.path() / "output")) {
|
||||
std::cout << " [RUN ] " << test.path() << std::endl;
|
||||
std::cout << " [Create output] " << std::endl;
|
||||
std::cout << output_computed;
|
||||
std::ofstream(test.path() / "output") << output_computed;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string output = ReadFile(test.path() / "output");
|
||||
if (output_computed == output) {
|
||||
// std::cout << " [PASS] " << test.path() << std::endl;
|
||||
} else {
|
||||
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;
|
||||
|
||||
//std::ofstream(test.path() / "output") << output_computed;
|
||||
|
||||
result = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
for (int y = top; y <= bottom; ++y) {
|
||||
lines_[y][x] = L'│';
|
||||
lines_[y][x] = c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,21 +41,19 @@ void Actor::Draw(Screen& screen, int height) {
|
||||
|
||||
void Message::Draw(Screen& screen) {
|
||||
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 {
|
||||
if (direction == Direction::Right) {
|
||||
screen.DrawHorizontalLine(line_left, line_left + offset, line_top);
|
||||
screen.DrawVerticalLine(line_top, line_bottom, line_left + offset);
|
||||
screen.DrawHorizontalLine(line_left + offset, line_right, line_bottom);
|
||||
screen.DrawPixel(line_left + offset, line_top, 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'┘');
|
||||
}
|
||||
screen.DrawHorizontalLine(line_right - offset, line_right, line_top, dashed ? L'-' : L'─');
|
||||
screen.DrawVerticalLine(line_top, line_bottom, line_right - offset, dashed ? L'|' : L'│');
|
||||
screen.DrawHorizontalLine(line_left, line_right - offset, line_bottom, dashed ? L'-' : L'─');
|
||||
screen.DrawPixel(line_right - offset, line_top, L'.');
|
||||
screen.DrawPixel(line_right - offset, line_bottom, L'`');
|
||||
}
|
||||
|
||||
// Tip of the arrow.
|
||||
@@ -464,6 +462,8 @@ void Sequence::AddMessageCommand(
|
||||
|
||||
message.from = GetText(message_command->text(0));
|
||||
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) {
|
||||
std::cerr << "Self messages are not supported yet. It has been ignored."
|
||||
@@ -473,7 +473,8 @@ void Sequence::AddMessageCommand(
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ COMMENT: '/' '*' .*? '*' '/' -> channel(HIDDEN);
|
||||
LINE_COMMENT: '/' '/' (~('\n'))* -> channel(HIDDEN);
|
||||
|
||||
ARROW_RIGHT: '->';
|
||||
ARROW_RIGHT_DASHED: '-->';
|
||||
ARROW_LEFT: '<-';
|
||||
ARROW_LEFT_DASHED: '<--';
|
||||
COMMA: ':';
|
||||
LOWER: '<';
|
||||
GREATER: '>';
|
||||
@@ -39,5 +41,5 @@ number: SPACE* NUMBER SPACE*;
|
||||
|
||||
comparison: LOWER | GREATER;
|
||||
|
||||
arrow: ARROW_LEFT | ARROW_RIGHT;
|
||||
arrow: ARROW_LEFT | ARROW_RIGHT | ARROW_LEFT_DASHED | ARROW_RIGHT_DASHED;
|
||||
// vim: filetype=ANTLR
|
||||
|
||||
@@ -42,6 +42,7 @@ struct Message {
|
||||
std::wstring to;
|
||||
int id = -1;
|
||||
std::vector<std::wstring> messages;
|
||||
bool dashed = false;
|
||||
|
||||
Direction direction = Direction::Right;
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
A --> B: Make me a sandwitch
|
||||
B --> A: No
|
||||
A --> B: Sudo make me a sandwitch
|
||||
B --> A: Okay
|
||||
@@ -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│
|
||||
└─┘ └─┘
|
||||
@@ -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
|
||||
@@ -0,0 +1,16 @@
|
||||
┌─┐ ┌─┐
|
||||
│A│ │B│
|
||||
└┬┘ └┬┘
|
||||
│ │
|
||||
│--. │
|
||||
│message 2│
|
||||
│-------->│
|
||||
│ | │
|
||||
│message 1│
|
||||
│ `----->│
|
||||
│ │
|
||||
│message 3│
|
||||
│<--------│
|
||||
┌┴┐ ┌┴┐
|
||||
│A│ │B│
|
||||
└─┘ └─┘
|
||||
Reference in New Issue
Block a user