Skip to content

Commit

Permalink
🐛 Make skipped tokens explicit so that braces work
Browse files Browse the repository at this point in the history
Whenever tokens were skipped there was a possibility of parsing braces
incorrectly which messed up the scopes.
  • Loading branch information
ChmielewskiKamil committed Dec 17, 2024
1 parent 77c5a13 commit bf2f684
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,20 @@ func (p *Parser) parseSourceUnitDeclaration() ast.Declaration {
default:
// TODO: Once this function is fully implemented, the default case
// should only be hit on errors. Add the parses error then.
// p.errors.Add(p.currTkn.Pos, "Unhandled declaration type in the SourceUnit: "+p.currTkn.Literal)
p.errors.Add(p.currTkn.Pos, "Unhandled declaration type in the SourceUnit: "+p.currTkn.Literal)
return nil

case tk == token.COMMENT_LITERAL:
// TODO Parse comments; skip for now
return nil

case tk == token.PRAGMA:
// TODO parse pragma; skip for now
for !p.currTknIs(token.SEMICOLON) {
p.nextToken()
}
return nil

// pragma
// import-directive
// using-directive

Expand Down Expand Up @@ -249,10 +259,17 @@ func (p *Parser) parseContractBody() *ast.ContractBody {
default:
// TODO Once this function is fully implemented, throw parses errors
// when default case is hit.
// p.errors.Add(p.currTkn.Pos, "Unhandled declaration in contract's body: "+p.currTkn.Literal)
p.errors.Add(p.currTkn.Pos, "Unhandled declaration in contract's body: "+p.currTkn.Literal)
p.nextToken()
case tk == token.COMMENT_LITERAL:
// TODO Parse comments
p.nextToken()

// case tk == token.CONSTRUCTOR: // Constructor definition
case tk == token.CONSTRUCTOR: // Constructor definition
for !p.currTknIs(token.RBRACE) {
p.nextToken()
}
p.nextToken() // Move past RBRACE

case tk == token.FUNCTION: // Function definition
decls = append(decls, p.parseFunctionDeclaration())
Expand Down

0 comments on commit bf2f684

Please sign in to comment.