Fix stuff

This commit is contained in:
2026-08-01 08:13:47 +10:00
parent f81284fd37
commit 80649d77ae
3 changed files with 14 additions and 6 deletions

View File

@@ -90,7 +90,7 @@ namespace Solstice {
return input[current + ahead]; return input[current + ahead];
} }
std::optional<char> Lexer::consume() { std::optional<char> Lexer::consume() {
if (current + 1 >= input.size()) { if (current >= input.size()) {
return {}; return {};
} }
return input[current++]; return input[current++];

View File

@@ -1,10 +1,19 @@
#include "lexer/lexer.hpp" #include "lexer/lexer.hpp"
#include "parser/parser.hpp" #include "parser/parser.hpp"
#include <iostream>
#include <stdexcept>
int main() { int main() {
Solstice::Lexer lexer{"2 + 2"}; try {
auto lexed = lexer.lex(); Solstice::Lexer lexer{"2 + 2"};
auto lexed = lexer.lex();
Solstice::Parser parser{lexed}; Solstice::Parser parser{lexed};
auto parsed = parser.parse(); auto parsed = parser.parse();
} catch (const std::runtime_error& e) {
std::cout << e.what() << std::endl;
return 1;
}
return 0;
} }

View File

@@ -45,7 +45,6 @@ namespace Solstice {
if (!left.has_value()) { if (!left.has_value()) {
throw std::runtime_error("Expecting expression on left of '+'"); throw std::runtime_error("Expecting expression on left of '+'");
} }
consume(); // be rid of the +
Precedence precedence = getTokenPrecedence(Token(type)); Precedence precedence = getTokenPrecedence(Token(type));
auto right = parseOneNode(precedence); auto right = parseOneNode(precedence);
if (!right.has_value()) { if (!right.has_value()) {