fixed minor bugs

feature/strict-mode
Michael Ochmann 3 years ago
parent 7e19ede470
commit 5acd3b362e
  1. 3
      src/Lexer.php
  2. 4
      src/Parser.php

@ -9,12 +9,14 @@ class Lexer {
public function __construct(string $sourceCode, ?string $fileName = null) { public function __construct(string $sourceCode, ?string $fileName = null) {
$this->fileName = $fileName; $this->fileName = $fileName;
$unifiedSource = str_replace(["\r\n", "\r"], "\n", $sourceCode); $unifiedSource = str_replace(["\r\n", "\r"], "\n", $sourceCode);
$unifiedSource = str_replace(" ", "\t", $unifiedSource);
$this->source = explode("\n", trim($unifiedSource, "\n")); $this->source = explode("\n", trim($unifiedSource, "\n"));
} }
public function tokenize() : array { public function tokenize() : array {
$tokens = []; $tokens = [];
$row = 1; $row = 1;
$col = 1;
foreach ($this->source as $line) { foreach ($this->source as $line) {
if (strlen($line) < 1) { if (strlen($line) < 1) {
@ -129,7 +131,6 @@ class Lexer {
$row++; $row++;
} }
$clearBuffer();
array_push($tokens, new Token(TokenType::EOF, "\0", [$col, $row, $this->fileName])); array_push($tokens, new Token(TokenType::EOF, "\0", [$col, $row, $this->fileName]));
return $tokens; return $tokens;

@ -362,7 +362,7 @@ class Parser {
if ($this->current()->type === TokenType::EOF) if ($this->current()->type === TokenType::EOF)
break; 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) { if ($type === ListType::UNORDERED) {
$asterisk = $this->consume(); $asterisk = $this->consume();
self::Assert($asterisk->type === TokenType::ASTERISK, $asterisk, "expected asterisk, got ".$asterisk->type->name); self::Assert($asterisk->type === TokenType::ASTERISK, $asterisk, "expected asterisk, got ".$asterisk->type->name);
@ -568,6 +568,8 @@ class Parser {
$head = $this->parseTableHead(); $head = $this->parseTableHead();
$props = $this->parseTableAlignment(); $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; $i = 0;
foreach($head->childNodes as $col) { foreach($head->childNodes as $col) {
$col->setAttribute("style", "text-align: ".$props[$i]); $col->setAttribute("style", "text-align: ".$props[$i]);

Loading…
Cancel
Save