|
101 | 101 | import com.oracle.graal.python.nodes.subscript.SliceLiteralNode; |
102 | 102 | import com.oracle.graal.python.parser.ScopeInfo.ScopeKind; |
103 | 103 | import com.oracle.graal.python.runtime.PythonParser; |
104 | | -import static com.oracle.graal.python.runtime.exception.PythonErrorType.SyntaxError; |
105 | 104 | import com.oracle.truffle.api.RootCallTarget; |
106 | 105 | import com.oracle.truffle.api.Truffle; |
107 | 106 | import com.oracle.truffle.api.frame.FrameDescriptor; |
@@ -250,7 +249,7 @@ public PNode visit(AssignmentSSTNode node) { |
250 | 249 | public PNode visit(AugAssignmentSSTNode node) { |
251 | 250 | ExpressionNode lhs = (ExpressionNode) node.lhs.accept(this); |
252 | 251 | if (!(lhs instanceof ReadNode)) { |
253 | | - throw errors.raise(SyntaxError, "illegal expression for augmented assignment"); |
| 252 | + throw errors.raiseInvalidSyntax(source, createSourceSection(node.startOffset, node.endOffset), "illegal expression for augmented assignment"); |
254 | 253 | } |
255 | 254 | ExpressionNode rhs = (ExpressionNode) node.rhs.accept(this); |
256 | 255 | ExpressionNode binOp = nodeFactory.createInplaceOperation(node.operation, lhs, rhs); |
@@ -625,15 +624,15 @@ public PNode visit(ForSSTNode node) { |
625 | 624 | target = targets[0]; |
626 | 625 | if (!(target instanceof ReadNode || target instanceof TupleLiteralNode || target instanceof ListLiteralNode)) { |
627 | 626 | if (target instanceof StarredExpressionNode) { |
628 | | - throw errors.raise(SyntaxError, "starred assignment target must be in a list or tuple"); |
| 627 | + throw errors.raiseInvalidSyntax(source, createSourceSection(node.startOffset, node.endOffset), "starred assignment target must be in a list or tuple"); |
629 | 628 | } else { |
630 | 629 | // TODO handle this??? |
631 | 630 | // String text = ctx.getText(); |
632 | 631 | // if (environment.isNonlocal(text)) { |
633 | 632 | // throw errors.raise(SyntaxError, "no binding for nonlocal variable \"%s\" |
634 | 633 | // found", text); |
635 | 634 | // } |
636 | | - throw errors.raise(SyntaxError, "Cannot assign to %s", target); |
| 635 | + throw errors.raiseInvalidSyntax(source, createSourceSection(node.startOffset, node.endOffset), "Cannot assign to %s", target); |
637 | 636 | } |
638 | 637 | } |
639 | 638 | } else { |
@@ -1101,9 +1100,9 @@ public PNode visit(VarLookupSSTNode node) { |
1101 | 1100 | PNode result = (PNode) scopeEnvironment.findVariable(node.name); |
1102 | 1101 | if (result == null) { |
1103 | 1102 | if (scopeEnvironment.isNonlocal(node.name)) { |
1104 | | - throw errors.raise(SyntaxError, "no binding for nonlocal variable \"%s\" found", node.name); |
| 1103 | + throw errors.raiseInvalidSyntax(source, createSourceSection(node.startOffset, node.endOffset), "no binding for nonlocal variable \"%s\" found", node.name); |
1105 | 1104 | } |
1106 | | - throw errors.raise(SyntaxError, "Cannot assign to %s", node.name); |
| 1105 | + throw errors.raiseInvalidSyntax(source, createSourceSection(node.startOffset, node.endOffset), "Cannot assign to %s", node.name); |
1107 | 1106 | } |
1108 | 1107 | result.assignSourceSection(createSourceSection(node.startOffset, node.endOffset)); |
1109 | 1108 | // scopeEnvironment.setCurrentScope(oldScope); |
@@ -1213,7 +1212,11 @@ private StatementNode createDestructuringAssignment(ExpressionNode[] leftHandSid |
1213 | 1212 | temps[i] = tempRead; |
1214 | 1213 | if (leftHandSides[i] instanceof StarredExpressionNode) { |
1215 | 1214 | if (starredIndex != -1) { |
1216 | | - throw errors.raise(SyntaxError, "two starred expressions in assignment"); |
| 1215 | + SourceSection section = leftHandSides[0].getSourceSection(); |
| 1216 | + if (section == null) { |
| 1217 | + section = ((StarredExpressionNode) leftHandSides[i]).getValue().getSourceSection(); |
| 1218 | + } |
| 1219 | + throw errors.raiseInvalidSyntax(source, section, "two starred expressions in assignment"); |
1217 | 1220 | } |
1218 | 1221 | starredIndex = i; |
1219 | 1222 | statements[i] = createAssignment(((StarredExpressionNode) leftHandSides[i]).getValue(), (ExpressionNode) tempRead); |
|
0 commit comments