/** * Prepare the source code for parsing */ protected function _parsePreProcess() { // Strip newlines to common form $this->_source = str_replace("\r\n", "\n", $this->_source); $this->_source = str_replace("\r", "\n", $this->_source); // Get data // This just defines a few functions (geshi_$langname_$dialectname[_$contextname]) $file = $this->_getLanguageDataFile(); if (geshi_can_include($file)) { require_once $file; } else { $file = GESHI_LANGUAGES_ROOT . 'default/default.php'; if (geshi_can_include($file)) { require_once $file; } else { // @todo [blocking 1.1.2] graceful error handling when a // language does not exist trigger_error('Language does not exist', E_USER_ERROR); } } // Build the context tree. This creates a new context which calls a function which may // define children contexts etc. etc. $this->_rootContext = new GeSHiCodeContext($this->_language); //Work around a PHP5 bug(???) prohibiting to override $this GeSHiContext::_initContext($this->_rootContext, $this->_language); // Load the code parser if necessary $language_name = substr($this->_language, 0, strpos($this->_language, '/')); $codeparser_name = 'geshi' . $language_name . 'codeparser'; if (!class_exists($codeparser_name, false)) { $codeparser_file = GESHI_LANGUAGES_ROOT . $language_name . '/' . "class.{$codeparser_name}.php"; if (geshi_can_include($codeparser_file)) { /** Get the GeSHiCodeParser class */ require_once GESHI_CLASSES_ROOT . 'class.geshicodeparser.php'; /** Get the language code parser */ require_once $codeparser_file; } } // Now the code parser (if existing) has been included, create it if it is defined if (class_exists($codeparser_name, false)) { // Get the code parser $codeparser = new $codeparser_name($this->_language); // Call the source preprocessing method $this->_source = $codeparser->sourcePreProcess($this->_source); // Tell the styler about the code parser $this->_styler->setCodeParser($codeparser); } // Reset the styler parse data $this->_styler->resetParseData(); // Remove contexts from the parse tree that aren't interesting $this->_rootContext->trimUselessChildren($this->_source); return true; }
/** * Adds a child to this context that is actually a language * * e.g. doxygen within PHP */ function addChildLanguage($name, $start_delimiters, $end_delimiters, $case_sensitive = false, $parse_delimiter_flag = GESHI_CHILD_PARSE_NONE) { /** Get function info for the child language */ require_once GESHI_LANGUAGES_ROOT . $name . '.php'; $context = new GeSHiCodeContext($name); GeSHiContext::_initContext($context, $name); $context->addDelimiters($start_delimiters, $end_delimiters, $case_sensitive); $context->parseDelimiters($parse_delimiter_flag); // @todo setter $context->_isChildLanguage = true; $this->_childContexts[] = $context; }