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.

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
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: