From e4cbb91f61dd4f3edf1b4314444c17fed0d893cf Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 13 Feb 2025 22:12:57 +0100 Subject: [PATCH] Improved error message for invalid instructions --- src/ast/parseNode.go | 2 +- tests/errors/InvalidInstructionCall.q | 5 +++++ tests/errors_test.go | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/errors/InvalidInstructionCall.q diff --git a/src/ast/parseNode.go b/src/ast/parseNode.go index 93fada4..919566e 100644 --- a/src/ast/parseNode.go +++ b/src/ast/parseNode.go @@ -37,6 +37,6 @@ func parseNode(tokens token.List, source []byte, nodes AST) (Node, error) { return &Call{Expression: expr}, nil default: - return nil, errors.New(&errors.InvalidInstruction{Instruction: expr.Token.Text(source)}, nil, expr.Token.Position) + return nil, errors.New(&errors.InvalidInstruction{Instruction: tokens.Text(source)}, nil, tokens[0].Position) } } diff --git a/tests/errors/InvalidInstructionCall.q b/tests/errors/InvalidInstructionCall.q new file mode 100644 index 0000000..c11371a --- /dev/null +++ b/tests/errors/InvalidInstructionCall.q @@ -0,0 +1,5 @@ +import sys + +main() { + sys.write +} \ No newline at end of file diff --git a/tests/errors_test.go b/tests/errors_test.go index c2b6588..f861d26 100644 --- a/tests/errors_test.go +++ b/tests/errors_test.go @@ -22,7 +22,8 @@ var errs = []struct { {"ExpectedIfBeforeElse2.q", errors.ExpectedIfBeforeElse}, {"ExpectedStructName.q", errors.ExpectedStructName}, {"ExpectedPackageName.q", errors.ExpectedPackageName}, - {"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}}, + {"InvalidInstructionCall.q", &errors.InvalidInstruction{Instruction: "sys.write"}}, + {"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "2+3"}}, {"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}}, {"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}}, {"InvalidInstructionString.q", &errors.InvalidInstruction{Instruction: "\"Hello\""}},