-
Notifications
You must be signed in to change notification settings - Fork 117
Add PI processing support for common phrases #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -797,6 +797,34 @@ function getFileModificationHistory(): array { | |
} | ||
} | ||
|
||
echo "Process PI nodes...\n"; | ||
if (!$ac['LANG'] == 'en') { | ||
if (file_exists($srcdir . '/pi_processing/langs/' . $ac['LANG'] . '.php')) { | ||
require_once $srcdir . '/pi_processing/langs/' . $ac['LANG'] . '.php'; | ||
} | ||
} | ||
require_once $srcdir . '/pi_processing/langs/en.php'; | ||
require_once $srcdir . '/pi_processing/processors.php'; | ||
$xpath = new DOMXPath($dom); | ||
foreach ($xpath->query('//processing-instruction()') as $pi) { | ||
if (!str_starts_with($pi->target, 'phpdoc')) { | ||
continue; | ||
} | ||
// Don't care about generic phpdoc PI target | ||
if ($pi->target === 'phpdoc') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplication with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because we have a bunch of PI instruction that are just Maybe this design is crap, but I didn't want to figure out how to parse the function to call |
||
continue; | ||
} | ||
|
||
var_dump($pi->target, $pi->data); | ||
Girgias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$fn = match ($pi->target) { | ||
'phpdoc_error_ValueError_between' => error_section_value_error_between(...), | ||
'phpdoc_error_ValueError_between_changelog' => error_section_value_error_between_changelog(...), | ||
}; | ||
$data = explode(' ', $pi->data); | ||
$node = $fn($dom, ...$data); | ||
$pi->parentNode->insertBefore($node, $pi); | ||
} | ||
|
||
echo "Validating {$ac["INPUT_FILENAME"]}... "; | ||
flush(); | ||
if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
if (!defined('VALUE_ERROR_BETWEEN_ERROR_SECTION')) { | ||
define('VALUE_ERROR_BETWEEN_ERROR_SECTION', <<<'CONTENT' | ||
<simpara xmlns="http://docbook.org/ns/docbook"> | ||
Throws a <exceptionname>ValueError</exceptionname> if <parameter>PARAMETER_NAME</parameter> | ||
is less than MIN_TAG or greater than MAX_TAG. | ||
</simpara> | ||
CONTENT | ||
); | ||
} | ||
|
||
if (!defined('VALUE_ERROR_BETWEEN_CHANGELOG')) { | ||
define('VALUE_ERROR_BETWEEN_CHANGELOG', <<<'CONTENT' | ||
<row xmlns="http://docbook.org/ns/docbook"> | ||
<entry>VERSION</entry> | ||
<entry> | ||
A <exceptionname>ValueError</exceptionname> is now thrown if | ||
<parameter>PARAMETER_NAME</parameter> is less than MIN_TAG | ||
or greater than MAX_TAG | ||
</entry> | ||
</row> | ||
CONTENT | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
const VALUE_ERROR_BETWEEN_ERROR_SECTION = <<<'CONTENT' | ||
<simpara> | ||
Lance une <exceptionname>ValueError</exceptionname> si <parameter>PARAMETER_NAME</parameter> | ||
est moins que MIN_TAG ou plus grand que MAX_TAG. | ||
</simpara> | ||
CONTENT; | ||
|
||
const VALUE_ERROR_BETWEEN_CHANGELOG = <<<'CONTENT' | ||
<row> | ||
<entry>VERSION</entry> | ||
<entry> | ||
Une <exceptionname>ValueError</exceptionname> est désormais lancé si | ||
<parameter>PARAMETER_NAME</parameter> est moins que MIN_TAG ou plus grand que MAX_TAG | ||
</entry> | ||
</row> | ||
CONTENT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
function error_section_value_error_between( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some duplication between these functions which would be nice to somehow get rid of; at least it should be possible to move the import to the caller. Note that there's also an |
||
DOMDocument $dom, | ||
string $parameter, | ||
string $min, | ||
string $max | ||
): DOMElement { | ||
$min_tag_name = is_numeric($min) ? 'literal' : 'constant'; | ||
$max_tag_name = is_numeric($max) ? 'literal' : 'constant'; | ||
|
||
$min_tag = '<' . $min_tag_name . '>' . $min . '</' . $min_tag_name . '>'; | ||
$max_tag = '<' . $max_tag_name . '>' . $max . '</' . $max_tag_name . '>'; | ||
|
||
$xml = str_replace( | ||
['PARAMETER_NAME', 'MIN_TAG', 'MAX_TAG'], | ||
[$parameter, $min_tag, $max_tag], | ||
VALUE_ERROR_BETWEEN_ERROR_SECTION, | ||
); | ||
$localDom = new DOMDocument(); | ||
$localDom->loadXML($xml); | ||
return $dom->importNode($localDom->documentElement, true); | ||
} | ||
|
||
function error_section_value_error_between_changelog( | ||
DOMDocument $dom, | ||
string $version, | ||
string $parameter, | ||
string $min, | ||
string $max | ||
): DOMElement { | ||
$min_tag_name = is_numeric($min) ? 'literal' : 'constant'; | ||
$max_tag_name = is_numeric($max) ? 'literal' : 'constant'; | ||
|
||
$min_tag = '<' . $min_tag_name . '>' . $min . '</' . $min_tag_name . '>'; | ||
$max_tag = '<' . $max_tag_name . '>' . $max . '</' . $max_tag_name . '>'; | ||
|
||
$xml = str_replace( | ||
['VERSION', 'PARAMETER_NAME', 'MIN_TAG', 'MAX_TAG'], | ||
[$version, $parameter, $min_tag, $max_tag], | ||
VALUE_ERROR_BETWEEN_CHANGELOG, | ||
); | ||
$localDom = new DOMDocument(); | ||
$localDom->loadXML($xml); | ||
return $dom->importNode($localDom->documentElement, true); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.