PPPluggableParser.st
changeset 0 739fe9b7253e
child 4 90de244a7fa2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PPPluggableParser.st	Thu Aug 18 20:56:17 2011 +0200
@@ -0,0 +1,52 @@
+"{ Package: 'squeak:petitparser' }"
+
+PPParser subclass:#PPPluggableParser
+	instanceVariableNames:'block'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitParser-Parsers'
+!
+
+PPPluggableParser comment:'A pluggable parser that passes the parser stream into a block. This enables users to perform manual parsing or to embed other parser frameworks into PetitParser.
+Instance Variables:
+	block	<BlockClosure>	The pluggable one-argument block.
+'
+!
+
+
+!PPPluggableParser class methodsFor:'instance creation'!
+
+on: aBlock
+	^ self new initializeOn: aBlock
+! !
+
+!PPPluggableParser methodsFor:'accessing'!
+
+block
+	"Answer the pluggable block."
+
+	^ block
+! !
+
+!PPPluggableParser methodsFor:'initialization'!
+
+initializeOn: aBlock
+	block := aBlock
+! !
+
+!PPPluggableParser methodsFor:'parsing'!
+
+parseOn: aStream
+	| position result |
+	position := aStream position.
+	result := block value: aStream.
+	result isPetitFailure
+		ifTrue: [ aStream position: position ].
+	^ result
+! !
+
+!PPPluggableParser class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id: PPPluggableParser.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
+! !