Inheritance: use trait DeclParser
Exemplo n.º 1
0
 public function parse(Grammar $grammar, Expr $left, Token $token)
 {
     $then = $grammar->_expr();
     $grammar->parser->match(Tag::T_ELSE);
     $else = $grammar->_expr(Precedence::TERNARY - 1);
     return new TernaryExpr($left, $then, $else);
 }
Exemplo n.º 2
0
 public function parse(Grammar $grammar, Token $token)
 {
     $expr = $grammar->_expr();
     $expr->addParentheses();
     $grammar->parser->match(')');
     return $expr;
 }
Exemplo n.º 3
0
 public function parse(Grammar $grammar, Token $token)
 {
     $cases = [];
     do {
         $grammar->parser->consume();
         // Default operation
         if ($grammar->parser->is(Tag::T_ELSE)) {
             $grammar->parser->consume();
             $default = new \stdClass();
             $default->condition = null;
             $default->action = $grammar->_expr();
             $cases[] = $default;
             goto fetch_next;
         }
         $case = new \stdClass();
         $case->condition = $grammar->_expr();
         $grammar->parser->match('->');
         $case->action = $grammar->_expr();
         $cases[] = $case;
         fetch_next:
         if (!$grammar->parser->is(Tag::T_END)) {
             $grammar->parser->match(';');
         }
     } while ($grammar->parser->is('|'));
     $grammar->parser->match(Tag::T_END);
     return new WhenExpr($cases);
 }
Exemplo n.º 4
0
 public function parse(Grammar $grammar, Token $token)
 {
     $shape_name = $grammar->qualifiedName();
     $initializer = null;
     if ($grammar->parser->is('@{')) {
         $initializer = $grammar->evalParselet(ObjectParselet::class);
     }
     return new NewExpr($shape_name, $initializer);
 }
Exemplo n.º 5
0
 public function parse(Grammar $grammar, Expr $from, Token $token)
 {
     $to = $grammar->_expr();
     $by = null;
     if ($grammar->parser->is(Tag::T_BY)) {
         $grammar->parser->consume();
         $by = $grammar->_expr();
     }
     return new RangeExpr($from, $to, $by);
 }
Exemplo n.º 6
0
 public function parse(Grammar $grammar, Token $token)
 {
     $items = [];
     if ($grammar->parser->is('}')) {
         $grammar->parser->consume();
     } else {
         $items[] = $grammar->_expr();
         while ($grammar->parser->is(';')) {
             $grammar->parser->consume();
             $items[] = $grammar->_expr();
         }
         $grammar->parser->match('}');
     }
     return new ArrayExpr($items);
 }
Exemplo n.º 7
0
 public function parse(Grammar $grammar, Expr $left, Token $token)
 {
     $clauses = [];
     $name = $grammar->identifier();
     $grammar->parser->match(':-');
     $value = $grammar->_expr();
     $clauses[] = [$name, $value];
     while ($grammar->parser->is(';')) {
         $grammar->parser->consume();
         $name = $grammar->identifier();
         $grammar->parser->match(':-');
         $value = $grammar->_expr();
         $clauses[] = [$name, $value];
     }
     return new WhereExpr($left, $clauses);
 }
Exemplo n.º 8
0
 public function parse(Grammar $grammar, Expr $left, Token $token)
 {
     $args = [];
     $is_bang = '!' === $token->getTag();
     if (!$is_bang) {
         if (!$grammar->parser->is(')')) {
             $args[] = $grammar->_expr();
             while ($grammar->parser->is(';')) {
                 $grammar->parser->consume();
                 $args[] = $grammar->_expr();
             }
         }
         $grammar->parser->match(')');
     }
     return new CallExpr($left, $args, $is_bang);
 }
