本文整理汇总了PHP中Parser::CreateParser方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::CreateParser方法的具体用法?PHP Parser::CreateParser怎么用?PHP Parser::CreateParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::CreateParser方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: switch
$text = $tree->sub_results[1]->sub_results[0]->sub_results[1]->sub_results[0]->full_text($this->stream);
switch ($tree->sub_results[1]->sub_results[0]->sub_results[1]->index) {
case 1:
// escaped
$object->def($case, $text);
break;
case 2:
// non escaped
if (array_key_exists($text, $this->rules)) {
$object = unserialize(serialize($this->rules[$text]));
$object->__construct($omit, $non);
} else {
$object->def($case, $text);
}
break;
}
break;
}
return $object;
}
function Parse($rule, $stream)
{
$stream->position = 0;
return $this->rules[$rule]->Parse($stream);
}
}
$x = new Parser();
$x->CreateParser("z case cat | |");
$file = new Stream("CATabcdefghijklmn");
$result = $x->rules["z"]->Parse($file);
echo $result->full_text($file);
示例2: Parser
<?php
include 'parser_compiler.php';
$output = '';
$input = '';
$ok = true;
if (isset($_POST['input'])) {
$input = $_POST['input'];
$p = new Parser();
$rules_text = <<<'RULESTEXT'
ws omit list set \32\\13\\10\ | min 0 | |
identifier list set case abcdefghijklmnopqrstuvwxyz | | |
block and ws identifier ws { ws blocks ws } | |
blocks list block min 0 | |
RULESTEXT;
$p->CreateParser($rules_text);
$s = new Stream($input);
$result = $p->rules["block"]->Parse($s);
$output = $result->text($s);
$ok = $result->ok;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<style>
#output {
background-color: #EEE;
width:1000px;
border: 1px solid #A0A0A0;
示例3: ParseSet
header('Content-Type: text/plain');
include 'parser_compiler.php';
ini_set('html_errors', false);
$rules = <<<RULES
\t\tname list set case abcdefghijklmnopqrstuvwxyz | | |
\t\tnumber list set 0123456789 | | |
\t\tevery and omit / number | |
\t\trange and number omit - number opt every | | |
\t\tmember or range number | |
\t\tgroup and omit ( list element del omit , | omit ) | |
\t\telement and opt ~ | or group member | opt subarray | | |
\t\tarray and opt name | omit : list element del omit , | | |
\t\tsubarray and omit { array omit } | |
RULES;
$x = new Parser();
$x->CreateParser($rules);
$file = new Stream("H:1{M:1,2,3},(5-20,23){M:4},~12-17/2");
$result = $x->rules["array"]->Parse($file);
if ($result->ok) {
//echo $result->text($file);
$set = ParseSet($result, $file);
print_r($set);
} else {
die('not matched');
}
function ParseSet($tree, $file)
{
echo "\n";
// echo $tree->nodes{0}->text($file);
$class = $tree->nodes[0]->text($file);
switch ($class) {