From 486ec3ba9d91259426fd51c40e2d0523640d7326 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Sun, 25 Oct 2015 17:03:21 +0100 Subject: [PATCH] Removed panic on "no tokens provided". --- README.md | 4 ++-- ToDo.md | 3 +++ in/sub/empty.asl | 0 out/sub/empty.sqf | 0 src/asl/parser.go | 4 +++- src/asl/parserHelper.go | 6 ++++-- 6 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 in/sub/empty.asl create mode 100644 out/sub/empty.sqf diff --git a/README.md b/README.md index 3b44735..71554d2 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ asl [-v|-r|-pretty|--help] | -r | optional | Read input directory recursively. | | -pretty | optional | Enable pretty printing to SQF. | | --help | optional | Show usage. | -| | required | Directory to read ASL files from. | -| | 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:** diff --git a/ToDo.md b/ToDo.md index 4eb2482..bd1bb5d 100644 --- a/ToDo.md +++ b/ToDo.md @@ -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 diff --git a/in/sub/empty.asl b/in/sub/empty.asl new file mode 100644 index 0000000..e69de29 diff --git a/out/sub/empty.sqf b/out/sub/empty.sqf new file mode 100644 index 0000000..e69de29 diff --git a/src/asl/parser.go b/src/asl/parser.go index d1d320d..a95246b 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -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() diff --git a/src/asl/parserHelper.go b/src/asl/parserHelper.go index f1b31b2..d8cd090 100644 --- a/src/asl/parserHelper.go +++ b/src/asl/parserHelper.go @@ -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.