Merged with PetitCompiler-JanKurs.20150510144201, PetitCompiler-Tests-JanKurs.20150510144201, PetitCompiler-Extras-Tests-JanKurs.20150510144201, PetitCompiler-Benchmarks-JanKurs.20150510144201
Name: PetitCompiler-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:42:29.192 PM
UUID: 58a4786b-1182-4904-8b44-a13d3918f244
Name: PetitCompiler-Tests-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:32:12.870 PM
UUID: 2a8fd41a-331b-4dcf-a7a3-752a50ce86e7
Name: PetitCompiler-Extras-Tests-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 04:59:25.308 PM
UUID: ef43bd1a-be60-4e88-b749-8b635622c969
Name: PetitCompiler-Benchmarks-JanKurs.20150510144201
Author: JanKurs
Time: 10-05-2015, 05:04:54.561 PM
UUID: d8e764fd-016b-46e2-9fc1-17c38c18f0e5
"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
"{ NameSpace: Smalltalk }"
PPAbstractParserTest subclass:#PPCLL1Test
instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
arguments configuration'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Tests-Core'
!
!PPCLL1Test methodsFor:'as yet unclassified'!
assert: p parse: whatever
^ result := super assert: p parse: whatever.
!
cleanClass
| parserClass |
parserClass := (Smalltalk at: arguments name ifAbsent: [nil]).
parserClass notNil ifTrue:[
self flag: 'uncomment'.
" parserClass removeFromSystem"
].
!
context
^ context := PPCProfilingContext new
!
parse: whatever
^ result := super parse: whatever.
!
setUp
arguments := PPCArguments default
profile: true;
yourself.
configuration := PPCLL1Configuration new
arguments: arguments;
yourself.
self cleanClass.
!
tearDown
self cleanClass
!
testChoiceOrder
parser := (
'a' asParser token, 'b' asParser token /
'a' asParser token)
compileWithConfiguration: configuration.
self assert: parser parse: 'ab'.
self assert: result first inputValue = 'a'.
self assert: result second inputValue = 'b'.
self assert: parser parse: 'a'.
self assert: result inputValue = 'a'.
self assert: parser fail: '_'.
!
testChoiceOrder2
| p1 p2 |
p1 := 'a' asParser token, 'b' asParser token.
p2 := 'b' asParser token / 'a' asParser token.
parser := p1 / p2 compileWithConfiguration: configuration.
self assert: parser parse: 'ab'.
self assert: result first inputValue = 'a'.
self assert: result second inputValue = 'b'.
self assert: parser parse: 'a'.
self assert: result inputValue = 'a'.
self assert: parser parse: 'b'.
self assert: result inputValue = 'b'.
self assert: parser fail: 'c'.
!
testChoiceOrder3
| p1 p2 a1 a2 |
a1 := 'a' asParser token name: 't1'; yourself.
a2 := 'a' asParser token name: 't2'; yourself.
p1 := a1, 'b' asParser token.
p2 := a2.
parser := p1 / p2 compileWithConfiguration: configuration.
self assert: parser parse: 'ab'.
self assert: result first inputValue = 'a'.
self assert: result second inputValue = 'b'.
self assert: parser parse: 'a'.
self assert: result inputValue = 'a'.
self assert: parser fail: 'b'.
!
testChoiceOrder4
| p1 p2 a1 a2 |
a1 := 'a' asParser token name: 't1'; yourself.
a2 := 'a' asParser token name: 't2'; yourself.
p1 := a1, 'b' asParser token.
p2 := 'b' asParser token / a2.
parser := p1 / p2 compileWithConfiguration: configuration.
self assert: parser parse: 'ab'.
self assert: result first inputValue = 'a'.
self assert: result second inputValue = 'b'.
self assert: parser parse: 'a'.
self assert: result inputValue = 'a'.
self assert: parser parse: 'b'.
self assert: result inputValue = 'b'.
self assert: parser fail: 'c'.
!
testCompileChoice
parser := ('foo' asParser / 'bar' asParser) compileWithConfiguration: configuration.
self assert: parser parse: 'foo' to: 'foo'.
self assert: parser parse: 'bar' to: 'bar'.
self assert: parser fail: '_'.
!
testCompileChoice2
parser := ('foo' asParser token trim / 'bar' asParser token trim) compileWithConfiguration: configuration.
self assert: parser parse: 'foo'.
self assert: result inputValue = 'foo'.
self assert: parser parse: 'bar'.
self assert: result inputValue = 'bar'.
self assert: parser fail: '_'.
!
testCompileLiteral
parser := 'foo' asParser token compileWithConfiguration: configuration.
self assert: parser parse: 'foo'.
self assert: result inputValue = 'foo'.
self assert: parser fail: 'boo'.
!
testCompileSequence
parser := ('foo' asParser token), ('bar' asParser token)
compileWithConfiguration: configuration.
self assert: parser parse: 'foobar'.
self assert: result first inputValue = 'foo'.
self assert: result second inputValue = 'bar'.
!
testCompileTokenComplex2
| a b argumentsWith |
"based on the PPSmalltlakGrammar>>blockArgumentsWith"
a := $| asParser smalltalkToken
yourself.
b := $] asParser smalltalkToken
yourself.
argumentsWith := (a / b and ==> [:t | ]) wrapped
name: 'argumentsWith';
yourself.
parser := argumentsWith compileWithConfiguration: configuration.
self assert: parser parse: '|'.
parser := argumentsWith compileWithConfiguration: configuration.
self assert: parser parse: ']'.
!
testCompileTokenComplex3
| choice1 choice2 a1 b1 a2 b2 tricky |
a1 := $| asParser token
yourself.
b1 := $] asParser token
yourself.
choice1 := (a1 / b1) wrapped
name: 'choice1';
yourself.
a2 := $| asParser token
yourself.
b2 := $] asParser token
yourself.
choice2 := (a2 / b2) wrapped
name: 'choice1';
yourself.
tricky := (a1 asParser, choice1) / (b2 asParser, choice2).
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: ']]'.
!
testCompileTrim
parser := 'foo' asParser token trim end compileWithConfiguration: configuration.
self assert: parser parse: 'foo'.
self assert: result inputValue = 'foo'.
self assert: parser parse: 'foo '.
self assert: result inputValue = 'foo'.
self assert: parser parse: ' foo'.
self assert: result inputValue = 'foo'.
self assert: parser fail: 'boo'.
!
testTokenName
| token |
token := 'foo' asParser token name: 'fooToken'; yourself.
parser := token plus
compileWithConfiguration: configuration.
self assert: parser parse: 'foofoo'.
self assert: result first inputValue = 'foo'.
self assert: result second inputValue = 'foo'.
self assert: (parser class methodDictionary includesKey: #fooToken).
! !