-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking up parser file into smaller ones
- Loading branch information
Showing
3 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/54L1m/mil-lang/token" | ||
) | ||
|
||
func (p *Parser) Errors() []string { | ||
return p.errors | ||
} | ||
|
||
func (p *Parser) peekError(t token.TokenType) { | ||
msg := fmt.Sprintf("expected next token to be %s, got %s instead", | ||
t, p.peekToken.Type) | ||
p.errors = append(p.errors, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package parser | ||
|
||
import "github.com/54L1m/mil-lang/token" | ||
|
||
func (p *Parser) nextToken() { | ||
p.curToken = p.peekToken | ||
p.peekToken = p.l.NextToken() | ||
} | ||
|
||
func (p *Parser) curTokenIs(t token.TokenType) bool { | ||
return p.curToken.Type == t | ||
} | ||
|
||
func (p *Parser) peekTokenIs(t token.TokenType) bool { | ||
return p.peekToken.Type == t | ||
} | ||
|
||
func (p *Parser) expectPeek(t token.TokenType) bool { | ||
if p.peekTokenIs(t) { | ||
p.nextToken() | ||
return true | ||
} else { | ||
p.peekError(t) | ||
return false | ||
} | ||
} |