diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-05-28 15:37:55 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-05-28 15:37:55 +0200 |
commit | 4c44b40429c2d15895cfb77d08d7c78781086a16 (patch) | |
tree | 6653fea7769025532ff69a87ff517b85a0ac0f51 /Praspel.php | |
parent | 186c66d8892dc531b893907723b77d31a91e82d1 (diff) | |
download | Praspel-4c44b40429c2d15895cfb77d08d7c78781086a16.zip Praspel-4c44b40429c2d15895cfb77d08d7c78781086a16.tar.gz Praspel-4c44b40429c2d15895cfb77d08d7c78781086a16.tar.bz2 |
Add the extractFromComment() method.
Diffstat (limited to 'Praspel.php')
-rw-r--r-- | Praspel.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Praspel.php b/Praspel.php index e7ac646..3a89a44 100644 --- a/Praspel.php +++ b/Praspel.php @@ -281,6 +281,33 @@ class Praspel { return $_interpreter->visit($ast); } + + /** + * Extract Praspel (as a string) from a comment. + * + * @access public + * @param string $comment Comment. + * @return string + * @throw \Hoa\Praspel\Exception + */ + public static function extractFromComment ( $comment ) { + + $i = preg_match('#/\*(.*?)\*/#s', $comment, $matches); + + if(0 === $i) + throw new Exception( + 'Not able to extract Praspel from the following ' . + 'comment:' . "\n" . '%s', 1, $comment); + + $i = preg_match_all('#^[\s\*]*([^\n]*)$#m', $matches[1], $maatches); + + if(0 === $i) + throw new Exception( + 'Not able to extract Praspel from the following ' . + 'comment:' . "\n" . '%s', 2, $comment); + + return trim(implode("\n", $maatches[1])); + } } } |