diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-02-20 11:31:31 +0100 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-02-20 11:31:31 +0100 |
commit | c63b23473f006b2d0edd501293b58d3982940938 (patch) | |
tree | bf6cd9192c8bb8500090702a45cae6e42229fc49 /Praspel.php | |
parent | ee13ce70bc01025e873351486d90bd69ba7ece47 (diff) | |
download | Praspel-c63b23473f006b2d0edd501293b58d3982940938.zip Praspel-c63b23473f006b2d0edd501293b58d3982940938.tar.gz Praspel-c63b23473f006b2d0edd501293b58d3982940938.tar.bz2 |
Add the interprete() method & praspel() function.
Diffstat (limited to 'Praspel.php')
-rw-r--r-- | Praspel.php | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/Praspel.php b/Praspel.php index bee70ed..e7ac646 100644 --- a/Praspel.php +++ b/Praspel.php @@ -41,7 +41,22 @@ from('Hoa') /** * \Hoa\Praspel\Exception */ --> import('Praspel.Exception.~'); +-> import('Praspel.Exception.~') + +/** + * \Hoa\Praspel\Visitor\Interpreter + */ +-> import('Praspel.Visitor.Interpreter') + +/** + * \Hoa\Compiler\Llk + */ +-> import('Compiler.Llk.~') + +/** + * \Hoa\File\Read + */ +-> import('File.Read'); } @@ -241,6 +256,47 @@ class Praspel { return $this->_callable; } + + /** + * Short interpreter. + * + * @access public + * @param string $praspel Praspel. + * @return \Hoa\Praspel\Model\Clause + */ + public static function interprete ( $praspel ) { + + static $_compiler = null; + static $_interpreter = null; + + if(null === $_compiler) + $_compiler = \Hoa\Compiler\Llk::load( + new \Hoa\File\Read('hoa://Library/Praspel/Grammar.pp') + ); + + if(null === $_interpreter) + $_interpreter = new Visitor\Interpreter(); + + $ast = $_compiler->parse($praspel); + + return $_interpreter->visit($ast); + } +} + } +namespace { + +/** + * Alias of \Hoa\Praspel::interprete(). + * + * @access public + * @param string $praspel Praspel + * @return \Hoa\Praspel\Model\Clause + */ +if(!ƒ('praspel')) { +function praspel ( $praspel ) { + + return \Hoa\Praspel::interprete($praspel); +}} } |