fix syntax, add expected to errors
| | |
| | | string name = "VoidScript"; |
| | | |
| | | // Functions |
| | | function $add(int $a, double $b, string $help) { |
| | | function add = (int $a, double $b, string $help) { |
| | | int $result = $a + $b; |
| | | print("The sum is: ", $result, "\n"); |
| | | print("Help: ", $help, "\n"); |
| | |
| | | if (startIt != tokens_.end() && endIt != tokens_.end() && startIt < endIt) { |
| | | filtered_tokens = std::vector<Lexer::Tokens::Token>(startIt + 1, endIt); |
| | | } |
| | | std::string_view input_string = input_str_view_.substr(opening_brace.end_pos, closing_brace.end_pos); |
| | | auto len = closing_brace.start_pos - opening_brace.end_pos; |
| | | std::string_view input_string = input_str_view_.substr(opening_brace.end_pos, len); |
| | | |
| | | current_token_index_ = tokenIndex; |
| | | expect(Lexer::Tokens::Type::PUNCTUATION, "}"); |
| | |
| | | public: |
| | | using BaseException::BaseException; |
| | | |
| | | Exception(const std::string & msg, const Lexer::Tokens::Token & token) { |
| | | Exception(const std::string & msg, const std::string & expected, const Lexer::Tokens::Token & token) { |
| | | rawMessage_ = msg + ": " + token.dump(); |
| | | context_ = |
| | | " at line: " + std::to_string(token.line_number) + ", column: " + std::to_string(token.column_number); |
| | | if (expected.empty() == false) { |
| | | rawMessage_ += " (expected: " + expected + ")"; |
| | | } |
| | | formattedMessage_ = formatMessage(); |
| | | } |
| | | |
| | | Exception(const std::string & msg, int line, int col) { |
| | | rawMessage_ = msg; |
| | | Exception(const std::string & msg, std::string & expected, int line, int col) { |
| | | rawMessage_ = msg; |
| | | if (expected.empty() == false) { |
| | | rawMessage_ += " (expected: " + expected + ")"; |
| | | } |
| | | context_ = " at line: " + std::to_string(line) + ", column: " + std::to_string(col); |
| | | formattedMessage_ = formatMessage(); |
| | | } |
| | |
| | | (current_token_index_ == tokens_.size() - 1 && tokens_.back().type == Lexer::Tokens::Type::END_OF_FILE); |
| | | } |
| | | |
| | | [[noreturn]] void reportError(const std::string & message) { |
| | | [[noreturn]] void reportError(const std::string & message, const std::string expected = "") { |
| | | if (current_token_index_ < tokens_.size()) { |
| | | throw Exception(message, tokens_[current_token_index_]); |
| | | throw Exception(message, expected, tokens_[current_token_index_]); |
| | | } |
| | | int line = tokens_.empty() ? 0 : tokens_.back().line_number; |
| | | int col = tokens_.empty() ? 0 : tokens_.back().column_number; |
| | | throw Exception(message, line, col); |
| | | throw Exception(message, expected, line, col); |
| | | } |
| | | |
| | | // parseStatement (változatlan) |
| | |
| | | <?void |
| | | string $name = "World 😀"; # world test |
| | | string $greeting = "Hello "; |
| | | string $smiley = "😀 = \\U0001F600 = \U0001F600\n"; |
| | |
| | | print("The number2: ", $number2, "\n"); |
| | | |
| | | print("Unicode: \u00E9 \U0001F600, hex: \x41, newline:\nEnd\t",$greeting, $name, "\n\nSmiley test: ", $smiley); |
| | | |
| | | ?> |
| | |
| | | <?void |
| | | |
| | | int $num = 123; |
| | | double $double = 12.3; |
| | | string $variable = "This is a string content with a number: 123"; |