summaryrefslogtreecommitdiff
path: root/inc/parser
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-01-19 11:39:37 -0800
committerAndreas Gohr <andi@splitbrain.org>2014-01-19 11:39:37 -0800
commit48e8e6fe70b186145f7d40faaf95708e40d6dcb2 (patch)
tree24a9488ca98f6a2cc4915fea8cf859245e678dae /inc/parser
parent0df76c4421bf3fa2c187d25b9409b5225850d1f5 (diff)
parent5a3e1f53b18728d500b3505f4fbd8c78848120e0 (diff)
downloadrpg-48e8e6fe70b186145f7d40faaf95708e40d6dcb2.tar.gz
rpg-48e8e6fe70b186145f7d40faaf95708e40d6dcb2.tar.bz2
Merge pull request #496 from splitbrain/plugindedup
remove some code duplication from syntax plugins
Diffstat (limited to 'inc/parser')
-rw-r--r--inc/parser/parser.php80
1 files changed, 64 insertions, 16 deletions
diff --git a/inc/parser/parser.php b/inc/parser/parser.php
index 1f14b98a3..252bd9170 100644
--- a/inc/parser/parser.php
+++ b/inc/parser/parser.php
@@ -125,43 +125,91 @@ class Doku_Parser {
}
//-------------------------------------------------------------------
+
/**
- * This class and all the subclasses below are
- * used to reduce the effort required to register
- * modes with the Lexer. For performance these
- * could all be eliminated later perhaps, or
- * the Parser could be serialized to a file once
- * all modes are registered
+ * Class Doku_Parser_Mode_Interface
*
- * @author Harry Fuecks <hfuecks@gmail.com>
+ * Defines a mode (syntax component) in the Parser
*/
-class Doku_Parser_Mode {
+interface Doku_Parser_Mode_Interface {
+ /**
+ * returns a number used to determine in which order modes are added
+ */
+ public function getSort();
+
+ /**
+ * Called before any calls to connectTo
+ */
+ function preConnect();
+
+ /**
+ * Connects the mode
+ *
+ * @param string $mode
+ */
+ function connectTo($mode);
/**
+ * Called after all calls to connectTo
+ */
+ function postConnect();
+
+ /**
+ * Check if given mode is accepted inside this mode
+ *
+ * @param string $mode
+ * @return bool
+ */
+ function accepts($mode);
+}
+
+/**
+ * This class and all the subclasses below are used to reduce the effort required to register
+ * modes with the Lexer.
+ *
+ * @author Harry Fuecks <hfuecks@gmail.com>
+ */
+class Doku_Parser_Mode implements Doku_Parser_Mode_Interface {
+ /**
* @var Doku_Lexer $Lexer
*/
var $Lexer;
-
var $allowedModes = array();
- // returns a number used to determine in which order modes are added
function getSort() {
trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING);
}
- // Called before any calls to connectTo
function preConnect() {}
-
- // Connects the mode
function connectTo($mode) {}
-
- // Called after all calls to connectTo
function postConnect() {}
-
function accepts($mode) {
return in_array($mode, (array) $this->allowedModes );
}
+}
+
+/**
+ * Basically the same as Doku_Parser_Mode but extends from DokuWiki_Plugin
+ *
+ * Adds additional functions to syntax plugins
+ */
+class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mode_Interface {
+ /**
+ * @var Doku_Lexer $Lexer
+ */
+ var $Lexer;
+ var $allowedModes = array();
+
+ function getSort() {
+ trigger_error('getSort() not implemented in '.get_class($this), E_USER_WARNING);
+ }
+ function preConnect() {}
+ function connectTo($mode) {}
+ function postConnect() {}
+ function accepts($mode) {
+ return in_array($mode, (array) $this->allowedModes );
+ }
}
//-------------------------------------------------------------------