Skip to content

Commit

Permalink
Remove argument from parseExpression: and parseMethod: in Parser to s…
Browse files Browse the repository at this point in the history
…imply use #source variable instead.
  • Loading branch information
dionisiydk committed May 14, 2021
1 parent 6e3dced commit b88e7f8
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/AST-Core/RBParser.class.st
Expand Up @@ -58,7 +58,7 @@ RBParser class >> parseExpression: aString onError: aBlock [
node := self new
errorBlock: aBlock;
initializeParserWith: aString;
parseExpression: aString.
parseExpression.
^ (node statements size == 1 and: [ node temporaries isEmpty ])
ifTrue: [ node statements first ]
ifFalse: [ node ]
Expand Down Expand Up @@ -95,7 +95,7 @@ RBParser class >> parseMethod: aString onError: aBlock [
parser := self new
errorBlock: aBlock;
initializeParserWith: aString.
^ [ parser parseMethod: aString ]
^ [ parser parseMethod ]
on: ReparseAfterSourceEditing
do: [ :exception | self parseMethod: exception newSource onError: aBlock ]
]
Expand Down Expand Up @@ -185,6 +185,11 @@ RBParser >> basicParsePragma [
ifFalse: [ self parseBinaryPragma ] ]
]

{ #category : #initialization }
RBParser >> beFaulty [
errorBlock := self class errorNodeBlock
]

{ #category : #'private-classes' }
RBParser >> blockNodeClass [
^ RBBlockNode
Expand Down Expand Up @@ -545,13 +550,12 @@ RBParser >> parseErrorNode: aMessageString [
^ RBParseErrorNode errorMessage: aMessageString value: currentToken value asString at: errorPosition
]

{ #category : #accessing }
RBParser >> parseExpression: anExpressionString [
{ #category : #parsing }
RBParser >> parseExpression [
"Parse and return an AST corresponding to the expression passed as argument."

| node |
node := self parseStatements: false.
(self methodNodeClass selector: #noMethod body: node) source: anExpressionString. "Make the sequence node have a method node as its parent"
(self methodNodeClass selector: #noMethod body: node) source: source. "Make the sequence node have a method node as its parent"
self atEnd ifFalse: [ ^ self parseIncompleteExpression: node ].
(node statements isEmpty and: [currentToken comments notNil])
ifTrue: [self extractCommentsFrom: currentToken. self addCommentsTo: node.].
Expand Down Expand Up @@ -715,7 +719,7 @@ RBParser >> parseLiteralByteArrayObject [
^self parsePrimitiveLiteral
]

{ #category : #accessing }
{ #category : #'private-parsing' }
RBParser >> parseLiterals: aString [
| stream |
stream := (Array new: 5) writeStream.
Expand All @@ -736,7 +740,7 @@ RBParser >> parseMessagePattern [
ifFalse: [self parseBinaryPattern]]
]

{ #category : #'private-parsing' }
{ #category : #parsing }
RBParser >> parseMethod [
| methodNode sequenceNode |
methodNode := self parseMessagePattern.
Expand All @@ -750,21 +754,10 @@ RBParser >> parseMethod [
self parseStatements: true into: methodNode body untilAnyCloserOf: #().

pragmas ifNotNil: [ methodNode pragmas: pragmas ].
^methodNode
]

{ #category : #accessing }
RBParser >> parseMethod: aMethodDefinitionString [
"Parse and return a abstract syntax tree from the argument"

| node |
node := self parseMethod.
node source: aMethodDefinitionString.
self atEnd
ifFalse: [
^ self parseIncompleteExpression: node body ].
node source: aMethodDefinitionString.
^ node
methodNode source: source.
self atEnd ifFalse: [ ^ self parseIncompleteExpression: methodNode body ].
methodNode source: source.
^ methodNode
]

{ #category : #'private-parsing' }
Expand Down Expand Up @@ -1220,7 +1213,10 @@ RBParser >> parseUnaryPattern [
| selector |
selector := currentToken.
self step.
^self methodNodeClass selector: selector value asSymbol keywordsPositions: (Array with: selector start) arguments: #()
^self methodNodeClass
selector: selector value asSymbol
keywordsPositions: (Array with: selector start)
arguments: #()
]

{ #category : #'private-parsing' }
Expand Down

0 comments on commit b88e7f8

Please sign in to comment.