parse let expressions, handle syntax errors
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user