PPGreedyRepeatingParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 26 Oct 2014 01:03:31 +0000
changeset 391 553a5456963b
parent 380 8fe3cb4e607f
permissions -rw-r--r--
Ported PetitCompiler-(Tests). Name: PetitCompiler-JanKurs.41 Author: JanKurs Time: 25-10-2014, 03:30:28 AM UUID: 105186d1-1187-4ca6-8d66-3d2d47def4d3 Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main Name: PetitCompiler-Tests-JanKurs.4 Author: JanKurs Time: 25-10-2014, 03:30:58 AM UUID: 3e798fad-d5f6-4881-a583-f0bbffe27869 Repository: http://smalltalkhub.com/mc/JanKurs/PetitParser/main In addition, fixed some problems to make it compilable under Smalltalk/X: * Fixed PPCTokenNode>>initialize - there's no children instvar, it's initialization removed. * Fixed PPCContextMemento>>propertyAt:ifAbsent: - removed return-in-return, not compilable under Smalltalk/X (C issues) * Fixed PPCContextMemento>>hash - there's no stream instvar, access to it removed. * Fixed PPCAbstractCharacterNode>>compileWith:effect:id: - removed dot after method selector (stc does not like it)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser' }"
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
PPLimitedRepeatingParser subclass:#PPGreedyRepeatingParser
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	instanceVariableNames:''
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	classVariableNames:''
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	poolDictionaries:''
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	category:'PetitParser-Parsers'
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
!
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!PPGreedyRepeatingParser methodsFor:'parsing'!
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    13
parseOn: aPPContext
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    14
	| memento element elements positions |
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    15
	memento := aPPContext remember.
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	elements := OrderedCollection new.
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	[ elements size < min ] whileTrue: [ 
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    18
		(element := parser parseOn: aPPContext) isPetitFailure ifTrue: [ 
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    19
			aPPContext restore: memento.
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
			^ element ].
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
		elements addLast: element ].
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    22
	positions := OrderedCollection with: aPPContext remember.
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    23
	[ elements size < max and: [ (element := parser parseOn: aPPContext) isPetitFailure not ] ] whileTrue: [
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
		elements addLast: element.
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    25
		positions addLast: aPPContext remember ].
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	[ positions isEmpty ] whileFalse: [
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    27
		aPPContext restore: positions last.
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    28
		element := limit parseOn: aPPContext.
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
		element isPetitFailure ifFalse: [
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    30
			aPPContext restore: positions last.
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
			^ elements asArray ].
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
		elements isEmpty ifTrue: [
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    33
			aPPContext restore: memento.
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
			^ element ].
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
		elements removeLast.
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
		positions removeLast ].
377
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    37
	aPPContext restore: memento.
6112a403a52d Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 166
diff changeset
    38
	^ PPFailure message: 'overflow' context: aPPContext at: memento position
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
! !
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
!PPGreedyRepeatingParser class methodsFor:'documentation'!
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
version
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPGreedyRepeatingParser.st,v 1.1 2014-03-04 14:32:42 cg Exp $'
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
!
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
version_CVS
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPGreedyRepeatingParser.st,v 1.1 2014-03-04 14:32:42 cg Exp $'
380
8fe3cb4e607f Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 377
diff changeset
    49
!
8fe3cb4e607f Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 377
diff changeset
    50
8fe3cb4e607f Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 377
diff changeset
    51
version_HG
8fe3cb4e607f Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 377
diff changeset
    52
8fe3cb4e607f Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 377
diff changeset
    53
    ^ '$Changeset: <not expanded> $'
166
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
! !
749f1a5c6d3e initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55