Skip to content

Commit

Permalink
Issue #465: moved Tonel parsing support to separate classes
Browse files Browse the repository at this point in the history
12 run, 11 passed, 1 failures, 0 errors
  • Loading branch information
dalehenrich committed Jul 24, 2019
1 parent 845bf6e commit ea81d29
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 195 deletions.
166 changes: 0 additions & 166 deletions rowan/src/AST-Core/RBParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -720,153 +720,6 @@ RBParser >> parseStatements: pragmaBoolean [
rightBar: rightBar)
]

{ #category : 'private-parsing' }
RBParser >> parseTonelKeywordPattern [
" do not process $[ token .. caller will do the right thing"

| keywords args node continue |
keywords := OrderedCollection new.
args := OrderedCollection new.
continue := true.
[ continue and: [ currentToken isKeyword ] ]
whileTrue:
[keywords add: currentToken.
continue := (self peekTonelFor: #special value: $[) not.
continue ifTrue: [ self step ].
args add: self parseTonelVariableNode].
node := self methodNodeClass
selectorParts: keywords
arguments: args.
node comments: (node comments, args last comments).
args last comments: nil.
^node
]

{ #category : 'private-parsing' }
RBParser >> parseTonelMessagePattern [

currentToken isLiteralToken ifTrue: [self patchTonelLiteralMessage].
^ currentToken isIdentifier
ifTrue: [ self parseTonelUnaryPattern]
ifFalse:
[currentToken isKeyword
ifTrue: [self parseTonelKeywordPattern]
ifFalse: [self parseTonelBinaryPattern] ]
]

{ #category : 'private-parsing' }
RBParser >> parseTonelPragmas [
| pragma start |
[ currentToken isBinary and: [ currentToken value = #< ] ] whileTrue: [
start := currentToken start.
self step.
pragma := self parsePragma.
(currentToken isBinary and: [ currentToken value = #> ])
ifFalse: [ self parserError: '''>'' expected' ].
pragma left: start; right: currentToken start.
pragmas isNil
ifTrue: [ pragmas := OrderedCollection new ].
pragmas addLast: pragma.
self step ]
]

{ #category : 'private-parsing' }
RBParser >> parseTonelPrimitiveIdentifier [
| token node |
token := currentToken.
(self peekTonelFor: #special value: $[)
ifFalse: [ self step ].
node := self variableNodeClass identifierToken: token.
self addCommentsTo: node.
^node
]

{ #category : 'private-parsing' }
RBParser >> parseTonelStatementList: pragmaBoolean into: sequenceNode [
| statements return periods returnPosition node |
return := false.
statements := OrderedCollection new.
periods := OrderedCollection new.
self addCommentsTo: sequenceNode.
pragmaBoolean ifTrue: [self parsePragmas].
[currentToken isSpecial and: [currentToken value = $.]] whileTrue:
[periods add: currentToken start.
self step].
[self atEnd
or: [currentToken isSpecial and: ['])}' includes: currentToken value]]]
whileFalse:
[return ifTrue: [self parserError: 'End of statement list encounted'].
(currentToken isSpecial and: [currentToken value = $^])
ifTrue:
[returnPosition := currentToken start.
self step.
node := self returnNodeClass return: returnPosition
value: self parseAssignment.
statements add: node.
return := true]
ifFalse:
[node := self parseAssignment.
statements add: node].
(currentToken isSpecial and: [currentToken value = $.])
ifTrue:
[periods add: currentToken start.
self step.
self addCommentsTo: node]
ifFalse: [return := true].
[currentToken isSpecial and: [currentToken value = $.]] whileTrue:
[periods add: currentToken start.
self step]].
statements notEmpty ifTrue: [self addCommentsTo: statements last].
sequenceNode
statements: statements;
periods: periods.
^sequenceNode
]

{ #category : 'private-parsing' }
RBParser >> parseTonelStatements: pragmaBoolean [
| args leftBar rightBar |
args := #().
leftBar := rightBar := nil.
currentToken isBinary
ifTrue:
[currentToken value = #|
ifTrue:
[leftBar := currentToken start.
self step.
args := self parseArgs.
(currentToken isBinary and: [currentToken value = #|])
ifFalse: [self parserError: '''|'' expected'].
rightBar := currentToken start.
self step]
ifFalse:
[currentToken value = #'||'
ifTrue:
[rightBar := (leftBar := currentToken start) + 1.
self step]]].
^self parseTonelStatementList: pragmaBoolean
into: (self sequenceNodeClass
leftBar: leftBar
temporaries: args
rightBar: rightBar)
]

{ #category : 'private-parsing' }
RBParser >> parseTonelUnaryPattern [
"only used when parsing the tonel method selector line"

| selector |
selector := currentToken.
^self methodNodeClass selectorParts: (Array with: selector) arguments: #()
]

{ #category : 'private-parsing' }
RBParser >> parseTonelVariableNode [
currentToken isIdentifier
ifFalse: [self parserError: 'Variable name expected'].
^self parseTonelPrimitiveIdentifier
]

{ #category : 'private-parsing' }
RBParser >> parseUnaryMessage [
| node |
Expand Down Expand Up @@ -997,12 +850,6 @@ RBParser >> patchNegativeLiteral [
nextToken start: nextToken start + 1
]

{ #category : 'private-parsing' }
RBParser >> peekTonelFor: characterType value: characterValue [

^ self scanner peekTonelFor: characterType value: characterValue
]

{ #category : 'private-classes' }
RBParser >> pragmaNodeClass [
^ RBPragmaNode
Expand Down Expand Up @@ -1053,19 +900,6 @@ RBParser >> step [
ifFalse: [currentToken := scanner next]
]

{ #category : 'private' }
RBParser >> tonelStep [
"only used when parsing the tonel method selector line"

(currentToken notNil and: [currentToken comments notNil])
ifTrue: [comments addAll: currentToken comments].
nextToken notNil
ifTrue:
[currentToken := nextToken.
nextToken := nil]
ifFalse: [currentToken := scanner tonelNext]
]

{ #category : 'private-classes' }
RBParser >> variableNodeClass [
^ RBVariableNode
Expand Down
28 changes: 0 additions & 28 deletions rowan/src/AST-Core/RBScanner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,6 @@ RBScanner >> on: aStream [
comments := OrderedCollection new
]

{ #category : 'private' }
RBScanner >> peekTonelFor: aCharacterType value: aCharacterValue [

^ currentCharacter = aCharacterValue and: [ characterType = aCharacterType ]
]

{ #category : 'private' }
RBScanner >> previousStepPosition [
^characterType = #eof
Expand Down Expand Up @@ -537,25 +531,3 @@ RBScanner >> stripSeparators [
currentCharacter = $"]
whileTrue: [self stripComment]
]
{ #category : 'accessing' }
RBScanner >> tonelNext [
"only used when parsing the tonel method selector line"
| token |
(characterType == #special and: [currentCharacter = $[ ])
ifFalse: [
characterType ~~ #eof
ifTrue: [ self error: 'Cannot parse Tonel method body. Missing ''[''.' ] ].
buffer reset.
tokenStart := stream position.
token := characterType = #eof
ifTrue:
[RBToken start: tokenStart + 1 "The EOF token should occur after the end of input"]
ifFalse: [self scanToken].
self stripSeparators.
"don't read comments"
false ifTrue: [ token comments: self getComments ].
"skip the $[ and get next token"
^self next
]
Loading

0 comments on commit ea81d29

Please sign in to comment.