Changeset View
Changeset View
Standalone View
Standalone View
support/xhpast/bin/xhpast-generate-nodes.php
- This file was moved from support/xhpast/generate_nodes.php.
#!/usr/bin/env php | #!/usr/bin/env php | ||||
<?php | <?php | ||||
require_once dirname(__FILE__).'/../../scripts/__init_script__.php'; | $arcanist_root = dirname(dirname(dirname(dirname(__FILE__)))); | ||||
require_once $arcanist_root.'/support/init/init-script.php'; | |||||
$xhpast_root = dirname(dirname(__FILE__)); | |||||
$hpp_outpath = $xhpast_root.'/node_names.hpp'; | |||||
$php_outpath = $xhpast_root.'/parser_nodes.php'; | |||||
$offset = 9000; | $offset = 9000; | ||||
$nodes = array( | $nodes = array( | ||||
'n_PROGRAM', | 'n_PROGRAM', | ||||
'n_SYMBOL_NAME', | 'n_SYMBOL_NAME', | ||||
'n_HALT_COMPILER', | 'n_HALT_COMPILER', | ||||
'n_NAMESPACE', | 'n_NAMESPACE', | ||||
'n_STATEMENT', | 'n_STATEMENT', | ||||
'n_EMPTY', | 'n_EMPTY', | ||||
'n_STATEMENT_LIST', | 'n_STATEMENT_LIST', | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | |||||
$nodes = array_combine( | $nodes = array_combine( | ||||
array_values($nodes), | array_values($nodes), | ||||
range($offset, $offset + count($nodes) - 1)); | range($offset, $offset + count($nodes) - 1)); | ||||
$hpp = ''; | $hpp = ''; | ||||
foreach ($nodes as $node => $value) { | foreach ($nodes as $node => $value) { | ||||
$hpp .= "#define {$node} {$value}\n"; | $hpp .= "#define {$node} {$value}\n"; | ||||
} | } | ||||
Filesystem::writeFile( | |||||
Filesystem::resolvePath('node_names.hpp', dirname(__FILE__)), | |||||
$hpp); | Filesystem::writeFile($hpp_outpath, $hpp); | ||||
echo pht('Wrote C++ definition.')."\n"; | echo pht('Wrote C++ definition.')."\n"; | ||||
$at = '@'; | $at = '@'; | ||||
$php = <<<EOPHP | $php = <<<EOPHP | ||||
<?php | <?php | ||||
/** | /** | ||||
* {$at}generated | * {$at}generated | ||||
* {$at}undivinable | * {$at}undivinable | ||||
*/ | */ | ||||
function xhp_parser_node_constants() { | function xhp_parser_node_constants() { | ||||
return array( | return array( | ||||
EOPHP; | EOPHP; | ||||
foreach ($nodes as $node => $value) { | foreach ($nodes as $node => $value) { | ||||
$php .= " {$value} => '{$node}',\n"; | $php .= " {$value} => '{$node}',\n"; | ||||
} | } | ||||
$php .= <<<EOPHP | $php .= <<<EOPHP | ||||
); | ); | ||||
} | } | ||||
EOPHP; | EOPHP; | ||||
Filesystem::writeFile( | |||||
Filesystem::resolvePath('parser_nodes.php', dirname(__FILE__)), | Filesystem::writeFile($php_outpath, $php); | ||||
$php); | |||||
echo pht('Wrote PHP definition.')."\n"; | echo pht('Wrote PHP definition.')."\n"; |