PPComposedTest.st
author sr
Thu, 05 Jul 2018 09:23:25 +0200
changeset 626 5159b1039a8f
parent 186 8fc35b70c3b9
permissions -rw-r--r--
order
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
90de244a7fa2 move to package
Claus Gittinger <cg@exept.de>
parents: 0
diff changeset
     1
"{ Package: 'stx:goodies/petitparser' }"
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
     3
PPAbstractParserTest subclass:#PPComposedTest
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
	instanceVariableNames:''
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	classVariableNames:''
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	poolDictionaries:''
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	category:'PetitTests-Tests'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
!PPComposedTest methodsFor:'accessing'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
comment
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
	^ ($" asParser , $" asParser negate star , $" asParser) flatten
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
identifier
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	^ (#letter asParser , #word asParser star) flatten
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
number
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	^ ($- asParser optional , #digit asParser plus , ($. asParser , #digit asParser plus) optional) flatten
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
! !
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!PPComposedTest methodsFor:'testing'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
testDoubledString
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    28
	| parser |
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    29
	parser := ($' asParser , (($' asParser , $' asParser) / $' asParser negate) star flatten , $' asParser) 
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    30
		==> [ :nodes | nodes second copyReplaceAll: '''''' with: '''' ].
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    32
	self assert: parser parse: '''''' to: ''.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    33
	self assert: parser parse: '''a''' to: 'a'.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    34
	self assert: parser parse: '''ab''' to: 'ab'.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    35
	self assert: parser parse: '''a''''b''' to: 'a''b'.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    36
	self assert: parser parse: '''a''''''''b''' to: 'a''''b'
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
testEvenNumber
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
	"Create a grammar that parses an even number of a's and b's."
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    41
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
	| a as b bs s |
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
	a := $a asParser ==> [ :char | as := as + 1 ].
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
	b := $b asParser ==> [ :char | bs := bs + 1 ].
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
	s := (a / b) star >=> [ :stream :cc |
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
		as := bs := 0.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
		cc value.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
		(as even and: [ bs even ])
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
			ifFalse: [ PPFailure message: 'Even number of a and b expected' at: 0 ] ].
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
	self assert: s fail: 'a' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
	self assert: s fail: 'b' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
	self assert: s fail: 'ab' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
	self assert: s fail: 'ba' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
	self assert: s fail: 'aaa' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
	self assert: s fail: 'bbb' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
	self assert: s fail: 'aab' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
	self assert: s fail: 'abb' end: 3.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    59
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
	self assert: s parse: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
	self assert: s parse: 'aa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
	self assert: s parse: 'bb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
	self assert: s parse: 'aaaa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
	self assert: s parse: 'aabb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
	self assert: s parse: 'abab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
	self assert: s parse: 'baba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
	self assert: s parse: 'bbaa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
	self assert: s parse: 'bbbb'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
testIfThenElse
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
	"S ::= if C then S else S | if C then S | X"
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
	| start if then else cond expr parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    75
	start := PPDelegateParser new.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
	if := 'if' asParser token trim.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
	then := 'then' asParser token trim.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
	else := 'else' asParser token trim.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
	cond := 'C' asParser token trim.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
	expr := 'X' asParser token trim.
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    81
	start setParser: (if , cond , then , start , else , start) / (if , cond , then , start) / expr.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
	parser := start end.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
	self assert: parser parse: 'X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
	self assert: parser parse: 'if C then X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
	self assert: parser parse: 'if C then X else X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
	self assert: parser parse: 'if C then if C then X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
	self assert: parser parse: 'if C then if C then X else if C then X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
	self assert: parser parse: 'if C then if C then X else X else if C then X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
	self assert: parser parse: 'if C then if C then X else X else if C then X else X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
	self assert: parser fail: 'if C'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
	self assert: parser fail: 'if C else X'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
	self assert: parser fail: 'if C then if C'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
testLeftRecursion
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
	"S ::= S 'x' S / '1'"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
    97
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
	| parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
    99
	parser := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   100
	parser setParser: ((parser , $x asParser , parser) / $1 asParser) memoized flatten.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
	self assert: parser parse: '1' to: '1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
	self assert: parser parse: '1x1' to: '1x1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
	self assert: parser parse: '1x1x1' to: '1x1x1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
	self assert: parser parse: '1x1x1x1' to: '1x1x1x1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
	self assert: parser parse: '1x1x1x1x1' to: '1x1x1x1x1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
	self assert: parser parse: '1x1x1x1x1x1' to: '1x1x1x1x1x1'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
testListOfIntegers
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
	"S ::= S , number | number"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   112
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
	| number list parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   114
	number := #digit asParser plus flatten trim
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   115
		==> [ :node | node asInteger ].
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
	list := (number separatedBy: $, asParser token trim)
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
		==> [ :node | node select: [ :each | each isInteger ] ].
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
	parser := list end.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
	self assert: parser parse: '1' to: (1 to: 1) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
	self assert: parser parse: '1,2' to: (1 to: 2) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
	self assert: parser parse: '1,2,3' to: (1 to: 3) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
	self assert: parser parse: '1,2,3,4' to: (1 to: 4) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
	self assert: parser parse: '1,2,3,4,5' to: (1 to: 5) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
	self assert: parser parse: '1' to: (1 to: 1) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
	self assert: parser parse: '1, 2' to: (1 to: 2) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
	self assert: parser parse: '1, 2, 3' to: (1 to: 3) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
	self assert: parser parse: '1, 2, 3, 4' to: (1 to: 4) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
	self assert: parser parse: '1, 2, 3, 4, 5' to: (1 to: 5) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
	self assert: parser parse: '1' to: (1 to: 1) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
	self assert: parser parse: '1 ,2' to: (1 to: 2) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
	self assert: parser parse: '1 ,2 ,3' to: (1 to: 3) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
	self assert: parser parse: '1 ,2 ,3 ,4' to: (1 to: 4) asArray.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
	self assert: parser parse: '1 ,2 ,3 ,4 ,5' to: (1 to: 5) asArray.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   137
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
	self assert: parser fail: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
	self assert: parser fail: ','.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
	self assert: parser fail: '1,'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
	self assert: parser fail: '1,,2'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
testNestedComments
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   145
	"C ::= B I* E"
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   146
	"I ::= !!E (C | T)"
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   147
	"B ::= /*"
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   148
	"E ::= */"
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   149
	"T ::= ."
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   150
	
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   151
	| begin end any inside parser |
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   152
	begin := '/*' asParser.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   153
	end := '*/' asParser.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   154
	any := #any asParser.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   155
	
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   156
	parser := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   157
	inside := end not , (parser / any).
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   158
	parser setParser: begin , inside star , end.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   159
	
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   160
	self assert: parser parse: '/*ab*/cd' end: 6.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   161
	self assert: parser parse: '/*a/*b*/c*/'.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   162
	self assert: parser fail: '/*a/*b*/c'
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
testPalindrome
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
	"S0 ::= a S1 a | b S1 b | ...
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
	 S1 ::= S0 | epsilon"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   168
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
	| s0 s1 parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   170
	s0 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   171
	s1 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   172
	s0 setParser: ($a asParser , s1 , $a asParser)
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
		/ ($b asParser , s1 , $b asParser)
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   174
		/ ($c asParser , s1 , $c asParser).	
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   175
	s1 setParser: s0 / nil asParser.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
	parser := s0 flatten end.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
	self assert: parser parse: 'aa' to: 'aa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
	self assert: parser parse: 'bb' to: 'bb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
	self assert: parser parse: 'cc' to: 'cc'.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   181
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
	self assert: parser parse: 'abba' to: 'abba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
	self assert: parser parse: 'baab' to: 'baab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
	self assert: parser parse: 'abccba' to: 'abccba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
	self assert: parser parse: 'abaaba' to: 'abaaba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
	self assert: parser parse: 'cbaabc' to: 'cbaabc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
	self assert: parser fail: 'a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
	self assert: parser fail: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
	self assert: parser fail: 'aab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
	self assert: parser fail: 'abccbb'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
testParseAaaBbb
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
	"S0 ::= a S1 b
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
	 S1 ::= S0 | epsilon"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   198
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
	| s0 s1 parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   200
	s0 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   201
	s1 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   202
	s0 setParser: $a asParser , s1 , $b asParser.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   203
	s1 setParser: s0 / nil asParser.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
	parser := s0 flatten.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
	self assert: parser parse: 'ab' to: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
	self assert: parser parse: 'aabb' to: 'aabb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
	self assert: parser parse: 'aaabbb' to: 'aaabbb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
	self assert: parser parse: 'aaaabbbb' to: 'aaaabbbb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
	self assert: parser parse: 'abb' to: 'ab' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
	self assert: parser parse: 'aabbb' to: 'aabb' end: 4.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
	self assert: parser parse: 'aaabbbb' to: 'aaabbb' end: 6.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
	self assert: parser parse: 'aaaabbbbb' to: 'aaaabbbb' end: 8.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
	self assert: parser fail: 'a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
	self assert: parser fail: 'b'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
	self assert: parser fail: 'aab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
	self assert: parser fail: 'aaabb'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
testParseAaaaaa
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
	"S ::= a a S | epsilon"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   224
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
	| s0 s1 parser |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   226
	s0 := PPDelegateParser new.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
	s1 := $a asParser , $a asParser , s0.
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   228
	s0 setParser: s1 / nil asParser.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
	parser := s0 flatten.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
	self assert: parser parse: '' to: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
	self assert: parser parse: 'aa' to: 'aa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
	self assert: parser parse: 'aaaa' to: 'aaaa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
	self assert: parser parse: 'aaaaaa' to: 'aaaaaa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
	self assert: parser parse: 'a' to: '' end: 0.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
	self assert: parser parse: 'aaa' to: 'aa' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
	self assert: parser parse: 'aaaaa' to: 'aaaa' end: 4.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
	self assert: parser parse: 'aaaaaaa' to: 'aaaaaa' end: 6
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
testParseAbAbAb
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
	"S ::= (A B)+"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   244
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
	| parser |
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
	parser := ($a asParser , $b asParser) plus flatten.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
	self assert: parser parse: 'ab' to: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
	self assert: parser parse: 'abab' to: 'abab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
	self assert: parser parse: 'ababab' to: 'ababab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
	self assert: parser parse: 'abababab' to: 'abababab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
	self assert: parser parse: 'abb' to: 'ab' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
	self assert: parser parse: 'ababa' to: 'abab' end: 4.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
	self assert: parser parse: 'abababb' to: 'ababab' end: 6.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
	self assert: parser parse: 'ababababa' to: 'abababab' end: 8.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   257
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
	self assert: parser fail: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
	self assert: parser fail: 'a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
	self assert: parser fail: 'bab'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
testParseAbabbb
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
	"S ::= (A | B)+"
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
	| parser |
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
	parser := ($a asParser / $b asParser) plus flatten.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
	self assert: parser parse: 'a' to: 'a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
	self assert: parser parse: 'b' to: 'b'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
	self assert: parser parse: 'ab' to: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
	self assert: parser parse: 'ba' to: 'ba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
	self assert: parser parse: 'aaa' to: 'aaa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
	self assert: parser parse: 'aab' to: 'aab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
	self assert: parser parse: 'aba' to: 'aba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
	self assert: parser parse: 'baa' to: 'baa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
	self assert: parser parse: 'abb' to: 'abb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
	self assert: parser parse: 'bab' to: 'bab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
	self assert: parser parse: 'bba' to: 'bba'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
	self assert: parser parse: 'bbb' to: 'bbb'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
	self assert: parser parse: 'ac' to: 'a' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
	self assert: parser parse: 'bc' to: 'b' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
	self assert: parser parse: 'abc' to: 'ab' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
	self assert: parser parse: 'bac' to: 'ba' end: 2.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   286
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
	self assert: parser fail: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
	self assert: parser fail: 'c'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
testParseAnBnCn
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   292
	"PEGs for a non context- free language: 
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   293
		
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
		a^n , b^n , c^n
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   295
		
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   296
	S <- &P1 P2 
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   297
	P1 <- AB 'c' 
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
	AB <- 'a' AB 'b' / epsilon
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
	P2 <- 'a'* BC end
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
	BC <- 'b' BC 'c' / epsilon"
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   301
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
	| s p1 ab p2 bc |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   303
	s := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   304
	p1 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   305
	ab := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   306
	p2 := PPDelegateParser new.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   307
	bc := PPDelegateParser new.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   308
	
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   309
	s setParser: (p1 and , p2 end) flatten.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   310
	p1 setParser: ab , $c asParser.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   311
	ab setParser: ($a asParser , ab , $b asParser) optional.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   312
	p2 setParser: $a asParser star , bc.
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   313
	bc setParser: ($b asParser , bc , $c asParser) optional.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   314
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
	self assert: s parse: 'abc' to: 'abc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
	self assert: s parse: 'aabbcc' to: 'aabbcc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
	self assert: s parse: 'aaabbbccc' to: 'aaabbbccc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
	self assert: s fail: 'bc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
	self assert: s fail: 'ac'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
	self assert: s fail: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
	self assert: s fail: 'abbcc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
	self assert: s fail: 'aabcc'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
	self assert: s fail: 'aabbc'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
! !
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
!PPComposedTest methodsFor:'testing-examples'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
testComment
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
	self assert: self comment parse: '""' to: '""'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
	self assert: self comment parse: '"a"' to: '"a"'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
	self assert: self comment parse: '"ab"' to: '"ab"'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
	self assert: self comment parse: '"abc"' to: '"abc"'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
	self assert: self comment parse: '""a' to: '""' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
	self assert: self comment parse: '"a"a' to: '"a"' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
	self assert: self comment parse: '"ab"a' to: '"ab"' end: 4.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
	self assert: self comment parse: '"abc"a' to: '"abc"' end: 5.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
	self assert: self comment fail: '"'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
	self assert: self comment fail: '"a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
	self assert: self comment fail: '"aa'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
	self assert: self comment fail: 'a"'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
	self assert: self comment fail: 'aa"'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
testIdentifier
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
	self assert: self identifier parse: 'a' to: 'a'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
	self assert: self identifier parse: 'a1' to: 'a1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
	self assert: self identifier parse: 'a12' to: 'a12'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
	self assert: self identifier parse: 'ab' to: 'ab'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
	self assert: self identifier parse: 'a1b' to: 'a1b'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
	self assert: self identifier parse: 'a_' to: 'a' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
	self assert: self identifier parse: 'a1-' to: 'a1' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
	self assert: self identifier parse: 'a12+' to: 'a12' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
	self assert: self identifier parse: 'ab^' to: 'ab' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
	self assert: self identifier parse: 'a1b*' to: 'a1b' end: 3.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
	self assert: self identifier fail: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
	self assert: self identifier fail: '1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
	self assert: self identifier fail: '1a'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
testNumber
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
	self assert: self number parse: '1' to: '1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
	self assert: self number parse: '12' to: '12'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
	self assert: self number parse: '12.3' to: '12.3'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
	self assert: self number parse: '12.34' to: '12.34'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
	self assert: self number parse: '1..' to: '1' end: 1.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
	self assert: self number parse: '12-' to: '12' end: 2.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
	self assert: self number parse: '12.3.' to: '12.3' end: 4.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
	self assert: self number parse: '12.34.' to: '12.34' end: 5.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   375
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
	self assert: self number parse: '-1' to: '-1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
	self assert: self number parse: '-12' to: '-12'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
	self assert: self number parse: '-12.3' to: '-12.3'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
	self assert: self number parse: '-12.34' to: '-12.34'.
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   380
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
	self assert: self number fail: ''.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
	self assert: self number fail: '-'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
	self assert: self number fail: '.'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
	self assert: self number fail: '.1'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
testReturn
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
	| number spaces return |
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   389
	number := #digit asParser plus flatten.
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
	spaces := #space asParser star.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
	return := (spaces , $^ asParser token , spaces , number)
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   392
		==> [ :nodes | Array with: #return with: (nodes at: 4) ].
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
	self assert: return parse: '^1' to: #(return '1').
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
	self assert: return parse: '^12' to: #(return '12').
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
	self assert: return parse: '^ 123' to: #(return '123').
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
	self assert: return parse: '^  1234' to: #(return '1234').
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   398
	
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
	self assert: return fail: '1'.
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
	self assert: return fail: '^'
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
! !
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
!PPComposedTest class methodsFor:'documentation'!
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   405
version
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   406
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPComposedTest.st,v 1.5 2014-03-04 14:34:10 cg Exp $'
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   407
!
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   408
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   409
version_CVS
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   410
    ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPComposedTest.st,v 1.5 2014-03-04 14:34:10 cg Exp $'
14
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   411
!
d72aa40bcf53 Checkin from browser
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 4
diff changeset
   412
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
version_SVN
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   414
    ^ '$Id: PPComposedTest.st,v 1.5 2014-03-04 14:34:10 cg Exp $'
0
739fe9b7253e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
! !
186
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
   416