/** * Parses a symbol. * * @return Token */ public function parseSymbol() { $token = $this->str[$this->last]; if (!($flags = Context::isSymbol($token))) { return null; } if ($flags & Token::FLAG_SYMBOL_VARIABLE) { ++$this->last; } else { $token = ''; } if (($str = $this->parseString('`')) === null) { if (($str = static::parseUnknown()) === null) { $this->error(__('Variable name was expected.'), $this->str[$this->last], $this->last); } } if ($str !== null) { $token .= $str->token; } return new Token($token, Token::TYPE_SYMBOL, $flags); }
public function testIsSymbol() { $this->assertEquals(Token::FLAG_SYMBOL_VARIABLE, Context::isSymbol('@')); $this->assertEquals(Token::FLAG_SYMBOL_BACKTICK, Context::isSymbol('`')); $this->assertEquals(Token::FLAG_SYMBOL_VARIABLE, Context::isSymbol('@id')); $this->assertEquals(Token::FLAG_SYMBOL_BACKTICK, Context::isSymbol('`id`')); $this->assertEquals(Context::isSymbol('id'), null); }
/** * Parses a symbol. * * @return Token */ public function parseSymbol() { $token = $this->str[$this->last]; if (!($flags = Context::isSymbol($token))) { return null; } if ($flags & Token::FLAG_SYMBOL_VARIABLE) { if ($this->str[++$this->last] === '@') { // This is a system variable (e.g. `@@hostname`). $token .= $this->str[$this->last++]; $flags |= Token::FLAG_SYMBOL_SYSTEM; } } else { $token = ''; } $str = null; if ($this->last < $this->len) { if (($str = $this->parseString('`')) === null) { if (($str = static::parseUnknown()) === null) { $this->error(__('Variable name was expected.'), $this->str[$this->last], $this->last); } } } if ($str !== null) { $token .= $str->token; } return new Token($token, Token::TYPE_SYMBOL, $flags); }