We can parse code with syntax errors: it generates partial ASTs with the faulty
part of the input as a RBParseErrorNode.
Only three methods are needed to allow generating executable methods from such
an AST: the SyntaxErrorNotification
is raised at runtime instead of compile time.
testEvalSimpleMethodWithError
| ast cm |
ast := OpalCompiler new
source: 'method 3+';
useFaultyForParsing: true;
parse.
self assert: ast isMethod.
self assert: ast isFaulty.
cm := ast compiledMethod.
self should: [cm valueWithReceiver: nil arguments: #()] raise:
SyntaxErrorNotification
The syntax error instance is compiled in via a literal variable, in the end the
only thing needed was:
visitParseErrorNode: anErrorNode
methodBuilder
pushLiteralVariable: #error -> anErrorNode
asSyntaxErrorNotification;
send: #signal.
This is in #50044.
Future work: introduce a RuntimeSyntaxError that can be turned off per error
and globally.
Marcus