Ejemplo n.º 1
0
 function parseObjectField($isConst, &$fieldNames)
 {
     $start = $this->token->start;
     $name = $this->parseName();
     if (array_key_exists($name->value, $fieldNames)) {
         throw Exception::create($this->source, $start, "Duplicate input object field " . $name->value . '.');
     }
     $fieldNames[$name->value] = true;
     $this->expect(Token::COLON);
     return new ObjectField(array('name' => $name, 'value' => $this->parseValue($isConst), 'loc' => $this->loc($start)));
 }
Ejemplo n.º 2
0
 private function readString($start)
 {
     $body = $this->source->body;
     $bodyLength = $this->source->length;
     $position = $start + 1;
     $chunkStart = $position;
     $code = null;
     $value = '';
     while ($position < $bodyLength && ($code = Utils::charCodeAt($body, $position)) && $code !== 34 && $code !== 10 && $code !== 13 && $code !== 0x2028 && $code !== 0x2029) {
         ++$position;
         if ($code === 92) {
             // \
             $value .= mb_substr($body, $chunkStart, $position - 1 - $chunkStart, 'UTF-8');
             $code = Utils::charCodeAt($body, $position);
             switch ($code) {
                 case 34:
                     $value .= '"';
                     break;
                 case 47:
                     $value .= '\\/';
                     break;
                 case 92:
                     $value .= '\\';
                     break;
                 case 98:
                     $value .= '\\b';
                     break;
                 case 102:
                     $value .= '\\f';
                     break;
                 case 110:
                     $value .= '\\n';
                     break;
                 case 114:
                     $value .= '\\r';
                     break;
                 case 116:
                     $value .= '\\t';
                     break;
                 case 117:
                     $hex = mb_substr($body, $position + 1, 4);
                     if (!preg_match('/[0-9a-fA-F]{4}/', $hex)) {
                         throw Exception::create($this->source, $position, 'Bad character escape sequence');
                     }
                     $value .= Utils::chr(hexdec($hex));
                     $position += 4;
                     break;
                 default:
                     throw Exception::create($this->source, $position, 'Bad character escape sequence');
             }
             ++$position;
             $chunkStart = $position;
         }
     }
     if ($code !== 34) {
         throw Exception::create($this->source, $position, 'Unterminated string');
     }
     $value .= mb_substr($body, $chunkStart, $position - $chunkStart, 'UTF-8');
     return new Token(Token::STRING, $start, $position + 1, $value);
 }