PPChoiceParser.st
changeset 0 739fe9b7253e
child 4 90de244a7fa2
equal deleted inserted replaced
-1:000000000000 0:739fe9b7253e
       
     1 "{ Package: 'squeak:petitparser' }"
       
     2 
       
     3 PPListParser subclass:#PPChoiceParser
       
     4 	instanceVariableNames:''
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitParser-Parsers'
       
     8 !
       
     9 
       
    10 PPChoiceParser comment:'A parser that uses the first parser that succeeds.'
       
    11 !
       
    12 
       
    13 
       
    14 !PPChoiceParser methodsFor:'operations'!
       
    15 
       
    16 / aRule 
       
    17 	^ self copyWith: aRule
       
    18 ! !
       
    19 
       
    20 !PPChoiceParser methodsFor:'parsing'!
       
    21 
       
    22 parseOn: aStream
       
    23 	"This is optimized code that avoids unnecessary block activations, do not change. When all choices fail, the last failure is answered."
       
    24 
       
    25 	| element |
       
    26 	1 to: parsers size do: [ :index |
       
    27 		element := (parsers at: index)
       
    28 			parseOn: aStream.
       
    29 		element isPetitFailure
       
    30 			ifFalse: [ ^ element ] ].
       
    31 	^ element
       
    32 ! !
       
    33 
       
    34 !PPChoiceParser class methodsFor:'documentation'!
       
    35 
       
    36 version_SVN
       
    37     ^ '$Id: PPChoiceParser.st,v 1.1 2011-08-18 18:56:17 cg Exp $'
       
    38 ! !