PPSequenceParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 03 Oct 2014 02:33:08 +0100
changeset 377 6112a403a52d
parent 180 48a6757d5f01
child 421 7e08b31e0dae
permissions -rw-r--r--
Updated to latest version from Moose repository. Name: PetitParser-JanKurs.250 Author: JanKurs Time: 01-10-2014, 04:44:04 AM UUID: c46eea20-51a0-4deb-8fd5-8cb99810a8b4 Repository: http://smalltalkhub.com/mc/Moose/PetitParser/main Name: PetitTests-JanKurs.60 Author: JanKurs Time: 29-09-2014, 11:48:10 AM UUID: 28fd2e65-c287-4f73-b71e-5b6bb25bebaa Repository: http://smalltalkhub.com/mc/Moose/PetitParser/main

"{ Package: 'stx:goodies/petitparser' }"

PPListParser subclass:#PPSequenceParser
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitParser-Parsers'
!



!PPSequenceParser methodsFor:'operations'!

, aRule
	^ self copyWith: aRule
!

permutation: anArrayOfIntegers
	"Answer a permutation of the receivers sequence."
	
	anArrayOfIntegers do: [ :index |
		(index isInteger and: [ index between: 1 and: parsers size ])
			ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ].
	^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ]
! !

!PPSequenceParser methodsFor:'operators-mapping'!

map: aBlock
	^ aBlock numArgs = self children size
		ifTrue: [ self ==> [ :nodes | aBlock valueWithArguments: nodes ] ]
		ifFalse: [ self error: aBlock numArgs asString , ' arguments expected.' ]
! !

!PPSequenceParser methodsFor:'parsing'!

parseOn: aPPContext
	"This is optimized code that avoids unnecessary block activations, do not change."
	
	| memento elements element |
	memento := aPPContext remember.
	elements := Array new: parsers size.
	1 to: parsers size do: [ :index |
		element := (parsers at: index) 
			parseOn: aPPContext.
		element isPetitFailure ifTrue: [
			aPPContext restore: memento.
			^ element ].
		elements at: index put: element ].
	^ elements
! !

!PPSequenceParser class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
!

version_SVN
    ^ '$Id: PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
! !