Parsing code with syntax errors

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.

    | ast cm |
    ast := OpalCompiler new
                source: 'method 3+';
                useFaultyForParsing: true;
    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  
		pushLiteralVariable: #error -> anErrorNode asSyntaxErrorNotification;
		send: #signal.

This is in #50044.

Future work: introduce a RuntimeSyntaxError that can be turned off per error and globally.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: