compiler/PPCCompilerTokenRememberStrategy.st
changeset 452 9f4558b3be66
child 464 f6d77fee9811
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/PPCCompilerTokenRememberStrategy.st	Sun May 10 06:28:36 2015 +0100
@@ -0,0 +1,45 @@
+"{ Package: 'stx:goodies/petitparser/compiler' }"
+
+"{ NameSpace: Smalltalk }"
+
+Object subclass:#PPCCompilerTokenRememberStrategy
+	instanceVariableNames:'compiler'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitCompiler-Core'
+!
+
+!PPCCompilerTokenRememberStrategy class methodsFor:'instance creation'!
+
+on: aPPCCompiler
+    ^ self new
+        compiler: aPPCCompiler;
+        yourself
+! !
+
+!PPCCompilerTokenRememberStrategy methodsFor:'accessing'!
+
+compiler: aPPCCompiler
+    compiler := aPPCCompiler 
+! !
+
+!PPCCompilerTokenRememberStrategy methodsFor:'as yet unclassified'!
+
+smartRemember: parser to: variableName 
+    parser isContextFree ifTrue: [ 
+        compiler 	codeAssign: 'context lwRemember.' 
+                    to: variableName.
+    ] ifFalse: [ 
+        compiler codeAssign: 'context remember.'
+                    to: variableName.
+    ]
+!
+
+smartRestore: parser from: mementoName
+    parser isContextFree ifTrue: [ 
+        compiler add: 'context lwRestore: ', mementoName, '.'.
+    ] ifFalse: [ 
+        compiler add: 'context restore: ', mementoName, '.'.
+    ].
+! !
+