compiler/tests/PPCOptimizingTest.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 26 Oct 2014 01:03:31 +0000
changeset 391 553a5456963b
child 392 9b297f0d949c
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:
391
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
TestCase subclass:#PPCOptimizingTest
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
	instanceVariableNames:''
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
	classVariableNames:''
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     6
	poolDictionaries:''
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	category:'PetitCompiler-Tests-Nodes'
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
PPCOptimizingTest comment:''
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
!PPCOptimizingTest methodsFor:'test support'!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
assert: object type: class
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
	self assert: object class == class
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    18
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
optimize: p
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    20
	^ p asCompilerTree optimizeTree 
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    21
! !
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    22
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    23
!PPCOptimizingTest methodsFor:'tests'!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
testAnyPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
	tree := self optimize: #any asParser.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
	self assert: tree type: PPCAnyNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
testCharSetPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
	tree := self optimize: (PPPredicateObjectParser on: [:each | each = $b or: [each = $c] ] message: #foo).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
	self assert: tree type: PPCCharSetPredicateNode
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
testChoiceInlining
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
	tree := self optimize: $a asParser  / $b asParser.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
	self assert: tree type: PPCChoiceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
	self assert: tree children first  type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
	self assert: tree children second type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
testForwarding
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
	| tree p1 p2 |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
	p2 := $a asParser.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
	p1 := p2 wrapped.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
	p1 name: 'p1'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
	tree := self optimize: p1.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
	self assert: tree type: PPCCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
	self assert: tree name = 'p1'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
	p2 name: 'p2'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
	tree := self optimize: p1.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
	self assert: tree type: PPCForwardNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
	self assert: tree name = 'p1'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
	self assert: tree child name = 'p2'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
testInlineCharacter
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
	tree := self optimize: $a asParser plus.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
	self assert: tree type: PPCPlusNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
	self assert: tree child  type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
	self assert: tree child character = $a.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
testInlineCharacter2
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
	tree := self optimize: $a asParser star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
	self assert: tree type: PPCStarNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
	self assert: tree child  type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
	self assert: tree child character = $a.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
testInlineCharacter3
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    85
	tree := self optimize: $a asParser, $b asParser.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    86
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    87
	self assert: tree type: PPCSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    88
	self assert: tree children first type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    89
	self assert: tree children first character = $a.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
	self assert: tree children second type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
	self assert: tree children second character = $b.	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    93
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    94
testInlineNil
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    95
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    96
	tree := self optimize: nil asParser star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    97
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    98
	self assert: tree type: PPCStarNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    99
	self assert: tree child type: PPCInlineNilNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   100
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   101
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
testInlineNotLiteral
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   103
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   104
	tree := self optimize: 'foo' asParser not star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   105
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   106
	self assert: tree type: PPCStarNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   107
	self assert: tree child type: PPCInlineNotLiteralNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
	self assert: tree child literal = 'foo'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
testInlineNotPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
	tree := self optimize: (#letter asParser not, (PPPredicateObjectParser on: [ :e | e = $a or: [  e = $b ]] message: #foo) not).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
	self assert: tree type: PPCSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
	self assert: tree children first type: PPCInlineNotMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
	self assert: tree children second type: PPCInlineNotCharSetPredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
testInlinePluggable
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
	tree := self optimize: [:ctx | nil] asParser star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
	self assert: tree type: PPCStarNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
	self assert: tree child type: PPCInlinePluggableNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   126
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
testInlinePredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
	tree := self optimize: (#letter asParser, (PPPredicateObjectParser on: [ :e | e = $a or: [  e = $b ]] message: #foo)).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
	self assert: tree type: PPCSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
	self assert: tree children first type: PPCInlineMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
	self assert: tree children second type: PPCInlineCharSetPredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
testLetterPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
	tree := self optimize: #letter asParser.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
	self assert: tree type: PPCMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
	self assert: tree message = #isLetter.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   145
testNotCharSetPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   146
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
	tree := self optimize: (PPPredicateObjectParser on: [:each | each = $b or: [each = $c] ] message: #foo) asParser not.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   148
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   149
	self assert: tree type: PPCNotCharSetPredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   150
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   151
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
testNotLiteral
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   154
	tree := self optimize: 'foo' asParser not.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   156
	self assert: tree type: PPCNotLiteralNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
	self assert: tree literal = 'foo'.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   158
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   159
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   160
testNotMessagePredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   161
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   162
	tree := self optimize: #letter asParser not.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   163
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   164
	self assert: tree type: PPCNotMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   165
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   166
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   167
testStarAny
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   168
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   169
	tree := self optimize: #any asParser star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   170
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   171
	self assert: tree type: PPCStarAnyNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   172
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   173
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   174
testStarCharSetPredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   175
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
	tree := self optimize: (PPPredicateObjectParser on: [:each | each = $b or: [each = $c] ] message: #foo) star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   177
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   178
	self assert: tree type: PPCStarCharSetPredicateNode
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   179
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   181
testStarMessagePredicate
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   182
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   183
	tree := self optimize: #letter asParser star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   184
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   185
	self assert: tree type: PPCStarMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   186
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   187
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   188
testSymbolAction
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   189
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   190
	tree := self optimize: (#letter asParser) ==> #second.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   192
	self assert: tree type: PPCSymbolActionNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   193
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   194
	tree := self optimize: (#letter asParser) ==> [:e | e second ].
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   195
	self assert: tree type: PPCActionNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   196
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   197
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   198
testToken
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   199
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
	tree := self optimize: ((#letter asParser, #word asParser star) token).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   202
	self assert: tree type: PPCTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   203
	self assert: tree child type: PPCTokenSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   204
	self assert: tree child children size = 2.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   205
	self assert: tree child children first type: PPCInlineMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   206
	self assert: tree child children second type: PPCTokenStarMessagePredicateNode.	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   207
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   208
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   209
testTokenSequence
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   210
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   211
	tree := self optimize: ($a asParser, $b asParser) token.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   212
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   213
	self assert: tree type: PPCTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   214
	self assert: tree child type: PPCTokenSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   215
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   216
	tree := self optimize: ($a asParser, $b asParser) trimmingToken.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   217
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
	self assert: tree type: PPCTrimmingTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
	self assert: tree child type: PPCTokenSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   220
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
testTrimmingToken
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223
	| tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   224
	tree := self optimize: ((#letter asParser, #word asParser star) trimmingToken).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   225
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   226
	self assert: tree type: PPCTrimmingTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   227
	self assert: tree whitespace type: PPCTokenStarMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   228
	self assert: tree child type: PPCTokenSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   229
	self assert: tree child children size = 2.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
	self assert: tree child children first type: PPCInlineMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
	self assert: tree child children second type: PPCTokenStarMessagePredicateNode.	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   232
!
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   233
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   234
testTrimmingToken2
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   235
	| parser tree |
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   236
	parser := 'foo' asParser trimmingToken.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   237
	tree := parser asCompilerTree optimizeTree.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   238
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   239
	self assert: tree type: PPCTrimmingTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   240
	self assert: tree child type: PPCInlineLiteralNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   241
	self assert: (tree whitespace allNodes allSatisfy: [ :n | n isKindOf: PPCNode ]).
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   242
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   243
	parser := ('foo' asParser, $b asParser) trimmingToken.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   244
	tree := parser asCompilerTree optimizeTree.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   245
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   246
	self assert: tree type: PPCTrimmingTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   247
	self assert: tree child type: PPCTokenSequenceNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   248
	self assert: tree whitespace type: PPCTokenStarMessagePredicateNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   249
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   250
	parser := $d asParser trimmingToken star.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   251
	tree := parser asCompilerTree optimizeTree.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   252
	
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   253
	self assert: tree type: PPCStarNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   254
	self assert: tree child type: PPCTrimmingTokenNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   255
	self assert: tree child child type: PPCInlineCharacterNode.
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   256
! !
553a5456963b Ported PetitCompiler-(Tests).
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   257