Skip to content

Commit

Permalink
all test green with ast nodes :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Sep 20, 2019
1 parent 52fc92e commit 26c61eb
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
36 changes: 33 additions & 3 deletions src/ClassParser-Tests/CDSlotParserArgumentingSlotTest.class.st
Expand Up @@ -25,7 +25,7 @@ CDSlotParserArgumentingSlotTest >> classDefinitionString [
^ '{superclassname} subclass: #{classname}
slots: \{
''{instvar1}'' => (LazyClassVariable default: 5).
''{instvar2}'' => (ObservableSlot default: 5).
''{instvar2}'' => (ObservableSlot default: true extras: (1 + 4)).
\}
classVariableNames: ''{classvar1} {classvar2}''
package: #MyPackage'
Expand All @@ -43,12 +43,42 @@ CDSlotParserArgumentingSlotTest >> testClassDefWithInitializationSlot [
self
assert: classDefinition slotNodes first name
equals: self firstInstanceVariableName.

self
assert: classDefinition slotNodes first slotClassName
equals: #LazyClassVariable.

self
assert: classDefinition slotNodes first initializationMessage printString
equals: 'default: ''5'''.
assert: classDefinition slotNodes first initializationMessage selectorParts
equals: #(default:).

self assert: classDefinition slotNodes first initializationMessage argumentParts isCollection.
self
assert: (classDefinition slotNodes first initializationMessage argumentParts first isKindOf: RBLiteralValueNode)



]

{ #category : #tests }
CDSlotParserArgumentingSlotTest >> testClassDefWithInitializationSlot2 [
self
assert: classDefinition slotNodes second name
equals: self secondInstanceVariableName.

self
assert: classDefinition slotNodes second slotClassName
equals: #ObservableSlot.

self
assert: classDefinition slotNodes second initializationMessage selectorParts
equals: #(default: extras:).

self assert: classDefinition slotNodes second initializationMessage argumentParts isCollection.
self
assert: (classDefinition slotNodes second initializationMessage argumentParts first isKindOf: RBLiteralValueNode).
self
assert: classDefinition slotNodes second initializationMessage argumentParts first value equals: true.
self
assert: (classDefinition slotNodes second initializationMessage argumentParts second isKindOf: RBMessageNode)
]
6 changes: 3 additions & 3 deletions src/ClassParser/CDClassDefinitionParser.class.st
Expand Up @@ -189,7 +189,7 @@ CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
node: aRBMessageNode
name: aRBMessageNode value
slotClassName: #InstanceVariableSlot
initializationMessage: (self slotInitializationNodeClass new)
initializationMessage: self slotInitializationNodeClass new
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
Expand All @@ -207,7 +207,7 @@ CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
node: aRBMessageNode
name: aRBMessageNode receiver value
slotClassName: aRBMessageNode arguments first name
initializationMessage: (self slotInitializationNodeClass new)
initializationMessage: self slotInitializationNodeClass new
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
Expand All @@ -227,7 +227,7 @@ CDClassDefinitionParser >> parseSlotNode: aRBMessageNode [
initializationMessage:
(self slotInitializationNodeClass
selectorParts: aRBMessageNode arguments first selectorParts
argumentParts: aRBMessageNode arguments first argumentPartStrings)
argumentParts: aRBMessageNode arguments first arguments)
start: aRBMessageNode start
stop: aRBMessageNode stop.
classDefinition addSlot: slot.
Expand Down
6 changes: 6 additions & 0 deletions src/ClassParser/CDNode.class.st
Expand Up @@ -25,6 +25,12 @@ CDNode class >> on: aRBMessageNode [
yourself
]

{ #category : #visitor }
CDNode >> acceptVisitor: aProgramNodeVisitor [

self subclassResponsibility
]

{ #category : #accessing }
CDNode >> addChild: aChild [

Expand Down
1 change: 0 additions & 1 deletion src/ClassParser/CDSlotNode.class.st
Expand Up @@ -2,7 +2,6 @@ Class {
#name : #CDSlotNode,
#superclass : #CDNode,
#instVars : [
'slot',
'node',
'index',
'start',
Expand Down
17 changes: 7 additions & 10 deletions src/ClassParser/RBSlotInitializationNode.class.st
@@ -1,9 +1,12 @@
"
I represent the Slot initialization part of a slot definition.
I'm not super well integrated in the language AST because I'm a transformation from the AST.
For example for this expression 'first' => LazyClassVariable default: 5, I represent
I'm a transformation from the AST.
For example for this expression 'first' => (LazyClassVariable default: 5), I represent
the default: 5 part.
Still I support visiting protocol in case.
Slot initialization node works for the three slot forms below.
To make sure that all slot definition are polymorphic, all slots have a initializationNode (some acting as null node).
Object subclass: #MyClass
slots: {
Expand All @@ -14,15 +17,9 @@ Object subclass: #MyClass
classVariableNames: ''
package: #MyPackage'
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')
In this case the argument parts is a RBMessageNode.
Expand Down

0 comments on commit 26c61eb

Please sign in to comment.