Skip to content

Commit

Permalink
Issue #465: more progress testMethodDef_PASSING has the passing cases…
Browse files Browse the repository at this point in the history
… from testMethodDef ... methodBody logic needs work ...

12 run, 11 passed, 1 failures, 0 errors
  • Loading branch information
dalehenrich committed Jul 24, 2019
1 parent c183765 commit ea07ad6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 21 deletions.
55 changes: 50 additions & 5 deletions rowan/src/AST-Core/RBParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -720,16 +720,38 @@ 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]
^ currentToken isIdentifier
ifTrue: [ self parseTonelUnaryPattern]
ifFalse:
[currentToken isKeyword
ifTrue: [self parseKeywordPattern]
ifFalse: [self parseTonelBinaryPattern]]
ifTrue: [self parseTonelKeywordPattern]
ifFalse: [self parseTonelBinaryPattern] ]
]

{ #category : 'private-parsing' }
Expand All @@ -748,6 +770,17 @@ RBParser >> parseTonelPragmas [
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 |
Expand Down Expand Up @@ -824,10 +857,16 @@ RBParser >> parseTonelUnaryPattern [

| selector |
selector := currentToken.
self tonelStep.
^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 @@ -958,6 +997,12 @@ 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
8 changes: 7 additions & 1 deletion rowan/src/AST-Core/RBScanner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ 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 @@ -539,7 +545,7 @@ RBScanner >> tonelNext [
| token |
(characterType == #special and: [currentCharacter = $[ ])
ifFalse: [
characterType ~~ #eof
characterType ~~ #eof
ifTrue: [ self error: 'Cannot parse Tonel method body. Missing ''[''.' ] ].
buffer reset.
tokenStart := stream position.
Expand Down
6 changes: 4 additions & 2 deletions rowan/src/Rowan-Components/NewTonelParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ xStart := stream position.
scanner: (methodParser scannerClass on: stream
errorBlock: [:errorMessage :errorPosition |self halt]).
currentMethodNode := methodParser parseTonelMessagePattern.
end := methodParser scanner stream position.
end := methodParser scanner previousStepPosition.
start := methodBodyStart := methodParser scanner previousStepPosition - 3.
currentPosition := methodParser scanner stream position.
methodParser scanner stream position: xStart.
count := end - xStart + 1.
count := end - xStart.
selector := String new: count.
methodParser scanner stream readInto: selector startingAt: 1 count: count.
methodParser scanner stream position: currentPosition.
selector := selector trimBoth.
type := type trimBoth substrings: ' '.
type size = 1 ifTrue: [ type := type copyWith: nil ].
methodParser tonelStep.

^ {
type.
selector.
Expand Down
29 changes: 16 additions & 13 deletions rowan/src/Rowan-Tests/NewTonelParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ what] is inside'.
NewTonelParserTest >> testMethodDef [
self
assertParse: '
TClass classSide >> template: aSystemCategoryName [
"I really do not care"
]'
rule: #methodDef
equals: (self newMethodDefinitionForClassNamed: #TClass
classIsMeta: true
selector: #template:
category: ''
source: 'template: aSystemCategoryName
"I really do not care"').
]

{ #category : 'tests' }
NewTonelParserTest >> testMethodDef_PASSING [
self
assertParse: '
{ #category: ''accessing'' }
Object>>name [
^ self printString
Expand All @@ -195,19 +211,6 @@ Object class>>name [
category: ''
source: 'name
^ self printString').

self
assertParse: '
TClass classSide >> template: aSystemCategoryName [
"I really do not care"
]'
rule: #methodDef
equals: (self newMethodDefinitionForClassNamed: #TClass
classIsMeta: true
selector: #template:
category: ''
source: 'template: aSystemCategoryName
"I really do not care"').
]

{ #category : 'tests' }
Expand Down

0 comments on commit ea07ad6

Please sign in to comment.