isSymbol() public static method

Checks if the given character is the beginning of a symbol. A symbol can be either a variable or a field name.
public static isSymbol ( string $str ) : integer
$str string String to be checked.
return integer The appropriate flag for the symbol type.
Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }