Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix of #7165. #7204

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions src/AST-Core-Tests/RBErrorNodeParserTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Class {
#name : #RBErrorNodeParserTest,
#superclass : #RBParserTest,
#category : #'AST-Core-Tests-Parser'
}

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyBinaryMessageSendArgumentShouldHaveTheCorrectMessage [

| node |
node := self parserClass parseFaultyExpression: '+ arg'.

self assert: node isMessage.
self assert: node receiver isParseError.
self assert: node selector equals: #+.
self assert: node arguments first isVariable.
self assert: node arguments first name equals: #arg.

]

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyBinaryMessageSendWithLiteralArgumentShouldHaveTheCorrectMessage [

| node |
node := self parserClass parseFaultyExpression: '+ 12'.

self assert: node isMessage.
self assert: node receiver isParseError.
self assert: node selector equals: #+.
self assert: node arguments first isLiteralNode.
self assert: node arguments first value equals: 12.

]

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyMessageSendShouldHaveTheCorrectMessage [

| node |
node := self parserClass parseFaultyExpression: 'msg: arg'.

self assert: node isMessage.
self assert: node receiver isParseError.
self assert: node selector equals: #msg:.
self assert: node arguments first isVariable.
self assert: node arguments first name equals: #arg.

]

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyMessageSendWithLiteralArgumentShouldHaveTheCorrectMessage [

| node |
node := self parserClass parseFaultyExpression: 'msg: 12'.

self assert: node isMessage.
self assert: node receiver isParseError.
self assert: node selector equals: #msg:.
self assert: node arguments first isLiteralNode.
self assert: node arguments first value equals: 12.

]

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyMessageSendWithSymbolsArgumentShouldHaveTheCorrectMessage [

| node |
node := self parserClass parseFaultyExpression: 'msg: #lala: and:12'.

self assert: node isMessage.
self assert: node receiver isParseError.
self assert: node selector equals: #msg:and:.

self assert: node arguments first isLiteralNode.
self assert: node arguments first value equals: #lala:.

self assert: node arguments second isLiteralNode.
self assert: node arguments second value equals: 12.

]

{ #category : #tests }
RBErrorNodeParserTest >> testFaultyMethodHasAnErrorNodeAndContinueParsing [

| node |
node := self parserClass parseFaultyMethod: '1 between: 2 and: 3'.

self assert: node isMethod.
self assert: node selector equals: #faulty.

self assert: node body statements first isParseError.

self assert: node body statements second isMessage.
self assert: node body statements second selector equals: #between:and:.

]
2 changes: 1 addition & 1 deletion src/AST-Core-Tests/RBParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ RBParserTest >> testParserErrors [
RBParserTest >> testParserErrorsWithErrorBlock [
"Parse source with errors and ensure we identify them"
#(#('self foo. + 3' 2) #('self 0' 1) #('self asdf;;asfd' 1))
#(#('self foo. + 3' 1) #('self 0' 1) #('self asdf;;asfd' 1))
do: [:each | |ast errorCount|
[ ast := self parseError: each first onError:
[:msg :pos :parser | parser parseErrorNode: msg]]
Expand Down
18 changes: 13 additions & 5 deletions src/AST-Core/RBParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ RBParser >> parseBinaryMessageWith: aNode [
RBParser >> parseBinaryPattern [
| binaryToken node args |
currentToken isBinary
ifFalse: [ ^ self parserError: 'Message pattern expected'].
ifFalse: [
^ self methodNodeClass
selector: #faulty
arguments: #()
body: (self sequenceNodeClass statements: (OrderedCollection with: (self parserError: 'Message pattern expected')))].

binaryToken := currentToken.
self step.
args := Array with: self parseVariableNode.
Expand Down Expand Up @@ -698,9 +703,12 @@ RBParser >> parseMethod [
self parsePragmas.
self addCommentsTo: methodNode.

sequenceNode:= self sequenceNodeClass new.
(self parseStatements: true into: sequenceNode).
methodNode body: sequenceNode .
methodNode body ifNil: [
sequenceNode := self sequenceNodeClass new.
methodNode body: sequenceNode ].

(self parseStatements: true into: methodNode body).

pragmas ifNotNil: [ methodNode pragmas: pragmas ].
^methodNode
]
Expand Down Expand Up @@ -835,7 +843,7 @@ RBParser >> parsePrimitiveObject [
currentToken value = $( ifTrue: [^self parseParenthesizedExpression].
currentToken value = ${ ifTrue: [^self parseArray]].
errorNode := self parserError: 'Variable or expression expected'.
self step.
errorNode isParseError ifFalse: [ self step ].
^errorNode.
]

Expand Down
12 changes: 12 additions & 0 deletions src/Rubric/RubSmalltalkCommentMode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ RubSmalltalkCommentMode >> formatMethodCode [
RubSmalltalkCommentMode >> isCompletionEnabled [
^ false
]

{ #category : #parsing }
RubSmalltalkCommentMode >> parseExpression: aString [

^ RBParser parseFaultyExpression: aString
]

{ #category : #parsing }
RubSmalltalkCommentMode >> parseSource: aString [

^ RBParser parseFaultyExpression: aString
]