Removed panic on "no tokens provided".

This commit is contained in:
Marvin Blum
2015-10-25 17:03:21 +01:00
parent 4471ae285e
commit 486ec3ba9d
6 changed files with 12 additions and 5 deletions

View File

@@ -9,7 +9,9 @@ const TAB = " "
// Parses tokens, validates code to a specific degree
// and writes SQF code into desired location.
func Parse(token []Token, prettyPrinting bool) string {
initParser(token, prettyPrinting)
if !initParser(token, prettyPrinting) {
return ""
}
for tokenIndex < len(token) {
parseBlock()

View File

@@ -7,9 +7,9 @@ var offset int
var pretty bool
// Initilizes the parser.
func initParser(token []Token, prettyPrinting bool) {
func initParser(token []Token, prettyPrinting bool) bool {
if len(token) == 0 {
panic("No tokens provided")
return false
}
tokens = token
@@ -17,6 +17,8 @@ func initParser(token []Token, prettyPrinting bool) {
out = ""
offset = 0
pretty = prettyPrinting
return true
}
// Returns true, if current token matches expected one.