Skip to content

Commit

Permalink
all tests green but I'm happy with the solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Sep 20, 2019
1 parent 59928e4 commit 52fc92e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
17 changes: 16 additions & 1 deletion src/ClassParser-Tests/CDSlotParserArgumentingSlotTest.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"
A slot definition can be composed as follows:
{
#x .
#x => Observable .
#x => (Observable keyword: literal message: literal2)
}
This test is about the second case.
However I'm not really happy about the representation of literal in the RBSlotInitializationNode class.
Indeed I currently store '5' as argument of keyword: 5 and probably 'true' for keyword: true
and it will force the visitors to rescan.
"
Class {
#name : #CDSlotParserArgumentingSlotTest,
#superclass : #CDClassDefinitionParserTest,
Expand Down Expand Up @@ -33,7 +48,7 @@ CDSlotParserArgumentingSlotTest >> testClassDefWithInitializationSlot [
equals: #LazyClassVariable.
self
assert: classDefinition slotNodes first initializationMessage printString
equals: 'default: 5'.
equals: 'default: ''5'''.


]
4 changes: 2 additions & 2 deletions src/ClassParser-Tests/RBSlotInitializationNodeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RBSlotInitializationNodeTest >> testSelector [
RBSlotInitializationNodeTest >> testSlotInitializationCreation [

| s |
s := RBSlotInitializationNode selectorParts: #(#default:) arguments: #(5).
s := RBSlotInitializationNode selectorParts: #(#default:) argumentParts: #(5).
self assert: s selectorString equals: #default:.
self assert: s argumentParts equals: #(5)
]
Expand All @@ -64,7 +64,7 @@ RBSlotInitializationNodeTest >> testSlotInitializationCreation [
RBSlotInitializationNodeTest >> testSlotMultipleInitializationCreation [

| s |
s := RBSlotInitializationNode selectorParts: #(default: named:) arguments: #(5 'titi').
s := RBSlotInitializationNode selectorParts: #(default: named:) argumentParts: #(5 'titi').
self assert: s selectorParts equals: #(default: named:).
self assert: s selectorString equals: 'default:named:'.
self assert: s argumentParts equals: #(5 'titi')
Expand Down
7 changes: 3 additions & 4 deletions src/ClassParser/CDClassDefinitionParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,18 @@ CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
#x => 2"
]
ifTrue: [
"when a slot is just 'inst' => (InstanceVariableSlot default: 5)."

"when a slot is 'inst' => (InstanceVariableSlot default: 5)."
| slot slotDefNode |
slotDefNode := aRBMessageNode.
self halt.
slot := self slotNodeClass
node: aRBMessageNode
name: slotDefNode receiver value
slotClassName: slotDefNode arguments first receiver name
initializationMessage:
(self slotInitializationNodeClass
selector: aRBMessageNode arguments first selector
argument: (aRBMessageNode arguments first argumentPartStrings))
selectorParts: aRBMessageNode arguments first selectorParts
argumentParts: aRBMessageNode arguments first argumentPartStrings)
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
Expand Down
18 changes: 8 additions & 10 deletions src/ClassParser/RBSlotInitializationNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ In addition, to make sure that all slot definition are polymorphic
start and end are not managed for the moment at my level.
argumentParts holds a collection of strings since we can have
'first' => LazyClassVariable default: x + 3
In this case the argument part is #('x + 3')
Expand All @@ -33,15 +39,7 @@ Class {
}

{ #category : #'instance creation' }
RBSlotInitializationNode class >> selector: aSelector arguments: aCollection [
^ self new
selector: aSelector;
argument: aCollection;
yourself
]

{ #category : #'instance creation' }
RBSlotInitializationNode class >> selectorParts: selectors arguments: aCollection [
RBSlotInitializationNode class >> selectorParts: selectors argumentParts: aCollection [
^ self new
selectorParts: selectors;
argumentParts: aCollection;
Expand Down Expand Up @@ -102,7 +100,7 @@ RBSlotInitializationNode >> printOn: aStream [
aStream
<< each asString ;
<< ' ';
print: (argumentParts at: i).
<< (argumentParts at: i) printString.
i = size ifFalse: [ aStream << ' ']]]
]

Expand Down

0 comments on commit 52fc92e

Please sign in to comment.