about summary refs log tree commit diff
path: root/src/libexpr/parser.y
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-04-05T22·27+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-04-05T22·27+0000
commit59b94ee18ac0cba5c7b261ee72550a4d3db0acb5 (patch)
tree9dbe6721699439cda3ce68ac86acbe38e9839e66 /src/libexpr/parser.y
parenta520b1cbc3327dfb8e3c6f503dfd0bd41e0a6d55 (diff)
* When something goes wrong in the evaluation of a Nix expression,
  print a nice backtrace of the stack, rather than vomiting a gigantic
  (and useless) aterm on the screen.  Example:

    error: while evaluating file `.../pkgs/system/test.nix':
    while evaluating attribute `subversion' at `.../pkgs/system/all-packages-generic.nix', line 533:
    while evaluating function at `.../pkgs/applications/version-management/subversion/default.nix', line 1:
    assertion failed at `.../pkgs/applications/version-management/subversion/default.nix', line 13

  Since the Nix expression language is lazy, the trace may be
  misleading.  The purpose is to provide a hint as to the location of
  the problem.    
  

Diffstat (limited to 'src/libexpr/parser.y')
-rw-r--r--src/libexpr/parser.y19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index cfcbc589f61c..347516f69239 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -19,11 +19,20 @@ void setParseResult(void * data, ATerm t);
 void parseError(void * data, char * error, int line, int column);
 ATerm absParsedPath(void * data, ATerm t);
 ATerm fixAttrs(int recursive, ATermList as);
+const char * getPath(void * data);
 
 void yyerror(YYLTYPE * loc, yyscan_t scanner, void * data, char * s)
 {
     parseError(data, s, loc->first_line, loc->first_column);
 }
+
+ATerm makePos(YYLTYPE * loc, void * data)
+{
+    return ATmake("Pos(<str>, <int>, <int>)",
+        getPath(data), loc->first_line, loc->first_column);
+}
+
+#define CUR_POS makePos(yylocp, data)
  
 %}
 
@@ -55,15 +64,15 @@ expr: expr_function;
 
 expr_function
   : '{' formals '}' ':' expr_function
-    { $$ = ATmake("Function(<term>, <term>)", $2, $5); }
+    { $$ = ATmake("Function(<term>, <term>, <term>)", $2, $5, CUR_POS); }
   | ID ':' expr_function
-    { $$ = ATmake("Function1(<term>, <term>)", $1, $3); }
+    { $$ = ATmake("Function1(<term>, <term>, <term>)", $1, $3, CUR_POS); }
   | expr_assert
   ;
 
 expr_assert
   : ASSERT expr ';' expr_assert
-    { $$ = ATmake("Assert(<term>, <term>)", $2, $4); }
+    { $$ = ATmake("Assert(<term>, <term>, <term>)", $2, $4, CUR_POS); }
   | expr_if
   ;
 
@@ -123,9 +132,9 @@ binds
 
 bind
   : ID '=' expr ';'
-    { $$ = ATmake("Bind(<term>, <term>)", $1, $3); }
+    { $$ = ATmake("Bind(<term>, <term>, <term>)", $1, $3, CUR_POS); }
   | INHERIT inheritsrc ids ';'
-    { $$ = ATmake("Inherit(<term>, <term>)", $2, $3); }
+    { $$ = ATmake("Inherit(<term>, <term>, <term>)", $2, $3, CUR_POS); }
   ;
 
 inheritsrc