--- a/compiler/tests/PPCTokenizingTest.st Fri Jul 31 14:07:31 2015 +0100
+++ b/compiler/tests/PPCTokenizingTest.st Mon Aug 17 12:56:02 2015 +0100
@@ -21,11 +21,15 @@
!
cleanClass
- | parserClass |
+ | parserClass scannerClass |
parserClass := (Smalltalk at: arguments parserName ifAbsent: [nil]).
parserClass notNil ifTrue:[
- self flag: 'uncomment'.
-" parserClass removeFromSystem"
+ parserClass removeFromSystem
+ ].
+
+ scannerClass := (Smalltalk at: arguments scannerName ifAbsent: [nil]).
+ scannerClass notNil ifTrue:[
+ scannerClass removeFromSystem
].
"Modified: / 24-07-2015 / 19:50:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -52,7 +56,34 @@
!
tearDown
- self cleanClass
+ "self cleanClass"
+!
+
+testChoice
+ | p1 p2 a1 a2 |
+ a1 := 'a' asParser token name: 't1'; yourself.
+ a2 := 'b' asParser token name: 't2'; yourself.
+
+ p1 := a1 star.
+ p2 := a2.
+
+ parser := p1 / p2 compileWithConfiguration: configuration.
+
+ self assert: parser parse: ''.
+ self assert: result isEmpty.
+
+ self assert: parser parse: 'a'.
+ self assert: result first inputValue = 'a'.
+
+ self assert: parser parse: 'aa'.
+ self assert: result first inputValue = 'a'.
+ self assert: result second inputValue = 'a'.
+
+ self assert: parser parse: 'b' end: 0.
+ self assert: result isEmpty.
+
+ self assert: parser parse: 'c' end: 0.
+
!
testChoiceOrder
@@ -205,6 +236,21 @@
!
+testCompileEmptytoken
+ | start stop epsilon |
+ start := $( asParser token.
+ stop := $) asParser token.
+ epsilon := '' asParser token.
+
+ self should: [
+ (start, epsilon, stop) compileWithConfiguration: configuration.
+ ] raise: Exception.
+"
+ self assert: parser parse: '()'.
+ self assert: parser fail: '('.
+"
+!
+
testCompileLiteral
parser := 'foo' asParser token compileWithConfiguration: configuration.
@@ -222,6 +268,39 @@
self assert: result second inputValue = 'bar'.
!
+testCompileSequence2
+ parser := ('foo' asParser trimmingToken), ('bar' asParser trimmingToken)
+ compileWithConfiguration: configuration.
+
+ self assert: parser parse: 'foobar'.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'bar'.
+
+ self assert: parser parse: 'foo bar'.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'bar'.
+
+ self assert: parser parse: ' foo bar'.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'bar'.
+!
+
+testCompileSequence3
+ parser := ('foo' asParser trimmingToken),
+ ('bar' asParser trimmingToken),
+ ('baz' asParser trimmingToken)
+ compileWithConfiguration: configuration.
+
+ self assert: parser parse: 'foobarbaz'.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'bar'.
+
+ self assert: parser parse: ' foo bar baz '.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'bar'.
+ self assert: result third inputValue = 'baz'.
+!
+
testCompileStar
parser := 'foo' asParser token star compileWithConfiguration: configuration.
@@ -236,7 +315,7 @@
parser := ('foo' asParser token, 'bar' asParser token) star compileWithConfiguration: configuration.
self assert: parser parse: 'foobar'.
- self assert: context tokenReads size = 3.
+ self assert: context tokenReads size = 1.
self assert: parser parse: 'bar' end: 0.
self assert: result isEmpty.
@@ -258,7 +337,6 @@
parser := argumentsWith compileWithConfiguration: configuration.
self assert: parser parse: '|'.
- parser := argumentsWith compileWithConfiguration: configuration.
self assert: parser parse: ']'.
!
@@ -285,16 +363,41 @@
parser := tricky compileWithConfiguration: configuration.
self assert: parser parse: '||'.
- parser := tricky compileWithConfiguration: configuration.
self assert: parser parse: '|]'.
- parser := tricky compileWithConfiguration: configuration.
self assert: parser parse: ']|'.
- parser := tricky compileWithConfiguration: configuration.
self assert: parser parse: ']]'.
!
+testCompileTokenComplex4
+ | symbol symbolLiteralArray symbolLiteral arrayItem arrayLiteral |
+ "based on symbolLiteral symbolLiteralArray in SmalltalkGrammar"
+
+ symbol := PPDelegateParser new.
+ symbol setParser: 'foo' asParser.
+ symbol name: 'symbol'.
+
+ symbolLiteralArray := PPDelegateParser new.
+ symbolLiteralArray setParser: symbol token.
+ symbolLiteralArray name: 'symbolLiteralArray'.
+
+ symbolLiteral := PPDelegateParser new.
+ symbolLiteral setParser: $# asParser token, symbol token ==> [:e | e].
+ symbolLiteral name: 'symbolLiteral'.
+
+ arrayLiteral := PPDelegateParser new.
+ arrayLiteral setParser: '#(' asParser token, symbolLiteralArray, ')' asParser token.
+ arrayLiteral name: 'arrayLiteral'.
+
+ arrayItem := arrayLiteral / symbolLiteral.
+
+ parser := arrayItem compileWithConfiguration: configuration.
+
+ self assert: parser parse: '#(foo)'.
+ self assert: parser parse: '#foo'.
+!
+
testCompileTrim
parser := 'foo' asParser token trim end compileWithConfiguration: configuration.
@@ -322,7 +425,10 @@
self assert: parser parse: 'a'.
self assert: result first inputValue = 'a'.
- self assert: context invocations size = 5.
+ self assert: context tokenReads size = 1.
+
+ self flag: 'add the assertion here?'.
+" self assert: context invocations size = 5."
!
testTokenCharacter2
@@ -335,7 +441,10 @@
self assert: result first inputValue = 'a'.
self assert: result second inputValue = 'a'.
self assert: result third inputValue = 'a'.
- self assert: context invocations size = 7.
+
+ self assert: context tokenReads size = 1.
+ self flag: 'Add the assertion here?'.
+" self assert: context invocations size = 7."
!
testTokenName
@@ -366,7 +475,7 @@
self assert: parser parse: ' foo '.
self assert: result first inputValue = 'foo'.
- self assert: (context invocations select: [:e | e = #consumeWhitespace ]) size = 2.
+ self assert: (context invocations select: [:e | e = #consumeWhitespace ]) size = 3.
!
testWhitespace2
@@ -386,6 +495,27 @@
self assert: result first inputValue = 'foo'.
self assert: result second inputValue = 'foo'.
- self assert: (context invocations select: [:e | e = #consumeWhitespace ]) size = 3.
+ self assert: (context invocations select: [:e | e = #consumeWhitespace ]) size = 4.
+!
+
+testWhitespace3
+ | token ws trimmingToken |
+ configuration arguments inline: false.
+
+ token := 'foo' asParser token.
+ ws := #blank asParser star name: 'consumeWhitespace'; yourself.
+ trimmingToken := ((ws, token, ws) ==> #second)
+ propertyAt: 'trimmingToken' put: true;
+ yourself.
+
+ parser := trimmingToken plus
+ compileWithConfiguration: configuration.
+
+ self assert: parser parse: ' foo foo foo '.
+ self assert: result first inputValue = 'foo'.
+ self assert: result second inputValue = 'foo'.
+ self assert: result third inputValue = 'foo'.
+
+ self assert: (context invocations select: [:e | e = #consumeWhitespace ]) size = 5.
! !