feat: unclosed expression test added and fulfilled
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>Hello World</h1>
|
||||||
|
<p>{{ INVALID EXPRESSION </p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+13
-5
@@ -31,15 +31,23 @@ void test_parse_unclosed_expression() {
|
|||||||
p.parse();
|
p.parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_parse_unclosed_expression_2() {
|
||||||
|
std::ifstream i("test/test_parse_unclosed_expression_2.wbt", std::ios_base::in);
|
||||||
|
std::ostream o(std::cout.rdbuf());
|
||||||
|
const WBT_Parser p(i, o);
|
||||||
|
p.parse();
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << std::endl << "-----" << std::endl;
|
std::cout << std::endl << "1 -----" << std::endl;
|
||||||
test_parse_no_expressions();
|
test_parse_no_expressions();
|
||||||
std::cout << std::endl << "-----" << std::endl;
|
std::cout << std::endl << "2 -----" << std::endl;
|
||||||
test_parse_single_expression();
|
test_parse_single_expression();
|
||||||
std::cout << std::endl << "-----" << std::endl;
|
std::cout << std::endl << "3 -----" << std::endl;
|
||||||
test_parse_invalid_character_expression();
|
test_parse_invalid_character_expression();
|
||||||
std::cout << std::endl << "-----" << std::endl;
|
std::cout << std::endl << "4 -----" << std::endl;
|
||||||
test_parse_unclosed_expression();
|
test_parse_unclosed_expression();
|
||||||
std::cout << std::endl << "-----" << std::endl;
|
std::cout << std::endl << "5 -----" << std::endl;
|
||||||
|
test_parse_unclosed_expression_2();
|
||||||
|
std::cout << std::endl << "END -----" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-3
@@ -5,13 +5,20 @@ module;
|
|||||||
// This module is the transpiler from WBT to HTML for site build
|
// This module is the transpiler from WBT to HTML for site build
|
||||||
export module wbt;
|
export module wbt;
|
||||||
|
|
||||||
export enum WBT_States {
|
enum WBT_States {
|
||||||
WBT_STATE_INIT,
|
WBT_STATE_INIT,
|
||||||
WBT_STATE_OPEN,
|
WBT_STATE_OPEN,
|
||||||
WBT_STATE_EXPRESSION,
|
WBT_STATE_EXPRESSION,
|
||||||
WBT_STATE_CLOSE,
|
WBT_STATE_CLOSE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct WBT_Parser_Internal_Data {
|
||||||
|
int32_t line = 1;
|
||||||
|
int32_t column = 1;
|
||||||
|
int32_t expr_start_line = 1;
|
||||||
|
int32_t expr_start_column = 1;
|
||||||
|
};
|
||||||
|
|
||||||
export class WBT_Parser {
|
export class WBT_Parser {
|
||||||
std::istream& input;
|
std::istream& input;
|
||||||
std::ostream& output;
|
std::ostream& output;
|
||||||
@@ -38,8 +45,7 @@ public:
|
|||||||
void parse() const {
|
void parse() const {
|
||||||
auto state = WBT_STATE_INIT;
|
auto state = WBT_STATE_INIT;
|
||||||
std::string expr;
|
std::string expr;
|
||||||
auto line = 1;
|
auto [line, column, expr_start_line, expr_start_column] = WBT_Parser_Internal_Data();
|
||||||
auto column = 1;
|
|
||||||
while (input.peek() != std::char_traits<char>::eof()) {
|
while (input.peek() != std::char_traits<char>::eof()) {
|
||||||
char c;
|
char c;
|
||||||
input.get(c);
|
input.get(c);
|
||||||
@@ -47,6 +53,8 @@ public:
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case WBT_STATE_INIT:
|
case WBT_STATE_INIT:
|
||||||
if (c == '{') {
|
if (c == '{') {
|
||||||
|
expr_start_line = line;
|
||||||
|
expr_start_column = column;
|
||||||
state = WBT_STATE_OPEN;
|
state = WBT_STATE_OPEN;
|
||||||
} else {
|
} else {
|
||||||
output_char(c);
|
output_char(c);
|
||||||
@@ -89,5 +97,9 @@ public:
|
|||||||
column++;
|
column++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Final state cannot be WBT_STATE_EXPRESSION
|
||||||
|
if (state == WBT_STATE_EXPRESSION) {
|
||||||
|
error("Unclosed expression", expr_start_line, expr_start_column);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user