compiler/PPCCompilationOptions.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 26 Aug 2015 23:34:48 +0100
changeset 533 666372dbe307
parent 529 439c4057517f
child 534 a949c4fe44df
permissions -rw-r--r--
PPCConfiguration refactoring: [5/10]: Commented options in PPCCompilationOptions. So it's more clear for what the option is and how to use it. This is a base for user-documentation as options are meant to be set by the end user.

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

Object subclass:#PPCCompilationOptions
	instanceVariableNames:'options'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Core'
!

!PPCCompilationOptions class methodsFor:'as yet unclassified'!

default
    ^ self new
!

new
    ^ self basicNew 
        initialize;
        yourself
! !

!PPCCompilationOptions methodsFor:'initialization'!

initialize
    super initialize.
    options := IdentityDictionary new
! !

!PPCCompilationOptions methodsFor:'options'!

mode
    ^ self at: #mode ifAbsent: #JIT

    "Created: / 26-08-2015 / 23:18:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

mode: mode
    "Set the compilation mode - valid values are #JIT or #AOT.

     #JIT mode put less constraints on the original pure PetitParser
       parser (such as action blocks are not required to be purely functional,
       support mixing of compiled parsing code with custom PPParsers and so on).
       However, JIT-compiled parser class SHOULD NOT be commited into the
       repository - it won't work when loaded back. 

     #AOT mode allows for parser to be pre-compiled and generated code
       to be commited to repository. Thus, the deployed application don't need
       to contain full PetitCompiler. However, this is at cost of more contraints
       being put on the original Petit Parser. In other words, not all PetitParser
       parser may be compiled in AOT mode.
       WARNING: #AOT mode is not yet fully supported, do not use!!
    "

    (#(JIT AOT) includes: mode) ifFalse:[ 
        PPCCompilationError new signal: 'Invalid mode: option value - must be either #JIT or #AOT'.
    ].
    mode == #AOT ifTrue:[ 
        PPCCompilationWarning new signal: '#AOT mode not yet supported'.
    ].
    self at: #mode put: mode

    "Created: / 26-08-2015 / 23:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parserName
    ^ self at: #parserName ifAbsent: #PPGeneratedParser

    "Modified (format): / 26-08-2015 / 23:04:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parserName: aSymbol
    "Sets the name of the generated parser class.
     Defaults to #PPGeneratedParser."

    self set: #parserName to: aSymbol.

    "Modified (comment): / 26-08-2015 / 23:05:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

scannerName
    ^ self at: #scannerName ifAbsent: #PPGeneratedScanner
!

scannerName: value
    "Sets the name of the generated parser class.
     Defaults to #PPGeneratedScanner."    

    self set: #scannerName to: value.

    "Modified (comment): / 26-08-2015 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tokenize
    ^ self at: #tokenize ifAbsent: true
!

tokenize: aBoolean
    "Build tokenizing parser, i.e., build scanner that tokenizes the input and then
     parser consuming tokens produced by scanner.

     Tokenizing parser more resemble hand-written top-down parser and
     makes hand-tuning of the parser / scanner easier. However, not all
     PetitParsers may be tokenized.

     Default value is true. If the compilation fails, try to set it to
     false
    "    
    self set: #tokenize to: aBoolean.

    "Modified (comment): / 26-08-2015 / 23:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCCompilationOptions methodsFor:'options - undocumented (do not use)'!

cacheFirstFollow
    ^ self at: #cacheFirstFollow ifAbsent: true
!

cacheFirstFollow: value
    self set: #cacheFirstFollow to: value.
!

debug
    ^ self at: #debug ifAbsent: true
!

debug: value
    self set: #debug to: value.
!

detectTokens
    ^ self at: #detectTokens ifAbsent: true
!

detectTokens: value
    self set: #detectTokens to: value.
!

generate
    ^ self at: #generate ifAbsent: true
!

generate: value
    ^ self set: #generate to: value
!

guards
    ^ self at: #guards ifAbsent: true
!

guards: value
    self set: #guards to: value.
!

inline
    ^ self at: #inline ifAbsent: true
!

inline: value
    self set: #inline to: value.
!

merge
    ^ self at: #merge ifAbsent: true
!

merge: value
    self set: #merge to: value.
!

parserSuperclass
    ^ self at: #parserSuperclass ifAbsent: PPTokenizingCompiledParser
!

parserSuperclass: value
    self set: #parserSuperclass to: value.
!

profile
    ^ self at: #profile ifAbsent: false
!

profile: value
    self set: #profile to: value.
!

recognizingComponents
    ^ self at: #recognizingComponents ifAbsent: true
!

recognizingComponents: value
    self set: #recognizingComponents to: value.
!

scannerSuperclass
    ^ self at: #scannerSuperclass ifAbsent: PPCDistinctScanner
!

scannerSuperclass: value
    self set: #scannerSuperclass to: value.
!

specialize
    ^ self at: #specialize ifAbsent: true
!

specialize: value
    self set: #specialize to: value.
! !

!PPCCompilationOptions methodsFor:'private'!

at: symbol ifAbsent: defaultValue
    ^ options at: symbol ifAbsent: [ ^ defaultValue  ]
!

set: symbol to: defaultValue
    ^ options at: symbol put: defaultValue 
! !