[svn] r6482: nemerle/trunk/ncc/parsing/PreParser.n

VladD2 svnadmin at nemerle.org
Sat Aug 5 01:36:56 CEST 2006


Log:
Fix location in "using parsing notification" and error message.

Author: VladD2
Date: Sat Aug  5 01:36:50 2006
New Revision: 6482

Modified:
   nemerle/trunk/ncc/parsing/PreParser.n

Modified: nemerle/trunk/ncc/parsing/PreParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/PreParser.n	(original)
+++ nemerle/trunk/ncc/parsing/PreParser.n	Sat Aug  5 01:36:50 2006
@@ -354,7 +354,7 @@
                   | [] => ([x], [tok1.Location, tok2.Location])
                   | _  => (x :: ident, tok1.Location :: tok2.Location :: locs)
                 }
-              | t => push_back (t); ([x], [tok1.Location, tok2.Location])
+              | t => push_back (t); ([x], [tok1.Location])
             }
           | t =>
             Message.Error (t.Location, $"expected qualified identifier, got token $t");
@@ -363,6 +363,11 @@
         }
       }
 
+      def make_before_location (location)
+      {
+        Location(location.FileIndex, location.Line, location.Column);
+      }
+      
       def parse_using_directive (tok)
       {
         finish_current (current_begin);
@@ -377,8 +382,8 @@
             def using_tok = Token.Using (loc, Env);
             current_stream.Add (using_tok);
 
-            lexer.Manager.OnAfterUsingDirectiveParse(
-              loc + st.Location, id, idLocs, currentNsEnv, Env);
+            lexer.Manager.OnAfterUsingDirectiveParse(loc 
+              + make_before_location (st.Location), id, idLocs, currentNsEnv, Env);
             
           | Token.Operator ("=") =>
             def (id', idLocs') = get_qualified_identifier ();
@@ -386,7 +391,9 @@
             def st = get_token ();
             match (st) {
               | Token.Semicolon => ()
-              | _ => Message.Error (st.Location, "expecting `;' after using alias")
+              | _ =>
+                push_back (st);
+                Message.Error (st.Location, "expecting `;' after using alias")
             }
 
             match (id) {
@@ -397,12 +404,18 @@
             def using_tok = Token.Using (tok.Location + st.Location, Env);
             current_stream.Add (using_tok);
             
-            lexer.Manager.OnAfterUsingDirectiveParse(tok.Location + st.Location, 
-              id', idLocs', currentNsEnv, Env);
+            lexer.Manager.OnAfterUsingDirectiveParse(tok.Location 
+              + make_before_location (st.Location), id', idLocs', currentNsEnv, Env);
 
           | x => 
-            Message.Error (x.Location, "expecting `;' or `='");
-            lexer.Manager.OnAfterUsingDirectiveParse(tok.Location + lexer.Location, 
+            push_back (x);
+            // The error message must point to last using token
+            def loc = match (idLocs) { | [] => tok.Location | _ => idLocs.Last };
+            def loc = Location(loc.FileIndex, loc.EndLine, loc.EndColumn);
+            Message.Error (loc, "expecting `;' or `='");
+            // In notification location must point before first token of next directive
+            lexer.Manager.OnAfterUsingDirectiveParse(tok.Location 
+              + make_before_location (x.Location),
               id, idLocs, currentNsEnv, Env);
         }
 



More information about the svn mailing list