compiler/tests/extras/PPCSmalltalkGrammarTests.st
changeset 515 b5316ef15274
child 516 3b81c9e53352
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PPSmalltalkGrammarTests subclass:#PPCSmalltalkGrammarTests
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Extras-Tests-Smalltalk'
       
    10 !
       
    11 
       
    12 !PPCSmalltalkGrammarTests class methodsFor:'resources'!
       
    13 
       
    14 resources
       
    15     ^ Array with: (PPCSetUpBeforeTearDownAfterResource for: self)
       
    16 ! !
       
    17 
       
    18 !PPCSmalltalkGrammarTests class methodsFor:'testing'!
       
    19 
       
    20 isAbstract
       
    21     ^ self == PPCSmalltalkGrammarTests
       
    22 ! !
       
    23 
       
    24 !PPCSmalltalkGrammarTests methodsFor:'accessing'!
       
    25 
       
    26 compiledParser
       
    27     ^ self compiledParserClass new
       
    28 
       
    29     "Created: / 29-07-2015 / 17:00:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    30 !
       
    31 
       
    32 compiledParserClass
       
    33     ^ Smalltalk at: self compiledParserClassName
       
    34 
       
    35     "Created: / 29-07-2015 / 16:54:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    36 !
       
    37 
       
    38 compiledParserClassName
       
    39     "Return the name of the compiled parser"
       
    40 
       
    41     ^ (self petitParserClass name , 'C_' , 
       
    42             "This is bit hacky!!"
       
    43             ((self compilerConfiguration isKindOf: PPCTokenizingConfiguration) ifTrue:[ 'Tokenizing' ] ifFalse:[ 'Universal' ])) asSymbol
       
    44 
       
    45     "Created: / 29-07-2015 / 16:54:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    46 !
       
    47 
       
    48 compiledScannerClassName
       
    49     "Return the name of the compiled parser"
       
    50 
       
    51     ^ (self petitParserClass name , 'C_Scanner') asSymbol
       
    52 !
       
    53 
       
    54 compilerConfiguration
       
    55     "Return configuration to use when compiling parser (as instance of PPCConfiguration)"
       
    56 
       
    57     ^ self subclassResponsibility
       
    58 
       
    59     "Created: / 29-07-2015 / 16:53:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    60 !
       
    61 
       
    62 parserClass
       
    63     ^ self compiledParserClass
       
    64 
       
    65     "Modified: / 29-07-2015 / 18:43:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    66 !
       
    67 
       
    68 parserInstanceFor: aSymbol
       
    69     ^ self parserClass new startSymbol: aSymbol
       
    70 
       
    71     "Modified: / 29-07-2015 / 18:43:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    72 !
       
    73 
       
    74 petitParser
       
    75     ^ self petitParserClass new
       
    76 
       
    77     "Created: / 29-07-2015 / 17:01:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    78 !
       
    79 
       
    80 petitParserClass
       
    81     ^ PPSmalltalkGrammar
       
    82 ! !
       
    83 
       
    84 !PPCSmalltalkGrammarTests methodsFor:'context'!
       
    85 
       
    86 context
       
    87 
       
    88     ^ PPCContext new 
       
    89 ! !
       
    90 
       
    91 !PPCSmalltalkGrammarTests methodsFor:'setup & teardown'!
       
    92 
       
    93 setUpBefore
       
    94     "Called before any of my tests is run (when resources are set up)"
       
    95     | time configuration |
       
    96 
       
    97     configuration := self compilerConfiguration.
       
    98     configuration arguments parserName: self compiledParserClassName.
       
    99     configuration arguments scannerName: self compiledScannerClassName.
       
   100         
       
   101     time := Time millisecondsToRun: [
       
   102         self petitParser compileWithConfiguration: configuration.
       
   103     ].
       
   104     Transcript show: self petitParserClass name ; show:' compiled in: '; show: time asString; show: 'ms'; cr.
       
   105 
       
   106     "Created: / 29-07-2015 / 16:29:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   107     "Modified: / 29-07-2015 / 18:40:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   108 !
       
   109 
       
   110 tearDownAfter
       
   111     "Called after all my tests are ryn(when resources are torn down)"
       
   112 
       
   113     "Created: / 29-07-2015 / 16:33:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   114 ! !
       
   115