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)
app := &App{ui, nav}
app.ui.loadFile(app.nav)
if _, err := os.Stat(gConfigPath); err == nil {
log.Printf("reading configuration file: %s", gConfigPath)
@ -37,21 +39,19 @@ func client() {
msg := fmt.Sprintf("opening configuration file: %s", err)
app.ui.message = msg
log.Printf(msg)
} else {
app.ui.loadFile(app.nav)
}
defer rcFile.Close()
p := newParser(rcFile)
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)
}
// TODO: parser error check
}
app.ui.loadFile(app.nav)
app.ui.draw(app.nav)
app.handleInp()

View File

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