Exemplo n.º 9
0
 public function parse(Grammar $grammar, Token $token)
 {
     $op_table =& Tag::getPartialOperators();
     $next_op = $grammar->parser->lookahead->getTag();
     $right = null;
     if (in_array($next_op, $op_table, true)) {
         $grammar->parser->match($next_op);
         // Faster than _optExpr
         if (!$grammar->parser->is(')')) {
             $right = $grammar->_expr();
         }
         $grammar->parser->match(')');
     } else {
         $grammar->parser->match('operator');
     }
     return new PartialFuncExpr($next_op, $right);
 }
Exemplo n.º 10
0
 public function parse(Grammar $grammar, Token $token)
 {
     $keys = [];
     $values = [];
     if (!$grammar->parser->consumeIf('}')) {
         $keys[] = $grammar->identifier();
         $grammar->parser->match('->');
         $values[] = $grammar->_expr();
         while ($grammar->parser->consumeIf(';')) {
             $keys[] = $grammar->identifier();
             $grammar->parser->match('->');
             $values[] = $grammar->_expr();
         }
         $grammar->parser->match('}');
     }
     return new ObjectExpr($keys, $values);
 }
Exemplo n.º 11
0
 public function parse(Grammar $grammar, Token $token)
 {
     $keys = [];
     $values = [];
     if ($grammar->parser->is('}')) {
         $grammar->parser->consume();
     } else {
         $keys[] = $grammar->_expr();
         $grammar->parser->match('->');
         $values[] = $grammar->_expr();
         while ($grammar->parser->is(';')) {
             $grammar->parser->consume();
             $keys[] = $grammar->_expr();
             $grammar->parser->match('->');
             $values[] = $grammar->_expr();
         }
         $grammar->parser->match('}');
     }
     return new MapExpr($keys, $values);
 }
Exemplo n.º 12
0
 public function parse(Grammar $grammar, Token $token)
 {
     $parameters = [];
     $kind = null;
     $body = null;
     $has_brackets = false;
     // When identifier, we have an unary function
     if ($grammar->parser->is(Tag::T_IDENT)) {
         $name = $grammar->identifier();
         $parameters[] = (object) ['name' => $name, 'is_reference' => false];
     } else {
         $has_brackets = true;
         $grammar->parser->match('[');
         if (!$grammar->parser->consumeIf(']')) {
             $parameters[] = $grammar->_parameter();
             while ($grammar->parser->consumeIf(',')) {
                 $parameters[] = $grammar->_parameter();
             }
             $grammar->parser->match(']');
         }
     }
     $grammar->parser->match('->');
     if ($grammar->parser->is(Tag::T_BEGIN)) {
         $kind = static::TYPE_STATEMENT;
         $grammar->parser->consume();
         $body = iterator_to_array($grammar->_innerStmtList());
         $grammar->parser->match(Tag::T_END);
     } else {
         $kind = static::TYPE_EXPRESSION;
         $body = $grammar->_expr();
     }
     return new LambdaExpr($parameters, $kind, $body, $has_brackets);
 }
Exemplo n.º 13
0
 public function parse(Grammar $grammar, Token $token)
 {
     $body = new StmtList(iterator_to_array($grammar->_innerStmtList()));
     $grammar->parser->match('}');
     return new BlockExpr($body);
 }
Exemplo n.º 14
0
 public function parse(Grammar $grammar, Expr $left, Token $token)
 {
     $index = $grammar->_expr();
     $grammar->parser->match('}');
     return new AccessExpr($left, $index);
 }
Exemplo n.º 15
0
 public function parse(Grammar $grammar, Expr $left, Token $token)
 {
     $right = $grammar->_name();
     return new OperatorExpr($left, $token->getTag(), $grammar->parser->resolveScope($right->getPointer()));
 }
Exemplo n.º 16
0
 public function parse(Grammar $parser, Expr $left, Token $token)
 {
     $right = $parser->_expr($this->precedence - ($this->is_right ? 1 : 0));
     return new OperatorExpr($left, $token->getTag(), $right);
 }
Exemplo n.º 17
0
 public function parse(Grammar $parser, Token $token)
 {
     $operand = $parser->_expr($this->precedence);
     return new PrefixExpr($token, $operand);
 }