Skip to content

Commit

Permalink
Merge pull request #528 from kamil-tekiela/types-in-Lexer
Browse files Browse the repository at this point in the history
Add native property types in Lexer
  • Loading branch information
MauricioFauth committed Jan 16, 2024
2 parents be871d1 + 5f7535e commit 31bf535
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -380,11 +380,6 @@ parameters:
count: 3
path: src/Lexer.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Lexer\\:\\:\\$delimiter \\(string\\) does not accept null\\.$#"
count: 1
path: src/Lexer.php

-
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array\\<non\\-empty\\-string, int\\> and array\\{\\} will always evaluate to false\\.$#"
count: 1
Expand Down
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Expand Up @@ -585,7 +585,6 @@
<code>$token</code>
</PossiblyNullArgument>
<PossiblyNullOperand>
<code><![CDATA[$this->delimiter]]></code>
<code><![CDATA[$this->str[$this->last++]]]></code>
<code><![CDATA[$this->str[$this->last++]]]></code>
<code><![CDATA[$this->str[$this->last]]]></code>
Expand All @@ -611,9 +610,6 @@
<code><![CDATA[$this->str[++$this->last]]]></code>
<code><![CDATA[$this->str[++$this->last]]]></code>
</PossiblyNullOperand>
<PossiblyNullPropertyAssignmentValue>
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyNullPropertyFetch>
<code><![CDATA[$next->type]]></code>
<code><![CDATA[$next->value]]></code>
Expand Down
32 changes: 9 additions & 23 deletions src/Lexer.php
Expand Up @@ -66,60 +66,46 @@ class Lexer

/**
* The string to be parsed.
*
* @var string|UtfString
*/
public $str = '';
public string|UtfString $str = '';

/**
* The length of `$str`.
*
* By storing its length, a lot of time is saved, because parsing methods
* would call `strlen` everytime.
*
* @var int
*/
public $len = 0;
public int $len = 0;

/**
* The index of the last parsed character.
*
* @var int
*/
public $last = 0;
public int $last = 0;

/**
* Tokens extracted from given strings.
*
* @var TokensList
*/
public $list;
public TokensList $list;

/**
* The default delimiter. This is used, by default, in all new instances.
*
* @var string
*/
public static $defaultDelimiter = ';';
public static string $defaultDelimiter = ';';

/**
* Statements delimiter.
* This may change during lexing.
*
* @var string
*/
public $delimiter;
public string $delimiter;

/**
* The length of the delimiter.
*
* Because `parseDelimiter` can be called a lot, it would perform a lot of
* calls to `strlen`, which might affect performance when the delimiter is
* big.
*
* @var int
*/
public $delimiterLen;
public int $delimiterLen;

/**
* @param string|UtfString $str the query to be lexed
Expand Down Expand Up @@ -253,7 +239,7 @@ public function lex(): void
$pos = $this->last + 1;

// Parsing the delimiter.
$this->delimiter = null;
$this->delimiter = '';
$delimiterLen = 0;
while (
++$this->last < $this->len
Expand All @@ -264,7 +250,7 @@ public function lex(): void
++$delimiterLen;
}

if (empty($this->delimiter)) {
if ($this->delimiter === '') {
$this->error('Expected delimiter.', '', $this->last);
$this->delimiter = ';';
}
Expand Down

0 comments on commit 31bf535

Please sign in to comment.