示例#1
0
    public function visitLiteral(LiteralNode $node)
    {
        $expecting = var_export($node->getString(), true);
        $match = "substr(\$this->string, \$this->position, strlen({$node->getString()}))";
        if ($node->isCaseInsensitive()) {
            $cond = "strtolower({$match}) === strtolower({$node->getString()})";
        } else {
            $cond = "{$match} === {$node->getString()}";
        }
        $this->results[] = <<<EOS
if ({$cond}) {
    \$_success = true;
    \$this->value = {$match};
    \$this->position += strlen({$node->getString()});
} else {
    \$_success = false;

    \$this->report(\$this->position, {$expecting});
}
EOS;
    }