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

@@ -28,8 +28,8 @@ asl [-v|-r|-pretty|--help] <input directory> <output directory>
| -r | optional | Read input directory recursively. |
| -pretty | optional | Enable pretty printing to SQF. |
| --help | optional | Show usage. |
| <input directory> | required | Directory to read ASL files from. |
| <output directory> | required | Directory for SQF output. Can be the same as input directory. |
| input directory | required | Directory to read ASL files from. |
| output directory | required | Directory for SQF output. Can be the same as input directory. |
**Example:**

View File

@@ -11,6 +11,9 @@
* ~~negative values e.g. -1, operator !~~
* ~~tokenizer splits commands like "format" -> for, mat~~
* ~~try ... catch~~
* better error reporting
- recover panic
- line, column
## Special cases

0
in/sub/empty.asl Normal file
View File

0
out/sub/empty.sqf Normal file
View File

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.