PetitCommonMark/software/petitcompiler/PPCTokenVisitor.class.st

67 lines
1.4 KiB
Smalltalk

"
I do updates in tokens. My goal is to remove tokens inside tokens.
If I could, I would be private class of PPCTokendDetector.
"
Class {
#name : 'PPCTokenVisitor',
#superclass : 'PPCRewritingVisitor',
#category : 'PetitCompiler-Visitors'
}
{ #category : 'traversing' }
PPCTokenVisitor >> afterAccept: node retval: retval [
(retval name isNil not and: [ (retval name endsWith: '_ws') ]) ifTrue: [
| newRetval |
newRetval := PPCTokenWhitespaceNode new
child: retval;
yourself.
^ super afterAccept: node retval: newRetval.
].
^ super afterAccept: node retval: retval
]
{ #category : 'as yet unclassified' }
PPCTokenVisitor >> visitActionNode: node [
(node isMarkedAsTrimmingToken) ifTrue: [
| child newChild |
"trimming token in token, remove it"
child := node child secondChild.
newChild := self visit: child.
child name isNil ifTrue: [
newChild name: node name.
^ newChild.
].
^ PPCForwardNode new
child: newChild;
name: node name;
yourself
].
"remove the action from token, they are not allowed there"
super visitActionNode: node.
^ node child
]
{ #category : 'as yet unclassified' }
PPCTokenVisitor >> visitTokenNode: node [
"token in token, remove the token"
| newNode |
node child name isNil ifTrue: [
node child name: node name.
^ super visit: node child
].
newNode := PPCForwardNode new
child: node child;
name: node name;
yourself.
^ super visit: newNode
]