51 lines
771 B
Smalltalk
51 lines
771 B
Smalltalk
|
"
|
||
|
I do print whatever I visit
|
||
|
"
|
||
|
Class {
|
||
|
#name : 'PPCPrintVisitor',
|
||
|
#superclass : 'PPCNodeVisitor',
|
||
|
#instVars : [
|
||
|
'indent'
|
||
|
],
|
||
|
#category : 'PetitCompiler-Visitors'
|
||
|
}
|
||
|
|
||
|
{ #category : 'printing' }
|
||
|
PPCPrintVisitor >> dedent [
|
||
|
indent := indent - 1
|
||
|
]
|
||
|
|
||
|
{ #category : 'printing' }
|
||
|
PPCPrintVisitor >> indent [
|
||
|
^ indent := indent + 1
|
||
|
]
|
||
|
|
||
|
{ #category : 'initialization' }
|
||
|
PPCPrintVisitor >> initialize [
|
||
|
super initialize.
|
||
|
|
||
|
indent := 0.
|
||
|
]
|
||
|
|
||
|
{ #category : 'printing' }
|
||
|
PPCPrintVisitor >> show: string [
|
||
|
indent timesRepeat: [
|
||
|
Transcript show: ' '.
|
||
|
].
|
||
|
|
||
|
Transcript
|
||
|
show: string;
|
||
|
cr.
|
||
|
|
||
|
]
|
||
|
|
||
|
{ #category : 'visiting' }
|
||
|
PPCPrintVisitor >> visitNode: node [
|
||
|
| retval |
|
||
|
self show: node asString.
|
||
|
self indent.
|
||
|
retval := super visitNode: node.
|
||
|
self dedent.
|
||
|
^ retval
|
||
|
]
|