check some syntax errors in parser

This commit is contained in:
Gokcehan 2016-10-16 14:19:19 +03:00
parent 5470783f99
commit 5d0dfcde79
2 changed files with 15 additions and 17 deletions

View File

@ -29,6 +29,8 @@ func client() {
nav := newNav(ui.wins[0].h) nav := newNav(ui.wins[0].h)
app := &App{ui, nav} app := &App{ui, nav}
app.ui.loadFile(app.nav)
if _, err := os.Stat(gConfigPath); err == nil { if _, err := os.Stat(gConfigPath); err == nil {
log.Printf("reading configuration file: %s", gConfigPath) log.Printf("reading configuration file: %s", gConfigPath)
@ -37,21 +39,19 @@ func client() {
msg := fmt.Sprintf("opening configuration file: %s", err) msg := fmt.Sprintf("opening configuration file: %s", err)
app.ui.message = msg app.ui.message = msg
log.Printf(msg) log.Printf(msg)
} else {
app.ui.loadFile(app.nav)
} }
defer rcFile.Close() defer rcFile.Close()
p := newParser(rcFile) p := newParser(rcFile)
for p.parse() { for p.parse() {
if p.err != nil {
app.ui.message = "see the log file for errors in the configuration file"
log.Print(p.err)
}
p.expr.eval(app, nil) p.expr.eval(app, nil)
} }
// TODO: parser error check
} }
app.ui.loadFile(app.nav)
app.ui.draw(app.nav) app.ui.draw(app.nav)
app.handleInp() app.handleInp()

View File

@ -110,21 +110,21 @@ func (p *Parser) parseExpr() Expr {
var result Expr var result Expr
// TODO: syntax error check
switch s.typ { switch s.typ {
case TokenEOF: case TokenEOF:
return nil return nil
case TokenSemicolon:
s.scan()
case TokenIdent: case TokenIdent:
switch s.tok { switch s.tok {
case "set": case "set":
var val string
s.scan() s.scan()
if s.typ != TokenIdent {
p.err = fmt.Errorf("expected identifier: %s", s.tok)
}
opt := s.tok opt := s.tok
s.scan() s.scan()
var val string
if s.typ != TokenSemicolon { if s.typ != TokenSemicolon {
val = s.tok val = s.tok
s.scan() s.scan()
@ -195,19 +195,17 @@ func (p *Parser) parseExpr() Expr {
result = &ListExpr{exprs} result = &ListExpr{exprs}
case TokenPrefix: case TokenPrefix:
var expr string
pref := s.tok pref := s.tok
s.scan() s.scan()
var expr string
if s.typ == TokenLBraces { if s.typ == TokenLBraces {
s.scan() s.scan()
expr = s.tok expr = s.tok
s.scan() s.scan()
} else if s.typ == TokenCommand {
expr = s.tok
} else { } else {
// TODO: handle error expr = s.tok
} }
s.scan() s.scan()
@ -215,7 +213,7 @@ func (p *Parser) parseExpr() Expr {
result = &ExecExpr{pref, expr} result = &ExecExpr{pref, expr}
default: default:
// TODO: handle error p.err = fmt.Errorf("unexpected token: %s", s.tok)
} }
return result return result