compiler/PPCCompilationOptions.st
changeset 533 666372dbe307
parent 529 439c4057517f
child 534 a949c4fe44df
equal deleted inserted replaced
532:132d7898a2a1 533:666372dbe307
    19     ^ self basicNew 
    19     ^ self basicNew 
    20         initialize;
    20         initialize;
    21         yourself
    21         yourself
    22 ! !
    22 ! !
    23 
    23 
    24 !PPCCompilationOptions methodsFor:'accessing'!
       
    25 
       
    26 cacheFirstFollow
       
    27     ^ self at: #cacheFirstFollow ifAbsent: true
       
    28 !
       
    29 
       
    30 cacheFirstFollow: value
       
    31     self set: #cacheFirstFollow to: value.
       
    32 !
       
    33 
       
    34 codeGenerator
       
    35     self error: 'deprecated?'.
       
    36     ^ self at: #codeGenerator ifAbsent: PPCCodeGenerator
       
    37 !
       
    38 
       
    39 codeGenerator: value
       
    40     self set: #codeGenerator to: value.
       
    41 !
       
    42 
       
    43 debug
       
    44     ^ self at: #debug ifAbsent: true
       
    45 !
       
    46 
       
    47 debug: value
       
    48     self set: #debug to: value.
       
    49 !
       
    50 
       
    51 detectTokens
       
    52     ^ self at: #detectTokens ifAbsent: true
       
    53 !
       
    54 
       
    55 detectTokens: value
       
    56     self set: #detectTokens to: value.
       
    57 !
       
    58 
       
    59 generate
       
    60     ^ self at: #generate ifAbsent: true
       
    61 !
       
    62 
       
    63 generate: value
       
    64     ^ self set: #generate to: value
       
    65 !
       
    66 
       
    67 guards
       
    68     ^ self at: #guards ifAbsent: true
       
    69 !
       
    70 
       
    71 guards: value
       
    72     self set: #guards to: value.
       
    73 !
       
    74 
       
    75 inline
       
    76     ^ self at: #inline ifAbsent: true
       
    77 !
       
    78 
       
    79 inline: value
       
    80     self set: #inline to: value.
       
    81 !
       
    82 
       
    83 merge
       
    84     ^ self at: #merge ifAbsent: true
       
    85 !
       
    86 
       
    87 merge: value
       
    88     self set: #merge to: value.
       
    89 !
       
    90 
       
    91 parserName
       
    92     ^ self at: #parserName ifAbsent: #PPGeneratedParser 
       
    93 !
       
    94 
       
    95 parserName: value
       
    96     self set: #parserName to: value.
       
    97 !
       
    98 
       
    99 parserSuperclass
       
   100     ^ self at: #parserSuperclass ifAbsent: PPTokenizingCompiledParser
       
   101 !
       
   102 
       
   103 parserSuperclass: value
       
   104     self set: #parserSuperclass to: value.
       
   105 !
       
   106 
       
   107 profile
       
   108     ^ self at: #profile ifAbsent: false
       
   109 !
       
   110 
       
   111 profile: value
       
   112     self set: #profile to: value.
       
   113 !
       
   114 
       
   115 recognizingComponents
       
   116     ^ self at: #recognizingComponents ifAbsent: true
       
   117 !
       
   118 
       
   119 recognizingComponents: value
       
   120     self set: #recognizingComponents to: value.
       
   121 !
       
   122 
       
   123 scannerName
       
   124     ^ self at: #scannerName ifAbsent: #PPGeneratedScanner
       
   125 !
       
   126 
       
   127 scannerName: value
       
   128     self set: #scannerName to: value.
       
   129 !
       
   130 
       
   131 scannerSuperclass
       
   132     ^ self at: #scannerSuperclass ifAbsent: PPCDistinctScanner
       
   133 !
       
   134 
       
   135 scannerSuperclass: value
       
   136     self set: #scannerSuperclass to: value.
       
   137 !
       
   138 
       
   139 specialize
       
   140     ^ self at: #specialize ifAbsent: true
       
   141 !
       
   142 
       
   143 specialize: value
       
   144     self set: #specialize to: value.
       
   145 !
       
   146 
       
   147 tokenize
       
   148     ^ self at: #tokenize ifAbsent: true
       
   149 !
       
   150 
       
   151 tokenize: value
       
   152     self set: #tokenize to: value.
       
   153 ! !
       
   154 
       
   155 !PPCCompilationOptions methodsFor:'initialization'!
    24 !PPCCompilationOptions methodsFor:'initialization'!
   156 
    25 
   157 initialize
    26 initialize
   158     super initialize.
    27     super initialize.
   159     options := IdentityDictionary new
    28     options := IdentityDictionary new
   160 ! !
    29 ! !
   161 
    30 
       
    31 !PPCCompilationOptions methodsFor:'options'!
       
    32 
       
    33 mode
       
    34     ^ self at: #mode ifAbsent: #JIT
       
    35 
       
    36     "Created: / 26-08-2015 / 23:18:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    37 !
       
    38 
       
    39 mode: mode
       
    40     "Set the compilation mode - valid values are #JIT or #AOT.
       
    41 
       
    42      #JIT mode put less constraints on the original pure PetitParser
       
    43        parser (such as action blocks are not required to be purely functional,
       
    44        support mixing of compiled parsing code with custom PPParsers and so on).
       
    45        However, JIT-compiled parser class SHOULD NOT be commited into the
       
    46        repository - it won't work when loaded back. 
       
    47 
       
    48      #AOT mode allows for parser to be pre-compiled and generated code
       
    49        to be commited to repository. Thus, the deployed application don't need
       
    50        to contain full PetitCompiler. However, this is at cost of more contraints
       
    51        being put on the original Petit Parser. In other words, not all PetitParser
       
    52        parser may be compiled in AOT mode.
       
    53        WARNING: #AOT mode is not yet fully supported, do not use!!
       
    54     "
       
    55 
       
    56     (#(JIT AOT) includes: mode) ifFalse:[ 
       
    57         PPCCompilationError new signal: 'Invalid mode: option value - must be either #JIT or #AOT'.
       
    58     ].
       
    59     mode == #AOT ifTrue:[ 
       
    60         PPCCompilationWarning new signal: '#AOT mode not yet supported'.
       
    61     ].
       
    62     self at: #mode put: mode
       
    63 
       
    64     "Created: / 26-08-2015 / 23:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    65 !
       
    66 
       
    67 parserName
       
    68     ^ self at: #parserName ifAbsent: #PPGeneratedParser
       
    69 
       
    70     "Modified (format): / 26-08-2015 / 23:04:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    71 !
       
    72 
       
    73 parserName: aSymbol
       
    74     "Sets the name of the generated parser class.
       
    75      Defaults to #PPGeneratedParser."
       
    76 
       
    77     self set: #parserName to: aSymbol.
       
    78 
       
    79     "Modified (comment): / 26-08-2015 / 23:05:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    80 !
       
    81 
       
    82 scannerName
       
    83     ^ self at: #scannerName ifAbsent: #PPGeneratedScanner
       
    84 !
       
    85 
       
    86 scannerName: value
       
    87     "Sets the name of the generated parser class.
       
    88      Defaults to #PPGeneratedScanner."    
       
    89 
       
    90     self set: #scannerName to: value.
       
    91 
       
    92     "Modified (comment): / 26-08-2015 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 !
       
    94 
       
    95 tokenize
       
    96     ^ self at: #tokenize ifAbsent: true
       
    97 !
       
    98 
       
    99 tokenize: aBoolean
       
   100     "Build tokenizing parser, i.e., build scanner that tokenizes the input and then
       
   101      parser consuming tokens produced by scanner.
       
   102 
       
   103      Tokenizing parser more resemble hand-written top-down parser and
       
   104      makes hand-tuning of the parser / scanner easier. However, not all
       
   105      PetitParsers may be tokenized.
       
   106 
       
   107      Default value is true. If the compilation fails, try to set it to
       
   108      false
       
   109     "    
       
   110     self set: #tokenize to: aBoolean.
       
   111 
       
   112     "Modified (comment): / 26-08-2015 / 23:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   113 ! !
       
   114 
       
   115 !PPCCompilationOptions methodsFor:'options - undocumented (do not use)'!
       
   116 
       
   117 cacheFirstFollow
       
   118     ^ self at: #cacheFirstFollow ifAbsent: true
       
   119 !
       
   120 
       
   121 cacheFirstFollow: value
       
   122     self set: #cacheFirstFollow to: value.
       
   123 !
       
   124 
       
   125 debug
       
   126     ^ self at: #debug ifAbsent: true
       
   127 !
       
   128 
       
   129 debug: value
       
   130     self set: #debug to: value.
       
   131 !
       
   132 
       
   133 detectTokens
       
   134     ^ self at: #detectTokens ifAbsent: true
       
   135 !
       
   136 
       
   137 detectTokens: value
       
   138     self set: #detectTokens to: value.
       
   139 !
       
   140 
       
   141 generate
       
   142     ^ self at: #generate ifAbsent: true
       
   143 !
       
   144 
       
   145 generate: value
       
   146     ^ self set: #generate to: value
       
   147 !
       
   148 
       
   149 guards
       
   150     ^ self at: #guards ifAbsent: true
       
   151 !
       
   152 
       
   153 guards: value
       
   154     self set: #guards to: value.
       
   155 !
       
   156 
       
   157 inline
       
   158     ^ self at: #inline ifAbsent: true
       
   159 !
       
   160 
       
   161 inline: value
       
   162     self set: #inline to: value.
       
   163 !
       
   164 
       
   165 merge
       
   166     ^ self at: #merge ifAbsent: true
       
   167 !
       
   168 
       
   169 merge: value
       
   170     self set: #merge to: value.
       
   171 !
       
   172 
       
   173 parserSuperclass
       
   174     ^ self at: #parserSuperclass ifAbsent: PPTokenizingCompiledParser
       
   175 !
       
   176 
       
   177 parserSuperclass: value
       
   178     self set: #parserSuperclass to: value.
       
   179 !
       
   180 
       
   181 profile
       
   182     ^ self at: #profile ifAbsent: false
       
   183 !
       
   184 
       
   185 profile: value
       
   186     self set: #profile to: value.
       
   187 !
       
   188 
       
   189 recognizingComponents
       
   190     ^ self at: #recognizingComponents ifAbsent: true
       
   191 !
       
   192 
       
   193 recognizingComponents: value
       
   194     self set: #recognizingComponents to: value.
       
   195 !
       
   196 
       
   197 scannerSuperclass
       
   198     ^ self at: #scannerSuperclass ifAbsent: PPCDistinctScanner
       
   199 !
       
   200 
       
   201 scannerSuperclass: value
       
   202     self set: #scannerSuperclass to: value.
       
   203 !
       
   204 
       
   205 specialize
       
   206     ^ self at: #specialize ifAbsent: true
       
   207 !
       
   208 
       
   209 specialize: value
       
   210     self set: #specialize to: value.
       
   211 ! !
       
   212 
   162 !PPCCompilationOptions methodsFor:'private'!
   213 !PPCCompilationOptions methodsFor:'private'!
   163 
   214 
   164 at: symbol ifAbsent: defaultValue
   215 at: symbol ifAbsent: defaultValue
   165     ^ options at: symbol ifAbsent: [ ^ defaultValue  ]
   216     ^ options at: symbol ifAbsent: [ ^ defaultValue  ]
   166 !
   217 !