本文整理汇总了PHP中yy函数的典型用法代码示例。如果您正苦于以下问题:PHP yy函数的具体用法?PHP yy怎么用?PHP yy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wrap
static function wrap($name, $exps)
{
if ($exps->is_empty() || last($exps->expressions)->jumps()) {
return $exps;
}
return $exps->push(yy('Call', yy('Value', yy('Literal', $name), array(yy('Access', yy('Literal', 'push')))), array($exps->pop())));
}
示例2: compile_node
function compile_node($options)
{
$options['indent'] .= TAB;
$set = '';
$body = $this->body;
if ($body->is_empty()) {
$body = '';
} else {
if ($this->returns) {
$body->make_return($rvar = $options['scope']->free_variable('results'));
$set = "{$this->tab}{$rvar} = [];\n";
}
if ($this->guard) {
if (count($body->expressions) > 1) {
array_unshift($body->expressions, yy('If', yy('Parens', $this->guard)->invert(), yy('Literal', 'continue')));
} else {
$body = yy_Block::wrap(array(yy('If', $this->guard, $body)));
}
}
$body = "\n" . $body->compile($options, LEVEL_TOP) . "\n{$this->tab}";
}
$code = $set . $this->tab . 'while (' . $this->condition->compile($options, LEVEL_PAREN) . ") {{$body}}";
if ($this->returns) {
$code .= "\n{$this->tab}return {$rvar};";
}
return $code;
}
示例3: compile_node
function compile_node($options)
{
$options['indent'] .= TAB;
$set = '';
$body = $this->body;
if ($body->is_empty()) {
$body = '';
} else {
if ($options['level'] > LEVEL_TOP || $this->returns) {
$rvar = $options['scope']->free_variable('results');
$set = "{$this->tab}{$rvar} = [];\n";
if ($body) {
$body = yy_Push::wrap($rvar, $body);
}
}
if ($this->guard) {
$body = yy_Block::wrap(array(yy('If', $this->guard, $body)));
}
$body = "\n" . $body->compile($options, LEVEL_TOP) . "\n{$this->tab}";
}
$code = $set . $this->tab . 'while (' . $this->condition->compile($options, LEVEL_PAREN) . ") {{$body}}";
if ($this->returns) {
$code .= "\n{$this->tab}return {$rvar};";
}
return $code;
}
示例4: compile_node
function compile_node($options)
{
$props = $this->properties;
$prop_names = array();
foreach ($this->properties as $prop) {
if ($prop->is_complex()) {
$prop = isset($prop->variable) ? $prop->variable : NULL;
}
if ($prop) {
$prop_name = $prop->unwrap_all();
$prop_name = isset($prop_name->value) ? $prop_name->value . '' : NULL;
if (in_array($prop_name, $prop_names)) {
throw new SyntaxError('multiple object literal properties named "' . $prop_name . '"');
}
$prop_names[] = $prop_name;
}
}
if (!count($props)) {
return $this->front ? '({})' : '{}';
}
if ($this->generated) {
foreach ($props as $node) {
if ($node instanceof yy_Value) {
throw new Error('cannot have an implicit value in an implicit object');
}
}
}
$idt = $options['indent'] .= TAB;
$last_non_com = $this->last_non_comment($this->properties);
foreach ($props as $i => $prop) {
if ($i === count($props) - 1) {
$join = '';
} else {
if ($prop === $last_non_com || $prop instanceof yy_Comment) {
$join = "\n";
} else {
$join = ",\n";
}
}
$indent = $prop instanceof yy_Comment ? '' : $idt;
if ($prop instanceof yy_Value && (isset($prop->this) && $prop->this)) {
$prop = yy('Assign', $prop->properties[0]->name, $prop, 'object');
}
if (!$prop instanceof yy_Comment) {
if (!$prop instanceof yy_Assign) {
$prop = yy('Assign', $prop, $prop, 'object');
}
if (isset($prop->variable->base)) {
$prop->variable->base->as_key = TRUE;
} else {
$prop->variable->as_key = TRUE;
}
}
$props[$i] = $indent . $prop->compile($options, LEVEL_TOP) . $join;
}
$props = implode('', $props);
$obj = '{' . ($props ? "\n{$props}\n{$this->tab}" : '') . '}';
return $this->front ? "({$obj})" : $obj;
}
示例5: constructor
function constructor($name)
{
if (is_object($name)) {
$this->name = $name;
} else {
$this->name = yy('Literal', $name);
}
return $this;
}
示例6: unfold_soak
static function unfold_soak($options, $parent, $name)
{
if (!(isset($parent->{$name}) && $parent->{$name} && ($ifn = $parent->{$name}->unfold_soak($options)))) {
return NULL;
}
$parent->{$name} = $ifn->body;
$ifn->body = yy('Value', $parent);
return $ifn;
}
示例7: make_return
function make_return($res = NULL)
{
foreach ($this->cases as $pair) {
$pair[1]->make_return($res);
}
if ($res && !$this->otherwise) {
$this->otherwise = yy('Block', array(yy('Literal', 'void 0')));
}
if ($this->otherwise) {
$this->otherwise->make_return($res);
}
return $this;
}
示例8: wrap
static function wrap($expressions, $statement = NULL, $no_return = FALSE)
{
if ($expressions->jumps()) {
return $expressions;
}
$func = yy('Code', array(), yy_Block::wrap(array($expressions)));
$args = array();
if (($mentions_args = $expressions->contains('yy_Closure::literal_args')) || $expressions->contains('yy_Closure::literal_this')) {
$meth = yy('Literal', $mentions_args ? 'apply' : 'call');
$args = array(yy('Literal', 'this'));
if ($mentions_args) {
$args[] = yy('Literal', 'arguments');
}
$func = yy('Value', $func, array(yy('Access', $meth)));
}
$func->no_return = $no_return;
$call = yy('Call', $func, $args);
return $statement ? yy_Block::wrap(array($call)) : $call;
}
示例9: as_reference
function as_reference($options)
{
if (isset($this->reference) && $this->reference) {
return $this->reference;
}
$node = $this->name;
if (isset($node->this) && $node->this) {
$node = $node->properties[0]->name;
if (isset($this->value->reserved) && $this->value->reserved) {
$node = yy('Literal', $options['scope']->free_variable($node->value));
}
} else {
if ($node->is_complex()) {
$node = yy('Literal', $options['scope']->free_variable('arg'));
}
}
$node = yy('Value', $node);
if ($this->splat) {
$node = yy('Splat', $node);
}
return $this->reference = $node;
}
示例10: filter_implicit_objects
function filter_implicit_objects()
{
return call_user_func_array(array(yy('Call'), __FUNCTION__), func_get_args());
}
示例11: unfold_soak
function unfold_soak($options)
{
if ($this->soak) {
if ($this->variable) {
if ($ifn = unfold_soak($options, $this, 'variable')) {
return $ifn;
}
$tmp = yy('Value', $this->variable);
list($left, $rite) = $tmp->cache_reference($options);
} else {
$left = yy('Literal', $this->super_reference($options));
$rite = yy('Value', $left);
}
$rite = yy('Call', $rite, $this->args);
$rite->is_new($this->is_new());
$left = yy('Literal', 'typeof ' . $left->compile($options) . ' === "function"');
return yy('If', $left, yy('Value', $rite), array('soak' => TRUE));
}
$call = $this;
$list = array();
while (TRUE) {
if ($call->variable instanceof yy_Call) {
$list[] = $call;
$call = $call->variable;
continue;
}
if (!$call->variable instanceof yy_Value) {
break;
}
$list[] = $call;
if (!($call = $call->variable->base) instanceof yy_Call) {
break;
}
}
foreach (array_reverse($list) as $call) {
if (isset($ifn)) {
if ($call->variable instanceof yy_Call) {
$call->variable = $ifn;
} else {
$call->variable->base = $ifn;
}
}
$ifn = unfold_soak($options, $call, 'variable');
}
return isset($ifn) ? $ifn : NULL;
}
示例12: pluck_direct_call
function pluck_direct_call($options, $body)
{
$defs = '';
foreach ($body->expressions as $idx => $expr) {
$expr = $expr->unwrap_all();
if (!$expr instanceof yy_Call) {
continue;
}
$val = $expr->variable->unwrap_all();
if (!($val instanceof yy_Code || $val instanceof yy_Value && (isset($val->base) && $val->base && $val->base->unwrap_all() instanceof yy_Code && count($val->properties) === 1 && isset($val->properties[0]->name) && in_array($val->properties[0]->name['value'], array('call', 'apply'), TRUE)))) {
continue;
}
$fn = isset($val->base) && $val->base ? $val->base->unwrap_all() : $val;
$ref = yy('Literal', $options['scope']->free_variable('fn'));
$base = yy('Value', $ref);
if (isset($val->base) && $val->base) {
list($val->base, $base) = array($base, $val);
}
$body->expressions[$idx] = yy('Call', $base, $expr->args);
$tmp = yy('Assign', $ref, $fn);
$defs .= $this->tab . $tmp->compile($options, LEVEL_TOP) . ";\n";
}
return $defs;
}
示例13: compile_pattern_match
function compile_pattern_match($options)
{
$top = $options['level'] === LEVEL_TOP;
$value = $this->value;
$objects = $this->variable->base->objects;
if (!($olen = count($objects))) {
$code = $value->compile($options);
return $options['level'] >= LEVEL_OP ? "({$code})" : $code;
}
$is_object = $this->variable->is_object();
if ($top && $olen === 1 && !($obj = $objects[0]) instanceof yy_Splat) {
if ($obj instanceof yy_Assign) {
$idx = $obj->variable->base;
$obj = $obj->value;
} else {
if ($obj->base instanceof yy_Parens) {
$tmp = yy('Value', $obj->unwrap_all());
list($obj, $idx) = $tmp->cache_reference($options);
} else {
if ($is_object) {
$idx = $obj->this ? $obj->properties[0]->name : $obj;
} else {
$idx = yy('Literal', 0);
}
}
}
$acc = preg_match(IDENTIFIER, $idx->unwrap()->value);
$value = yy('Value', $value);
if ($acc) {
$value->properties[] = yy('Access', $idx);
} else {
$value->properties[] = yy('Index', $idx);
}
$tmp = $obj->unwrap();
$tmp = isset($tmp->value) ? $tmp->value : NULL;
if (in_array($tmp, Lexer::$COFFEE_RESERVED)) {
throw new SyntaxError('assignment to a reserved word: ' . $obj->compile($options) . ' = ' . $value->compile($options));
}
return yy('Assign', $obj, $value, NULL, array('param' => $this->param))->compile($options, LEVEL_TOP);
}
$vvar = $value->compile($options, LEVEL_LIST);
$assigns = array();
$splat = FALSE;
if (!preg_match(IDENTIFIER, $vvar) || $this->variable->assigns($vvar)) {
$assigns[] = ($ref = $options['scope']->free_variable('ref')) . ' = ' . $vvar;
$vvar = $ref;
}
foreach ($objects as $i => $obj) {
$idx = $i;
if ($is_object) {
if ($obj instanceof yy_Assign) {
$idx = $obj->variable->base;
$obj = $obj->value;
} else {
if ($obj->base instanceof yy_Parens) {
$tmp = yy('Value', $obj->unwrap_all());
list($obj, $idx) = $tmp->cache_reference($options);
} else {
$idx = $obj->this ? $obj->properties[0]->name : $obj;
}
}
}
if (!$splat && $obj instanceof yy_Splat) {
$name = $obj->name->unwrap()->value;
$obj = $obj->unwrap();
$val = "{$olen} <= {$vvar}.length ? " . utility('slice') . ".call({$vvar}, {$i}";
$ivar = 'undefined';
if ($rest = $olen - $i - 1) {
$ivar = $options['scope']->free_variable('i');
$val .= ", {$ivar} = {$vvar}.length - {$rest}) : ({$ivar} = {$i}, [])";
} else {
$val .= ') : []';
}
$val = yy('Literal', $val);
$splat = "{$ivar}++";
} else {
$name = $obj->unwrap();
$name = isset($name->value) ? $name->value : NULL;
if ($obj instanceof yy_Splat) {
$obj = $obj->name->compile($options);
throw new SyntaxError("multiple splats are disallowed in an assignment: {$obj}...");
}
if (is_numeric($idx)) {
$idx = yy('Literal', $splat ? $splat : $idx);
$acc = FALSE;
} else {
$acc = $is_object ? preg_match(IDENTIFIER, $idx->unwrap()->value) : 0;
}
$val = yy('Value', yy('Literal', $vvar), array($acc ? yy('Access', $idx) : yy('Index', $idx)));
}
if (isset($name) && $name && in_array($name, Lexer::$COFFEE_RESERVED)) {
throw new SyntaxError("assignment to a reserved word: " . $obj->compile($options) . ' = ' . $val->compile($options));
}
$tmp = yy('Assign', $obj, $val, NULL, array('param' => $this->param, 'subpattern' => TRUE));
$assigns[] = $tmp->compile($options, LEVEL_TOP);
}
if (!($top || $this->subpattern)) {
$assigns[] = $vvar;
}
$code = implode(', ', $assigns);
//.........这里部分代码省略.........
示例14: make_return
function make_return($res = NULL)
{
$me = $this->unwrap_all();
if ($res) {
return yy('Call', yy('Literal', "{$res}.push"), array($me));
} else {
return yy('Return', $me);
}
}
示例15: make_return
function make_return()
{
if ($this->body) {
$this->body = yy('Block', array($this->body->make_return()));
}
if ($this->else_body) {
$this->else_body = yy('Block', array($this->else_body->make_return()));
}
return $this;
}