|
|
|
@ -44,6 +44,10 @@ class Parser { |
|
|
|
|
return $char; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static function StripBackslashes(string $text) : string { |
|
|
|
|
return stripslashes($text); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PARSING |
|
|
|
|
|
|
|
|
|
private function parseBold() : DOMNode { |
|
|
|
@ -122,7 +126,16 @@ class Parser { |
|
|
|
|
if ((!$paragraph && $this->current()->type === TokenType::EOL) || |
|
|
|
|
($paragraph && ($this->current()->type === TokenType::EOL && $this->next()->type === TokenType::EOL)) || $this->current()->type === TokenType::EOF) |
|
|
|
|
break; |
|
|
|
|
if ($this->current()->type === TokenType::ASTERISK) { |
|
|
|
|
if ($this->current()->type === TokenType::BACKSLASH && in_array($this->next()->type, [ |
|
|
|
|
TokenType::BACKTICK, |
|
|
|
|
TokenType::ASTERISK, |
|
|
|
|
TokenType::LBRACKET, |
|
|
|
|
TokenType::BANG |
|
|
|
|
])) { |
|
|
|
|
$this->consume()->data; // backslash |
|
|
|
|
$buffer .= $this->consume()->data; |
|
|
|
|
continue; |
|
|
|
|
} elseif ($this->current()->type === TokenType::ASTERISK) { |
|
|
|
|
$clearBuffer(); |
|
|
|
|
if ($this->next()->type === TokenType::ASTERISK) { |
|
|
|
|
$this->consume(); |
|
|
|
@ -143,20 +156,20 @@ class Parser { |
|
|
|
|
$clearBuffer(); |
|
|
|
|
array_push($elms, $links); |
|
|
|
|
} else { |
|
|
|
|
$buffer .= $this->consume()->data; |
|
|
|
|
$buffer .= self::StripBackslashes($this->consume()->data); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} elseif ($this->current()->type === TokenType::BANG) { |
|
|
|
|
$bang = $this->consume(); |
|
|
|
|
if ($this->current()->type !== TokenType::LBRACKET) { |
|
|
|
|
$buffer .= $this->consume()->data; |
|
|
|
|
$buffer .= self::StripBackslashes($this->consume()->data); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$lbracket = $this->consume(); |
|
|
|
|
$alt = ""; |
|
|
|
|
while ($this->current()->type !== TokenType::RBRACKET && $this->current()->type !== TokenType::EOL) |
|
|
|
|
$alt .= $this->consume()->data; |
|
|
|
|
$alt .= self::StripBackslashes($this->consume()->data); |
|
|
|
|
|
|
|
|
|
if ($this->current()->type !== TokenType::RBRACKET || $this->next()->type !== TokenType::LPAREN) { |
|
|
|
|
$buffer .= "!"; |
|
|
|
@ -182,7 +195,7 @@ class Parser { |
|
|
|
|
array_push($elms, $elm); |
|
|
|
|
continue; |
|
|
|
|
} else |
|
|
|
|
$buffer .= $this->consume()->data; |
|
|
|
|
$buffer .= self::StripBackslashes($this->consume()->data); |
|
|
|
|
} |
|
|
|
|
if (strlen($buffer) > 0) |
|
|
|
|
array_push($elms, $this->document->createTextNode($buffer)); |
|
|
|
@ -285,7 +298,7 @@ class Parser { |
|
|
|
|
while (!($this->current()->type === TokenType::BACKTICK && |
|
|
|
|
$this->next()->type === TokenType::BACKTICK && |
|
|
|
|
$this->peek(2)->type === TokenType::BACKTICK) && $this->current()->type !== TokenType::EOF) { |
|
|
|
|
$buffer .= $this->consume()->data; |
|
|
|
|
$buffer .= self::StripBackslashes($this->consume()->data); |
|
|
|
|
} |
|
|
|
|
if ($this->current()->type !== TokenType::EOF) { |
|
|
|
|
$this->consume(); |
|
|
|
@ -412,6 +425,12 @@ class Parser { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function debug() : void { |
|
|
|
|
echo "<pre>"; |
|
|
|
|
print_r($this->tokenStream); |
|
|
|
|
echo "</pre>"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function parse() : DOMDocument { |
|
|
|
|
while ($this->current()->type !== TokenType::EOF) { |
|
|
|
|
switch($this->current()->type) { |
|
|
|
|