PHP code example of webapper / parzrkit
1. Go to this page and download the library: Download webapper/parzrkit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webapper / parzrkit example snippets
use ParzRKit\Parser\Lexer\AbstractToken;
use ParzRKit\Parser\Lexer;
use ParzRKit\Linker;
use ParzRKit\Parser;
use ParzRKit\Compiler;
use ParzRKit\Parser\Lexer\DataStreamToken;
define('SRC', realpath(dirname(dirname(__FILE__))).'/src/vendor/assarte/parzrkit/lib/');
.php';
taStream()
{
return false;
}
public function identifyOpenTag()
{
if ($this->stream{0} == '/') {
$this->openTag = '/';
}
}
}
class TestSubToken extends AbstractToken
{
public function identifyOpenTag()
{
if ($this->stream{0} == '[') {
$this->openTag = '[';
}
}
public function identifyCloseTag($inStream=null)
{
$pos = $this->getCursor();
if ($inStream !== null) {
$pos = 0;
} else {
$inStream = $this->processed;
}
if ($inStream{$pos} == ']') {
$this->closeTag = ']';
return true;
}
return false;
}
public function guessCloseTag()
{
return ']';
}
}
class TestLexer extends Lexer
{
protected function registerTokeners()
{
$this->addTokener('TestToken');
$this->addTokener('TestSubToken');
}
}
class TestLinker extends Linker
{
public function link()
{
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($this));
foreach ($it as $link) {
echo str_repeat('| ', $it->getDepth() - 1).'|-'.json_encode($link).'<br>';
}
}
}
$stream = '[876/t687][aa[bb[dd]]cc]';
$parser = new Parser($stream, TestLexer::getLexer());
$parser->parse();
$compiler = new Compiler(new TestLinker(), $parser->getToken()->getNode());
$compiler->compile();
echo $stream.'<br>';
$compiler->getLinker()->link();