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