diff --git a/src/Ast/IdentList.php b/src/Ast/IdentList.php index 0662425..6b2229f 100644 --- a/src/Ast/IdentList.php +++ b/src/Ast/IdentList.php @@ -22,9 +22,9 @@ public function __construct( public static function fromExprList(ExprList $list): self { return new self(\array_map( - static fn (Expr $expr): Ident => $expr instanceof Ident ? - $expr : - throw new InvalidArgument('Cannot create IdentList from an arbitrary expression list'), + static fn (Expr $expr): Ident => $expr instanceof Ident + ? $expr + : throw new InvalidArgument('Cannot create IdentList from an arbitrary expression list'), $list->exprs, )); } @@ -32,9 +32,9 @@ public static function fromExprList(ExprList $list): self public static function fromTypeList(TypeList $list): self { return new self(\array_map( - static fn (Type $type): Ident => $type instanceof SingleTypeName ? - $type->name : - throw new InvalidArgument('Cannot create IdentList from an arbitrary type list'), + static fn (Type $type): Ident => $type instanceof SingleTypeName + ? $type->name + : throw new InvalidArgument('Cannot create IdentList from an arbitrary type list'), $list->types, )); } diff --git a/src/NodeDumper.php b/src/NodeDumper.php index 3a3e6a9..ff733f7 100644 --- a/src/NodeDumper.php +++ b/src/NodeDumper.php @@ -81,9 +81,9 @@ private static function type(AstNode $node): string default => null, }; - return $type === null ? - self::name($node) : - \sprintf("[%s] %s", $type, self::name($node)); + return $type === null + ? self::name($node) + : \sprintf("[%s] %s", $type, self::name($node)); } private function printProp(AstNode $node, \ReflectionProperty $property, int $indent): void @@ -149,9 +149,9 @@ private function getPos(AstNode $node): string $pos = new Position( $value->offset, $value->line, - $this->showFilename ? - $value->filename : - null + $this->showFilename + ? $value->filename + : null ); return (string) $pos; diff --git a/src/Parser.php b/src/Parser.php index 3b6bdcf..f87e431 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -348,27 +348,27 @@ private function parseFuncOrMethodDecl(): FuncDecl|MethodDecl { $keyword = $this->parseKeyword(Token::Func); - $receiver = $this->match(Token::LeftParen) ? - $this->parseParams(false) : - null; + $receiver = $this->match(Token::LeftParen) + ? $this->parseParams(false) + : null; $name = $this->parseIdent(); - $typeParams = $receiver === null && $this->match(Token::LeftBracket) ? - $this->parseTypeParams() : - null; + $typeParams = $receiver === null && $this->match(Token::LeftBracket) + ? $this->parseTypeParams() + : null; $sign = $this->parseSignature(); - $body = $this->match(Token::LeftBrace) ? - $this->parseBlockStmt() : - null; + $body = $this->match(Token::LeftBrace) + ? $this->parseBlockStmt() + : null; $this->parseSemicolon(); - return $receiver === null ? - new FuncDecl($keyword, $name, $typeParams, $sign, $body) : - new MethodDecl($keyword, $receiver, $name, $sign, $body); + return $receiver === null + ? new FuncDecl($keyword, $name, $typeParams, $sign, $body) + : new MethodDecl($keyword, $receiver, $name, $sign, $body); } private function parseStmt(): Stmt @@ -487,9 +487,9 @@ private function parseTypeTerm(): TypeTerm $tilda = $this->tryParseOperator(Token::Tilda); $type = $this->parseType(); - return $tilda !== null ? - new UnderlyingType($tilda, $type) : - $type; + return $tilda !== null + ? new UnderlyingType($tilda, $type) + : $type; } private function parseSelectStmt(): SelectStmt @@ -651,9 +651,9 @@ private function parseForStmt(): ForStmt case $this->checkAheadTill(Token::LeftBrace, Token::Semicolon): $init = $this->parseSimpleStmt(); $cond = $this->parseSimpleStmt(); - $post = $this->match(Token::LeftBrace) ? - null : - $this->parseSimpleStmt(true); + $post = $this->match(Token::LeftBrace) + ? null + : $this->parseSimpleStmt(true); $iteration = new ForClause($init, $cond, $post); break; @@ -839,9 +839,9 @@ private function doParseCallExpr(): CallExpr private function parseEmptyStmt(bool $skipSemi = false): EmptyStmt { return new EmptyStmt( - $skipSemi ? - $this->peek()->pos : - $this->consume(Token::Semicolon)->pos + $skipSemi + ? $this->peek()->pos + : $this->consume(Token::Semicolon)->pos ); } @@ -850,9 +850,9 @@ private function parseSwitchStmt(): SwitchStmt $keyword = $this->parseKeyword(Token::Switch); $this->inCfHeader(); - $init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) ? - $this->parseSimpleStmt() : - null; + $init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) + ? $this->parseSimpleStmt() + : null; // ExprSwitchStmt // switch {} @@ -921,9 +921,9 @@ private function parseIfStmt(): IfStmt $if = $this->parseKeyword(Token::If); $this->inCfHeader(); - $init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) ? - $this->parseSimpleStmt() : - null; + $init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) + ? $this->parseSimpleStmt() + : null; $cond = $this->parseExpr(); $this->outCfHeader(); @@ -985,9 +985,9 @@ private function parseDeferStmt(): DeferStmt private function parseReturnStmt(): ReturnStmt { $keyword = $this->parseKeyword(Token::Return); - $exprs = $this->match(Token::Semicolon) ? - null : - $this->parseExprList(); + $exprs = $this->match(Token::Semicolon) + ? null + : $this->parseExprList(); $this->parseSemicolon(); @@ -1239,9 +1239,9 @@ private function parseCompositeLit(?Expr $type = null): CompositeLit } $lBrace = $this->parsePunctuation(Token::LeftBrace); - $elemList = $this->match(Token::RightBrace) ? - null : - $this->parseElementList(); + $elemList = $this->match(Token::RightBrace) + ? null + : $this->parseElementList(); $rBrace = $this->parsePunctuation(Token::RightBrace); return new CompositeLit($type, $lBrace, $elemList, $rBrace); @@ -1252,9 +1252,9 @@ private static function tryTypeFromExpr(?Expr $expr): ?Type return match (true) { $expr instanceof Type => $expr, $expr instanceof Ident => new SingleTypeName($expr, null), - $expr instanceof SelectorExpr => $expr->expr instanceof Ident ? - new QualifiedTypeName($expr->expr, new SingleTypeName($expr->selector, null)) : - null, + $expr instanceof SelectorExpr => $expr->expr instanceof Ident + ? new QualifiedTypeName($expr->expr, new SingleTypeName($expr->selector, null)) + : null, default => null, }; } @@ -1295,9 +1295,9 @@ private function parseKeyedElement(): KeyedElement private function parseElement(): Expr { - return $this->match(Token::LeftBrace) ? - $this->parseCompositeLit() : - $this->parseExpr(); + return $this->match(Token::LeftBrace) + ? $this->parseCompositeLit() + : $this->parseExpr(); } private function parseCallExpr(Expr $expr): CallExpr @@ -1531,9 +1531,9 @@ private function parseParamDecls(bool $variadic): array private function parseResult(): Params|Type|null { - return $this->match(Token::LeftParen) ? - $this->parseParams(false) : - $this->tryParseType(); + return $this->match(Token::LeftParen) + ? $this->parseParams(false) + : $this->tryParseType(); } private function tryParseType(): ?Type @@ -1765,9 +1765,9 @@ private function parseArrayOrSliceType(): ArrayType|SliceType $rParen = $this->parsePunctuation(Token::RightBracket); $elemType = $this->parseType(); - return $size === null ? - new SliceType($lParen, $rParen, $elemType) : - new ArrayType($lParen, $size, $rParen, $elemType); + return $size === null + ? new SliceType($lParen, $rParen, $elemType) + : new ArrayType($lParen, $size, $rParen, $elemType); } private function parseAnyOperator(): Operator @@ -1782,9 +1782,9 @@ private function parseOperator(Token $token): Operator private function tryParseOperator(Token $token): ?Operator { - return $this->match($token) ? - Operator::fromLexeme($this->consume($token)) : - null; + return $this->match($token) + ? Operator::fromLexeme($this->consume($token)) + : null; } private function parseIdent(): Ident @@ -1794,30 +1794,30 @@ private function parseIdent(): Ident private function tryParseIdent(): ?Ident { - return $this->match(Token::Ident) ? - Ident::fromLexeme($this->consume(Token::Ident)) : - null; + return $this->match(Token::Ident) + ? Ident::fromLexeme($this->consume(Token::Ident)) + : null; } private function parseTypeName(): TypeName { $ident = Ident::fromLexeme($this->consume(Token::Ident)); - $typeName = $this->consumeIf(Token::Dot) !== null ? - Ident::fromLexeme($this->consume(Token::Ident)) : - null; + $typeName = $this->consumeIf(Token::Dot) !== null + ? Ident::fromLexeme($this->consume(Token::Ident)) + : null; - $typeArgs = $this->match(Token::LeftBracket) ? - $this->parseTypeArgs() : - null; + $typeArgs = $this->match(Token::LeftBracket) + ? $this->parseTypeArgs() + : null; if ($typeArgs !== null && empty($typeArgs)) { $this->error('empty type parameter list'); } - return $typeName === null ? - new SingleTypeName($ident, $typeArgs) : - new QualifiedTypeName( + return $typeName === null + ? new SingleTypeName($ident, $typeArgs) + : new QualifiedTypeName( $ident, new SingleTypeName($typeName, $typeArgs), ); @@ -1827,9 +1827,9 @@ private function parseTypeNameInParams(): TypeName { $ident = Ident::fromLexeme($this->consume(Token::Ident)); - $typeName = $this->consumeIf(Token::Dot) !== null ? - Ident::fromLexeme($this->consume(Token::Ident)) : - null; + $typeName = $this->consumeIf(Token::Dot) !== null + ? Ident::fromLexeme($this->consume(Token::Ident)) + : null; $typeArgs = null; @@ -1840,9 +1840,9 @@ private function parseTypeNameInParams(): TypeName $typeArgs = $this->parseTypeArgs(); } - return $typeName === null ? - new SingleTypeName($ident, $typeArgs) : - new QualifiedTypeName( + return $typeName === null + ? new SingleTypeName($ident, $typeArgs) + : new QualifiedTypeName( $ident, new SingleTypeName($typeName, $typeArgs), ); @@ -1913,9 +1913,9 @@ private function parsePunctuation(Token $token): Punctuation private function tryParsePunctuation(Token $token): ?Punctuation { - return $this->match($token) ? - Punctuation::fromLexeme($this->consume($token)) : - null; + return $this->match($token) + ? Punctuation::fromLexeme($this->consume($token)) + : null; } private function inCfHeader(): void @@ -1937,9 +1937,9 @@ private function parseSemicolon(): void private function consume(Token $token): Lexeme { - return $this->match($token) ? - $this->advance() : - $this->error(\sprintf( + return $this->match($token) + ? $this->advance() + : $this->error(\sprintf( 'unexpected token \'%s\', expecting \'%s\'', $this->peek()->token->name, $token->name,