]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added location information to error messages
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 30 Oct 2014 19:58:51 +0000 (15:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 30 Oct 2014 19:58:51 +0000 (15:58 -0400)
source/sclpl/grammar.c
source/sclpl/main.c
source/sclpl/parser.c
spec/parser_spec.rb

index 4beecf7d48a8b938a431c93c6f95b8362ccae023..7b63a5cc86d9f7b2cf435c48dc0d9efaa9f4de2b 100644 (file)
@@ -24,7 +24,7 @@ tree_t* grammar_toplevel(parser_t* p)
             grammar_expression(p);
         p_tree = parser_get_tree(p);
     } catch(ParseException) {
-        fprintf(stderr, "Invalid Syntax\n");
+        /* Do nothing, the tree is bad */
     }
     return p_tree;
 }
@@ -136,7 +136,7 @@ void grammar_literal(parser_t* p)
             break;
 
         default:
-            parser_error(p, "Not a valid expression");
+            parser_error(p, "Expected a literal");
     }
 }
 
index 9b77876da47ca5caf81c4d5a8b606e60181c880c..91aef7627d698d08419334d11b33f36fe42a1bb9 100644 (file)
@@ -266,7 +266,8 @@ str_t* syntax_file(str_t* in) {
         fclose(output);
     } else {
         fclose(output);
-        remove(str_cstr(ofname));
+        if (NULL != ofname)
+            remove(str_cstr(ofname));
         mem_release(ofname);
         ofname = NULL;
     }
index 3d088303a15a3b2377b7ac8ba019a24c454861c2..5930d18277ceb0b707ff0def7ca7efdd73f7245a 100644 (file)
@@ -59,6 +59,8 @@ void parser_resume(parser_t* p_parser) {
 void parser_error(parser_t* p_parser, const char* p_text)
 {
     (void)p_parser;
+    lex_tok_t* tok = parser_peek(p_parser);
+    fprintf(stderr, "<file>:%zu:%zu:Error: %s\n", tok->line, tok->col, p_text);
     throw_msg(ParseException, p_text);
 }
 
index 89b254222e72362e8dd6a0933de2a6788c58d170..a7262cd67938b1e69c04871ef59302d28f3820b7 100644 (file)
@@ -11,19 +11,19 @@ describe "sclpl grammar" do
     end
 
     it "should error on missing semicolon" do
-      expect{ast('require "foo"')}.to raise_error /Invalid Syntax/
+      expect{ast('require "foo"')}.to raise_error /Error/
     end
 
     it "should error on missing filename" do
-      expect{ast('require ;')}.to raise_error /Invalid Syntax/
+      expect{ast('require ;')}.to raise_error /Error/
     end
 
     it "should error on invalid filename type" do
-      expect{ast('require 123;')}.to raise_error /Invalid Syntax/
+      expect{ast('require 123;')}.to raise_error /Error/
     end
 
     it "should error on too many parameters" do
-      expect{ast('require foo bar;')}.to raise_error /Invalid Syntax/
+      expect{ast('require foo bar;')}.to raise_error /Error/
     end
   end
 
@@ -216,11 +216,11 @@ describe "sclpl grammar" do
 
   context "corner cases" do
     it "an unexpected terminator should error" do
-      expect{ast(';')}.to raise_error /Invalid Syntax/
+      expect{ast(';')}.to raise_error /Error/
     end
 
     it "an invalid literal should error" do
-      expect{ast('\'')}.to raise_error /Invalid Syntax/
+      expect{ast('\'')}.to raise_error /Error/
     end
   end
 end