b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / vendor / theseer / tokenizer / src /
Filename/home/a/home/dev2.destoffenstraat.com/vendor/theseer/tokenizer/src/Tokenizer.php
Size3.5 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified03-Mar-2024 13:36
Last accessed23-Aug-2025 15:06
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php declare(strict_types = 1);
namespace TheSeer\Tokenizer;

class Tokenizer {

/**
* Token Map for "non-tokens"
*
* @var array
*/
private $map = [
'(' => 'T_OPEN_BRACKET',
')' => 'T_CLOSE_BRACKET',
'[' => 'T_OPEN_SQUARE',
']' => 'T_CLOSE_SQUARE',
'{' => 'T_OPEN_CURLY',
'}' => 'T_CLOSE_CURLY',
';' => 'T_SEMICOLON',
'.' => 'T_DOT',
',' => 'T_COMMA',
'=' => 'T_EQUAL',
'<' => 'T_LT',
'>' => 'T_GT',
'+' => 'T_PLUS',
'-' => 'T_MINUS',
'*' => 'T_MULT',
'/' => 'T_DIV',
'?' => 'T_QUESTION_MARK',
'!' => 'T_EXCLAMATION_MARK',
':' => 'T_COLON',
'"' => 'T_DOUBLE_QUOTES',
'@' => 'T_AT',
'&' => 'T_AMPERSAND',
'%' => 'T_PERCENT',
'|' => 'T_PIPE',
'$' => 'T_DOLLAR',
'^' => 'T_CARET',
'~' => 'T_TILDE',
'`' => 'T_BACKTICK'
];

public function parse(string $source): TokenCollection {
$result = new TokenCollection();

if ($source === '') {
return $result;
}

$tokens = \token_get_all($source);

$lastToken = new Token(
$tokens[0][2],
'Placeholder',
''
);

foreach ($tokens as $pos => $tok) {
if (\is_string($tok)) {
$token = new Token(
$lastToken->getLine(),
$this->map[$tok],
$tok
);
$result->addToken($token);
$lastToken = $token;

continue;
}

$line = $tok[2];
$values = \preg_split('/\R+/Uu', $tok[1]);

if (!$values) {
$result->addToken(
new Token(
$line,
\token_name($tok[0]),
'{binary data}'
)
);

continue;
}

foreach ($values as $v) {
$token = new Token(
$line,
\token_name($tok[0]),
$v
);
$lastToken = $token;
$line++;

if ($v === '') {
continue;
}

$result->addToken($token);
}
}

return $this->fillBlanks($result, $lastToken->getLine());
}

private function fillBlanks(TokenCollection $tokens, int $maxLine): TokenCollection {
$prev = new Token(
0,
'Placeholder',
''
);

$final = new TokenCollection();

foreach ($tokens as $token) {
$gap = $token->getLine() - $prev->getLine();

while ($gap > 1) {
$linebreak = new Token(
$prev->getLine() + 1,
'T_WHITESPACE',
''
);
$final->addToken($linebreak);
$prev = $linebreak;
$gap--;
}

$final->addToken($token);
$prev = $token;
}

$gap = $maxLine - $prev->getLine();

while ($gap > 0) {
$linebreak = new Token(
$prev->getLine() + 1,
'T_WHITESPACE',
''
);
$final->addToken($linebreak);
$prev = $linebreak;
$gap--;
}

return $final;
}
}