feat: unclosed expression test added and fulfilled
This commit is contained in:
+15
-3
@@ -5,13 +5,20 @@ module;
|
||||
// This module is the transpiler from WBT to HTML for site build
|
||||
export module wbt;
|
||||
|
||||
export enum WBT_States {
|
||||
enum WBT_States {
|
||||
WBT_STATE_INIT,
|
||||
WBT_STATE_OPEN,
|
||||
WBT_STATE_EXPRESSION,
|
||||
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 {
|
||||
std::istream& input;
|
||||
std::ostream& output;
|
||||
@@ -38,8 +45,7 @@ public:
|
||||
void parse() const {
|
||||
auto state = WBT_STATE_INIT;
|
||||
std::string expr;
|
||||
auto line = 1;
|
||||
auto column = 1;
|
||||
auto [line, column, expr_start_line, expr_start_column] = WBT_Parser_Internal_Data();
|
||||
while (input.peek() != std::char_traits<char>::eof()) {
|
||||
char c;
|
||||
input.get(c);
|
||||
@@ -47,6 +53,8 @@ public:
|
||||
switch (state) {
|
||||
case WBT_STATE_INIT:
|
||||
if (c == '{') {
|
||||
expr_start_line = line;
|
||||
expr_start_column = column;
|
||||
state = WBT_STATE_OPEN;
|
||||
} else {
|
||||
output_char(c);
|
||||
@@ -89,5 +97,9 @@ public:
|
||||
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