/**
* Module containing the options for parsing PHP sources.
* The main strategy to use the options is 'parse-php-options'
*
* Each options comes with strategies used to retrieve the configuration
* setting. Some of them have default values which are defined in this
* module.
*
* @author Eric Bouwers
*/
module php/parse/options
/**
* Parse the options that are available within the tool. These are:
* - Set a specific release (4,5)
* - Set a specific start-symbol (Document,TopStatement,Statement,Expr)
* - Indicate wheter to preserve the comments as annotations
* - Indicate wheter to preserve the positions as annotations
*/
strategies
/**
* Processes the options for PHP. Separate strategy because the parsing
* can be done on several sources.
*
* @type AST -> AST
*/
process-parse-php-options =
if must-preserve-comments then
asfix-anno-comments(|["Comment"])
end
; if must-preserve-positions
then asfix-anno-position-info(|<get-current-php-file>)
end
; implode-asfix
; post-process-structures
/**
* Strategy combining the several parse-options
*/
parse-php-options =
release-options
+ symbol-option
+ preserve-comments-option
+ preserve-positions-option
+ include-path-option
/**
* Strategy combining several include-file options
*/
include-file-options =
include-file-simple-option
+ include-file-complex-option
+ print-included-files-option
/**
* Utility strategies for the default options available
* fromi Stratego.
*/
strategies
/**
* Get's the input path of the current tool. This means that it
* tries to read a config-setting or uses standard-input.
*
* @type _ -> path
*/
get-input-path =
<get-config> "-i" <+ !"stdin"
/**
* Option to set the release. Either PHP version 4 and 5.
*/
strategies
release-options =
ArgOption("-r" + "--release"
,set-release-option
,!HelpString("-r | --release r", "Use a specific release, either 4 or 5. [4]")
)
set-release-option =
where(
switch id
case "4" : !"PHP4"
case "5" : !"PHP5"
otherwise :
<fprint> (<stderr-stream>, ["parse-php: parsing for version ", <id>, " is not supported.\n"])
end
; <set-config> ("version",<id>)
)
/**
* Choice between two strategies based on the
* current PHP version
*/
php-choose-version(s4,s5) =
if <eq> (<get-config> "version","PHP5")
then s4
else s5
end
/**
* Option to set the startsymbol.
* This can be Document, TopStatement, Statement and Expr for now
*/
strategies
symbol-option =
ArgOption("-s" + "--start-symbol"
, set-start-symbol
, !HelpString("-s|--start-symbol s", "Start parsing with symbol s [Document]")
)
set-start-symbol =
<set-config> ("start-symbol", <id>)
get-start-symbol =
<get-config> "start-symbol" <+ !"Document"
/**
* Option to keep the comments as annotations. Is
* used in the parsing to add an exra tool to the pipe-line
* if wanted.
*/
strategies
preserve-comments-option =
Option("--preserve-comments"
, <set-preserve-comments> "yes"
, !HelpString("--preserve-comments", "Preserve source code
comments as annotations of the
abstract syntax tree. [off]")
)
set-preserve-comments =
<set-config> ("preserve-comments", <id>)
must-preserve-comments =
<get-config> "preserve-comments" => "yes"
/**
* Option to keep the positions as annotations. Is
* used in the parsing to add an exra tool to the pipe-line
* if wanted.
*/
strategies
preserve-positions-option =
Option("--preserve-positions"
, <set-preserve-positions> "yes"
, !HelpString("--preserve-positions", "Preserve source code positions in the
input file as annotations of the abstract syntax tree. [off]")
)
set-preserve-positions =
<set-config> ("preserve-positions", <id>)
must-preserve-positions =
<get-config> "preserve-positions" => "yes"
/**
* Option to set the include path.
*
*/
strategies
include-path-option =
ArgOption("--include-path"
,set-php-include-path
,!HelpString("--include-path path1(:path2:..)"
, "Set the include path using a list of directories separated with a colon [.]")
)
/**
* Sets the include path of the current process.
*
* @type String -> String
*/
set-php-include-path =
<set-config> ("php-include-path",<id>)
/**
* Returns the current include path. The default include path
* is '.'
*
* @type _ -> String
*/
get-php-include-path =
<get-config> "php-include-path"
<+ !"."
/**
* Options for including files
*/
strategies
/**
* Include file simple option.
* This option enables the simple inclusion. Including
* all files with exact strings.
*/
strategies
include-file-simple-option =
Option("--simple-inclusion"
, <set-include-file-simple> "yes"
, !HelpString("--simple-inclusion", "Include files in a simple matter. [off]")
)
set-include-file-simple =
<set-config> ("include-file-simple", <id>)
include-file-simple =
<get-config> "include-file-simple" => "yes"
/**
* Include file complex option.
* This option enables the complex inclusion. Including
* all files that can be found with the use of constant propagation
*/
strategies
include-file-complex-option =
Option("--complex-inclusion"
, <set-include-file-complex> "yes"
, !HelpString("--complex-inclusion", "Include files using constant propogation. [off]")
)
set-include-file-complex =
<set-config> ("include-file-complex", <id>)
include-file-complex =
<get-config> "include-file-complex" => "yes"
/**
* Print included files option
* Enables the printing of included files.
*/
strategies
print-included-files-option =
Option("--print-included-files"
, <set-print-included-files> "yes"
, !HelpString("--print-included-files", "Print the files that are included [off]")
)
set-print-included-files =
<set-config> ("print-included-files", <id>)
should-print-included-files =
<get-config> "print-included-files" => "yes"