From 5acd3b362e0cb5d276db94236ea51381c21ed808 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Tue, 23 Aug 2022 19:23:35 +0200 Subject: [PATCH] fixed minor bugs --- src/Lexer.php | 3 ++- src/Parser.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index a8a39cd..de7db14 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -9,12 +9,14 @@ class Lexer { public function __construct(string $sourceCode, ?string $fileName = null) { $this->fileName = $fileName; $unifiedSource = str_replace(["\r\n", "\r"], "\n", $sourceCode); + $unifiedSource = str_replace(" ", "\t", $unifiedSource); $this->source = explode("\n", trim($unifiedSource, "\n")); } public function tokenize() : array { $tokens = []; $row = 1; + $col = 1; foreach ($this->source as $line) { if (strlen($line) < 1) { @@ -129,7 +131,6 @@ class Lexer { $row++; } - $clearBuffer(); array_push($tokens, new Token(TokenType::EOF, "\0", [$col, $row, $this->fileName])); return $tokens; diff --git a/src/Parser.php b/src/Parser.php index 9f079e0..c62d606 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -362,7 +362,7 @@ class Parser { if ($this->current()->type === TokenType::EOF) break; - // then we except an asterisk or a number followed by a period + // then we expect an asterisk or a number followed by a period if ($type === ListType::UNORDERED) { $asterisk = $this->consume(); self::Assert($asterisk->type === TokenType::ASTERISK, $asterisk, "expected asterisk, got ".$asterisk->type->name); @@ -568,6 +568,8 @@ class Parser { $head = $this->parseTableHead(); $props = $this->parseTableAlignment(); + self::Assert(count($props) === count($head->childNodes), $this->current(), "the number of alignment columns does not match the number of header columns"); + $i = 0; foreach($head->childNodes as $col) { $col->setAttribute("style", "text-align: ".$props[$i]);