Exemplo n.º 1
0
 /**
  * Returns the column in the source file the message refers to.
  * If this error message does not refer to a token (lint error),
  * the column number is 0.
  *
  * @returns integer
  */
 public function getColumn()
 {
     // Explicitly set column overrides token start column
     if ($this->column !== null) {
         return $this->column;
     }
     if (!$this->token instanceof Token) {
         return 0;
     }
     return $this->token->getColumn();
 }
Exemplo n.º 2
0
 /**
  * @covers spriebsch\PHPca\Token::__construct
  * @covers spriebsch\PHPca\Token::getColumn
  */
 public function testGetColumnReturnsRealValueWhenWhitespaceTokenHasNoLeadingNewLine()
 {
     $t = new Token(T_WHITESPACE, " ", 3, 7);
     $this->assertEquals(7, $t->getColumn());
 }
Exemplo n.º 3
0
Arquivo: Parser.php Projeto: g4z/poop
 protected function procAssignment(Token $token)
 {
     $this->debug(__METHOD__, __LINE__, "identifier: {$token->getValue()}");
     // Validate the leftside
     if ($token->getType() != TokenType::IDENTIFIER) {
         throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment identifier: '{$token->getValue()}'", __FILE__, __LINE__);
     }
     $name = $token->getValue();
     $token = $this->getToken();
     // Validate the operator
     switch ($token->getType()) {
         case TokenType::SYMBOL:
             switch ($token->getValue()) {
                 case ';':
                     if (!$this->memory->hasVar($name)) {
                         throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($name) + 1, "Unknown identifier: '{$name}'", __FILE__, __LINE__);
                     }
                     // Do nothing :\
                     return;
                     break;
                 case '=':
                     // allow =
                     break;
                 case '++':
                 case '--':
                     // allow ++ and --
                     break;
                 default:
                     throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
             }
             break;
         default:
             throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
     }
     $operator = $token->getValue();
     // Evaluate the rightside
     $type = $this->evalExp($value);
     // Perform action
     switch ($operator) {
         case '=':
             $this->memory->setVar($name, $value, $type);
             break;
         case '++':
             // number only
         // number only
         case '--':
             if (!$this->memory->hasVar($name)) {
                 throw new SyntaxException($token->getLine(), $token->getColumn(), "Unknown identifier: '{$name}'", __FILE__, __LINE__);
             }
             $value = $this->memory->getVar($name);
             if ($operator == '++') {
                 $newval = intval($value + 1);
             } else {
                 $newval = intval($value - 1);
             }
             $this->memory->setVar($name, $newval, $type);
             break;
         default:
             throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($operator) + 1, "Unknown operator: '{$operator}'", __FILE__, __LINE__);
             break;
     }
 }
Exemplo n.º 4
0
Arquivo: Lexer.php Projeto: g4z/poop
 protected function buildNumberToken(Token $token, Character $char)
 {
     $token->setType(TokenType::INTEGER);
     $buffer = '';
     do {
         $buffer .= $char->getValue();
         try {
             $char = $this->getCharacter();
         } catch (EofException $e) {
             throw new SyntaxException($char->getLine(), $char->getColumn() - mb_strlen($buffer) + 1, "Found EOF reading number: '{$buffer}'", __FILE__, __LINE__);
         }
     } while ($char->isNumber() || $char->getValue() == '.');
     $this->ungetCharacter();
     // If number contains a period, is a FLOAT
     if (mb_strpos($buffer, '.') !== FALSE) {
         $token->setType(TokenType::FLOAT);
         // If period is not followed by numbers
         if (mb_substr($buffer, -1) == '.') {
             throw new SyntaxException($token->getLine(), $token->getColumn(), "Invalid FLOAT value: '{$buffer}'", __FILE__, __LINE__);
         }
     }
     switch ($token->getType()) {
         case TokenType::FLOAT:
             $token->setValue(floatval($buffer));
             break;
         case TokenType::INTEGER:
             $token->setValue(intval($buffer));
             break;
         default:
             throw new SyntaxException($char->getLine(), $char->getColumn(), 'Unknown number token type: "' . $buffer . '"', __FILE__, __LINE__);
             break;
     }
     return $token;
 }