Parsing of code with errors:
In Pharo 11 ends ends up in RBParser>>#parserError:
parserError: aString
"Let the errorBlock try to recover from the error. Answer a ParseNode (possibly an RBParseErrorNode) or signal there is new source"
| errorNode errorMessage errorPosition newSource |
errorNode := self errorBlock cull: aString cull: self errorPosition cull: self.
errorNode ifNotNil: [ ^ errorNode ].
currentToken isError
ifTrue: [ errorMessage := currentToken cause. errorPosition := currentToken location ]
ifFalse: [errorMessage := aString. errorPosition := currentToken start].
newSource := SyntaxErrorNotification
inClass: Object
withCode: source
doitFlag: false
errorMessage: errorMessage
location: errorPosition.
"If the syntax error notification is resumed, then the source was corrected and we have to announce that parsing can restart."
ReparseAfterSourceEditing signalWithNewSource: newSource
and raises a SyntaxErrorNotification
Notification subclass: #SyntaxErrorNotification
instanceVariableNames: 'inClass code doitFlag location'
classVariableNames: ''
package: 'OpalCompiler-Core-Exception'
that can be caught. Resuming from that error raises then ReparseAfterSourceEditing
Notification subclass: #ReparseAfterSourceEditing
instanceVariableNames: 'newSource'
classVariableNames: ''
package: 'OpalCompiler-Core-Exception'
, and that triggers another reparsing.
In Pharo 12 a CodeError
is raised instead from RBNotice>>#signalError
. Parsing does not directly raise an error. Instead the AST is annotated with notices (RBNotice
) and RBProgramNode>>#checkFaulty:
throws a code error if any RBErrorNotice
are detect in any AST node.
The entry point where coder shows parse errors (SyntaxErrorNotification
Notification subclass: #SyntaxErrorNotification
instanceVariableNames: 'inClass code doitFlag location'
classVariableNames: ''
package: 'OpalCompiler-Core-Exception'
/CodeError
) and OCUndeclaredVariableWarning
OCSemanticWarning subclass: #OCUndeclaredVariableWarning
instanceVariableNames: ''
classVariableNames: ''
package: 'OpalCompiler-Core-Exception'
is GtSourceCoder>>#notifyParseError:requesterObject:
notifyParseError: aSemanticWarning requesterObject: aRequester
self
announce: (GtCoderParseError new
coder: self;
exception: aSemanticWarning;
errorMessage: aSemanticWarning messageText;
location: aSemanticWarning location;
requesterObject: aRequester)
RBParser parseMethod: 'ha
+1'
RBParser parseExpression: '+1'