PPChoiceParser.st
changeset 0 739fe9b7253e
child 4 90de244a7fa2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PPChoiceParser.st	Thu Aug 18 20:56:17 2011 +0200
@@ -0,0 +1,38 @@
+"{ Package: 'squeak:petitparser' }"
+
+PPListParser subclass:#PPChoiceParser
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'PetitParser-Parsers'
+!
+
+PPChoiceParser comment:'A parser that uses the first parser that succeeds.'
+!
+
+
+!PPChoiceParser methodsFor:'operations'!
+
+/ aRule 
+	^ self copyWith: aRule
+! !
+
+!PPChoiceParser methodsFor:'parsing'!
+
+parseOn: aStream
+	"This is optimized code that avoids unnecessary block activations, do not change. When all choices fail, the last failure is answered."
+
+	| element |
+	1 to: parsers size do: [ :index |
+		element := (parsers at: index)
+			parseOn: aStream.
+		element isPetitFailure
+			ifFalse: [ ^ element ] ].
+	^ element
+! !
+
+!PPChoiceParser class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id: PPChoiceParser.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
+! !