Beispiel #1
0
function ParseField(TokenStream $it, ASTEntity $entity)
{
    $f = new ASTField();
    $f->annotations = ParseAnnotations($it);
    $type = ParseDataType($it);
    $identifier = $it->getToken([SyntaxMap::Identifier, SyntaxMap::DataType]);
    //Verify if entity is already declared
    $entityKey = strtolower($entity->name);
    $key = strtolower($identifier->value);
    if (isset($it->entities[$entityKey][$key])) {
        throw ParserException::redeclaredField($entity, $identifier);
    } else {
        $it->entities[$entityKey][$key] = [];
    }
    if ($it->typeAt(SyntaxMap::AssignOp, 0)) {
        $it->getAndMove();
        $val = $it->getToken([SyntaxMap::String, SyntaxMap::Number]);
        $f->default = $val;
    }
    $it->getToken(SyntaxMap::Semicolon);
    $f->type = $type;
    $f->name = $identifier->value;
    return $f;
}
Beispiel #2
0
 public function expectAny($typeArr, $at = 0)
 {
     $p = $this->pos + $at;
     if (isset($this->tokens[$p])) {
         $t = $this->tokens[$p];
         if (!in_array($t->type, $typeArr, true)) {
             $tokenType = [];
             foreach ($typeArr as $type) {
                 $tokenType[] = SyntaxMap::$map[$type];
             }
             $tokenTypeStr = implode(",", $tokenType);
             throw ParserException::expectedToken($t, $tokenTypeStr);
         }
         return $t;
     }
     throw ParserException::indexOutOfRange($p);
 }