PPGreedyRepeatingParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 16 Jun 2015 07:49:21 +0100
changeset 491 82b272c7dc37
parent 380 8fe3cb4e607f
permissions -rw-r--r--
Codegen: added support for smart action node compiling. Avoid creation of intermediate result collection for action nodes if all references to action block's argument (i.e., the nodes collection) is in form of: * <nodes> at: <numeric constant> * <nodes> first (second, third...
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