From e7720e2d9e1319712f85cb0527e17f1251bd7d2c Mon Sep 17 00:00:00 2001 From: Elias Haugsbakk Date: Mon, 21 Sep 2026 14:36:59 +0200 Subject: add position info to semantic and IRgen exceptions --- .../kompilator/parsing/ParserTest.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/test/java/no/eliashaugsbakk/kompilator/parsing') diff --git a/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java b/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java index 0de2b5f..e4d48ec 100644 --- a/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java +++ b/src/test/java/no/eliashaugsbakk/kompilator/parsing/ParserTest.java @@ -12,6 +12,7 @@ import no.eliashaugsbakk.kompilator.parsing.node.Program; import no.eliashaugsbakk.kompilator.parsing.node.expression.FunctionCall; import no.eliashaugsbakk.kompilator.parsing.node.expression.literal.StringLiteral; import no.eliashaugsbakk.kompilator.parsing.node.statement.ExpressionStatement; +import no.eliashaugsbakk.kompilator.tokenization.Position; import no.eliashaugsbakk.kompilator.tokenization.Token; import org.junit.jupiter.api.Test; @@ -20,11 +21,11 @@ class ParserTest { @Test void validSyntaxBuildsCorrectTree() throws ParserException { List tokens = List.of( - new Token(KEYWORD, "skriv", 1, 0), - new Token(LPAREN, "(", 1, 5), - new Token(STRING_LITERAL, "Hello", 1, 6), - new Token(RPAREN, ")", 1, 13), - new Token(SEMICOLON, ";", 1, 14) + new Token(KEYWORD, "skriv", new Position(1, 0)), + new Token(LPAREN, "(", new Position(1, 5)), + new Token(STRING_LITERAL, "Hello", new Position(1, 6)), + new Token(RPAREN, ")", new Position(1, 13)), + new Token(SEMICOLON, ";", new Position(1, 14)) ); AST ast = new Parser(tokens).parse(); @@ -47,10 +48,10 @@ class ParserTest { @Test void missingSemicolonThrows() { List tokens = List.of( - new Token(KEYWORD, "print", 1, 0), - new Token(LPAREN, "(", 1, 5), - new Token(STRING_LITERAL, "Hello", 1, 6), - new Token(RPAREN, ")", 1, 13) + new Token(KEYWORD, "print", new Position(1, 0)), + new Token(LPAREN, "(", new Position(1, 5)), + new Token(STRING_LITERAL, "Hello", new Position(1, 6)), + new Token(RPAREN, ")", new Position(1, 13)) ); assertThrows(ParserException.class, () -> new Parser(tokens).parse()); @@ -59,10 +60,10 @@ class ParserTest { @Test void missingParenthesisThrows() { List tokens = List.of( - new Token(KEYWORD, "print", 1, 0), - new Token(STRING_LITERAL, "Hello", 1, 5), - new Token(RPAREN, ")", 1, 12), - new Token(SEMICOLON, ";", 1, 13) + new Token(KEYWORD, "print", new Position(1, 0)), + new Token(STRING_LITERAL, "Hello", new Position(1, 5)), + new Token(RPAREN, ")", new Position(1, 12)), + new Token(SEMICOLON, ";", new Position(1, 13)) ); assertThrows(ParserException.class, () -> new Parser(tokens).parse()); -- cgit v1.2.3