remove error handling in scanner

This commit is contained in:
Gokcehan committed 2016-10-15 22:59:31 +03:00
1 parent a3965ca1d9
commit 5470783f99
3 files changed
+42 -38

No files matched your search

+19 -1
View File
@@ -35,6 +35,12 @@ var gTests = []struct {
[]Expr{&SetExpr{"hidden", ""}, &SetExpr{"preview", ""}},
},
{
"set hidden\nset preview",
[]string{"set", "hidden", "\n", "set", "preview", "\n"},
[]Expr{&SetExpr{"hidden", ""}, &SetExpr{"preview", ""}},
},
{
"set ratios 1:2:3",
[]string{"set", "ratios", "1:2:3", "\n"},
@@ -53,12 +59,24 @@ var gTests = []struct {
[]Expr{&ListExpr{[]Expr{&SetExpr{"ratios", "1:2:3"}}}},
},
{
":set ratios 1:2:3\nset hidden",
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
[]Expr{&ListExpr{[]Expr{&SetExpr{"ratios", "1:2:3"}}}, &SetExpr{"hidden", ""}},
},
{
":set ratios 1:2:3;",
[]string{":", "set", "ratios", "1:2:3", ";", "\n"},
[]Expr{&ListExpr{[]Expr{&SetExpr{"ratios", "1:2:3"}}}},
},
{
":set ratios 1:2:3;\nset hidden",
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
[]Expr{&ListExpr{[]Expr{&SetExpr{"ratios", "1:2:3"}}}, &SetExpr{"hidden", ""}},
},
{
"map gh cd ~",
[]string{"map", "gh", "cd", "~", "\n"},
@@ -126,7 +144,7 @@ var gTests = []struct {
},
{
"map r push :rename<space> # trailing comments area allowed after a space",
"map r push :rename<space> # trailing comments are allowed after a space",
[]string{"map", "r", "push", ":rename<space>", "\n"},
[]Expr{&MapExpr{"r", &CallExpr{"push", []string{":rename<space>"}}}},
},
-10
View File
@@ -159,11 +159,6 @@ func (p *Parser) parseExpr() Expr {
s.scan()
if s.err != nil {
p.err = fmt.Errorf("parsing: %s", s.err)
return nil
}
result = &CallExpr{name, args}
}
case TokenColon:
@@ -218,11 +213,6 @@ func (p *Parser) parseExpr() Expr {
s.scan()
s.scan()
if s.err != nil {
p.err = fmt.Errorf("parsing: %s", s.err)
return nil
}
result = &ExecExpr{pref, expr}
default:
// TODO: handle error
+23 -27
View File
@@ -10,8 +10,7 @@ import (
type TokenType int
const (
TokenErr TokenType = iota
TokenEOF // end of file
TokenEOF TokenType = iota
// no explicit keyword type
TokenIdent // e.g. set, ratios, 1:2:3
TokenColon // :
@@ -35,7 +34,6 @@ type Scanner struct {
cmd bool // scanning command
typ TokenType // scanned token type
tok string // scanned token value
err error // error if any
// TODO: pos
}
@@ -110,6 +108,8 @@ scan:
s.nln = false
return true
}
s.typ = TokenEOF
s.tok = "EOF"
return false
case s.key:
beg := s.off
@@ -145,7 +145,9 @@ scan:
}
}
}
// TODO: fill error
s.typ = TokenEOF
s.tok = "EOF"
return false
case s.cmd:
for !s.eof && isSpace(s.chr) {
@@ -208,27 +210,19 @@ scan:
s.tok = ":"
s.nln = true
s.next()
case s.chr == '{':
if s.peek() == '{' {
s.next()
s.next()
s.typ = TokenLBraces
s.tok = "{{"
s.sem = false
s.nln = false
return true
}
// TODO: handle error
case s.chr == '}':
if s.peek() == '}' {
s.next()
s.next()
s.typ = TokenRBraces
s.tok = "}}"
s.sem = true
return true
}
// TODO: handle error
case s.chr == '{' && s.peek() == '{':
s.next()
s.next()
s.typ = TokenLBraces
s.tok = "{{"
s.sem = false
s.nln = false
case s.chr == '}' && s.peek() == '}':
s.next()
s.next()
s.typ = TokenRBraces
s.tok = "}}"
s.sem = true
case isPrefix(s.chr):
s.typ = TokenPrefix
s.tok = string(s.chr)
@@ -239,15 +233,17 @@ scan:
for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {
s.next()
}
s.typ = TokenIdent
s.tok = string(s.buf[beg:s.off])
s.sem = true
if s.tok == "push" {
s.key = true
for isSpace(s.chr) {
for !s.eof && isSpace(s.chr) && s.chr != '\n' {
s.next()
}
}
s.sem = true
}
return true