95 lines
2.1 KiB
Smalltalk
95 lines
2.1 KiB
Smalltalk
"
|
|
I can find tokens and I start PPCTokenVisitor, when I see a token.
|
|
"
|
|
Class {
|
|
#name : 'PPCTokenDetector',
|
|
#superclass : 'PPCRewritingVisitor',
|
|
#category : 'PetitCompiler-Visitors'
|
|
}
|
|
|
|
{ #category : 'as yet unclassified' }
|
|
PPCTokenDetector >> visitActionNode: node [
|
|
(node isMarkedAsTrimmingToken) ifTrue: [
|
|
| newNode child whitespace |
|
|
child := self visitWithTokenVisitor: node child secondChild.
|
|
whitespace := self visitWithTokenVisitor: node child firstChild.
|
|
|
|
newNode := PPCTrimmingTokenNode new
|
|
name: node name;
|
|
child: child;
|
|
whitespace: whitespace;
|
|
tokenClass: node child secondChild tokenClass;
|
|
properties: node properties copy;
|
|
yourself.
|
|
|
|
self cache: node value: newNode.
|
|
^ super visitActionNode: newNode
|
|
].
|
|
|
|
^ super visitActionNode: node
|
|
|
|
]
|
|
|
|
{ #category : 'as yet unclassified' }
|
|
PPCTokenDetector >> visitTokenNode: node [
|
|
| child newChild |
|
|
|
|
child := node child.
|
|
|
|
newChild := self visitWithTokenVisitor: node child.
|
|
self cache: node child value: newChild ifPresent: [ :e | self assert: newChild == e ].
|
|
|
|
^ super visitTokenNode: node
|
|
]
|
|
|
|
{ #category : 'as yet unclassified' }
|
|
PPCTokenDetector >> visitTokenOLNode: node [
|
|
^ self visitTokenNode: node
|
|
]
|
|
|
|
{ #category : 'as yet unclassified' }
|
|
PPCTokenDetector >> visitTrimNode: node [
|
|
(node child class = PPCTokenNode) ifTrue: [
|
|
| newNode |
|
|
newNode := PPCTrimmingTokenNode new
|
|
name: node name;
|
|
child: node child child;
|
|
tokenClass: node child tokenClass;
|
|
whitespace: node trimmer;
|
|
parser: node parser;
|
|
yourself.
|
|
|
|
self cache: node value: newNode.
|
|
^ super visitTrimNode: newNode.
|
|
].
|
|
|
|
^ super visitTrimNode: node
|
|
|
|
|
|
]
|
|
|
|
{ #category : 'as yet unclassified' }
|
|
PPCTokenDetector >> visitWithTokenVisitor: node [
|
|
| copy retval forbiddenNodes copyVisitor tokenVisitor |
|
|
|
|
"Do not modify the token structure"
|
|
(context options specialize) ifFalse: [
|
|
^ node
|
|
].
|
|
|
|
(self isCached: node) ifTrue: [
|
|
^ self cachedValue: node
|
|
].
|
|
|
|
copyVisitor := PPCCopyVisitor new.
|
|
tokenVisitor := PPCTokenVisitor new.
|
|
|
|
forbiddenNodes := openSet copy.
|
|
copyVisitor forbiddenSet: openSet copy.
|
|
|
|
copy := copyVisitor visit: node.
|
|
retval := tokenVisitor visit: copy.
|
|
^ retval
|
|
|
|
]
|