Example #1
0
 /**
  * Handles the parsing process. It's recommended to use Easy_Parse instead,
  * which wraps this function (and others).
  * \return a string which is formatted with an internal tagging spec.
  *    But the caller should not worry about that, it's only for recursion.
  *
  * \throw Exception in the event that the PCRE module fails somehow. The
  *    error is given in the exception message, but this is likely down to an
  *    exceptionally large string which is triggering the PCRE backtrack limit.
  *    The parser should survive, but the string will not by syntax highlighted
  * 
  */
 public function Parse_Full()
 {
     $this->DoStartEnds();
     $pos = -1;
     $parse_nothing = false;
     $parse_everything = false;
     // no legal start/end
     if (count($this->grammar->ignore_outside) && (!count($this->starts) || !count($this->ends))) {
         // Strict mode - don't parse anything
         if ($this->grammar->ignore_outside_strict) {
             $parse_nothing = true;
         }
     }
     if (!count($this->grammar->ignore_outside)) {
         $parse_everything = true;
     }
     if ($parse_nothing) {
         $this->output = $this->input_src;
     } else {
         if ($parse_everything) {
             $this->parse_all = true;
         }
         $this->ParseDelimiters();
         if ($parse_everything) {
             $this->output = str_replace("<&START>", "", $this->output);
             $this->output = str_replace("<&END>", "", $this->output);
             $this->output = $this->Parse_Regex_Wrapper_Callback(array(0, $this->output));
         } else {
             $this->SplitStartEnds();
         }
     }
     if ($this->output === null && preg_last_error() !== PREG_NO_ERROR) {
         throw new Exception("PCRE error: " . pcre_error_decode(preg_last_error()));
         $this->output = $this->input;
         return $this->input;
     }
     if ($this->grammar->child_grammar !== null) {
         $highlighter = new Luminous();
         $highlighter->verbosity = $this->verbosity;
         $highlighter->SetSource($this->output);
         $highlighter->SetGrammar($this->grammar->child_grammar);
         $highlighter->SetExtractionsOffset($this->num_extractions + $this->extractions_offset);
         $highlighter->FinaliseSetup();
         $this->output = $highlighter->Parse_Full();
     }
     $this->DoReplacements();
     return $this->output;
 }