Improved error message for invalid instructions

This commit is contained in:
Eduard Urbach 2025-02-13 22:12:57 +01:00
parent aec22b0a7e
commit e4cbb91f61
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 8 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -0,0 +1,5 @@
import sys
main() {
sys.write
}

View File

@ -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\""}},