Skip to content

Commit

Permalink
adding a #parserClass method for nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brant committed May 10, 2019
1 parent d8c77d5 commit 77069bf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/SmaCC_Runtime/SmaCCParseNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ SmaCCParseNode class >> collectionVariableIn: aSmaCCParseNode collectionGetter:
^ #()
]

{ #category : #accessing }
SmaCCParseNode class >> parserClass [
"Return the parser class that likely created this node"

| possibleClasses classNames topNodeClass |
self == SmaCCParseNode
ifTrue: [ ^ nil ].
topNodeClass := self withAllSuperclasses
detect: [ :each | each superclass = SmaCCParseNode ].
classNames := (topNodeClass withAllSubclasses collect: #name) asSet.
possibleClasses := SmaCCParser withAllSubclasses
select: [ :each |
(each class includesSelector: #symbolTypes)
and: [ each symbolTypes
anySatisfy: [ :clsName | classNames includes: clsName ] ] ].
possibleClasses size = 1
ifTrue: [ ^ possibleClasses first ].
^ nil
]

{ #category : #accessing }
SmaCCParseNode class >> variableIn: aSmaCCParseNode getter: aSymbol [
(aSmaCCParseNode respondsTo: aSymbol)
Expand Down Expand Up @@ -689,6 +709,11 @@ SmaCCParseNode >> parentOfType: aSmaCCParseNodeClassOrCollection [
ifFalse: [ nil ]
]

{ #category : #accessing }
SmaCCParseNode >> parserClass [
^ self class parserClass
]

{ #category : #copying }
SmaCCParseNode >> postCopy [
super postCopy.
Expand Down

0 comments on commit 77069bf

Please sign in to comment.