Skip to content

Commit

Permalink
Fix for embedded struct field parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Sep 9, 2023
1 parent b0e2380 commit 6a0e03f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Ast/FromLexeme.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
namespace GoParser\Ast;

use GoParser\Lexer\Lexeme;
use GoParser\Lexer\Position;

trait FromLexeme
{
public static function fromLexeme(Lexeme $lexeme): static
{
return new static($lexeme->pos, $lexeme->literal ?? $lexeme->token->value);
}

abstract public function __construct(Position $pos, string $literal);
}
7 changes: 3 additions & 4 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace GoParser;

interface Error
{
public function __toString(): string;
}
use Stringable;

interface Error extends Stringable {}
2 changes: 1 addition & 1 deletion src/Exception/ParseModeError.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ParseModeError extends BadMethodCallException
public function __construct(ParseMode $expected, ParseMode $actual)
{
parent::__construct(sprintf(
'Expected Parser to be initialised with Parse Mode "%s" , but got "%s"',
'Expected Parser to be initialised with Parse Mode "%s", but got "%s"',
$expected->name,
$actual->name
));
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ private function parseStructType(): StructType
$typeOrIdent = $this->parseType();
$tag = $this->tryParseTag();

if ($this->match(Token::Semicolon)) {
if ($this->matchAny(Token::Semicolon, Token::RightBrace)) {
if (
!$typeOrIdent instanceof TypeName
&& ($typeOrIdent instanceof PointerType && (!$typeOrIdent->type instanceof TypeName))
Expand Down

0 comments on commit 6a0e03f

Please sign in to comment.