aboutsummaryrefslogtreecommitdiffstats
path: root/Praspel.php
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-02-20 11:31:31 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-02-20 11:31:31 +0100
commitc63b23473f006b2d0edd501293b58d3982940938 (patch)
treebf6cd9192c8bb8500090702a45cae6e42229fc49 /Praspel.php
parentee13ce70bc01025e873351486d90bd69ba7ece47 (diff)
downloadPraspel-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.php58
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);
+}}
}