parse let expressions, handle syntax errors

This commit is contained in:
Tommy Parnell
2017-12-30 16:23:30 -05:00
parent 725e4dc5bf
commit 2742c41e98
3 changed files with 32 additions and 2 deletions

View File

@@ -16,6 +16,8 @@ let foobar = 838383;
p := New(l)
program := p.ParseProgram()
checkParserErrors(t, p)
if program == nil {
t.Fatalf("ParseProgram() returned nil")
}
@@ -40,6 +42,19 @@ let foobar = 838383;
}
}
func checkParserErrors(t *testing.T, p *Parser) {
errors := p.Errors()
if len(errors) == 0 {
return
}
t.Errorf("parser has %d errors", len(errors))
for _, msg := range errors {
t.Errorf("parser error: %q", msg)
}
t.FailNow()
}
func testLetStatement(t *testing.T, s ast.Statement, name string) bool {
if s.TokenLiteral() != "let" {
t.Errorf("s.TokenLiteral not 'let'. got=%q", s.TokenLiteral())