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

IT svnadmin at nemerle.org
Tue Oct 3 04:21:39 CEST 2006


Log:
#region/#endregion validation.

Author: IT
Date: Tue Oct  3 04:21:36 2006
New Revision: 6744

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

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Tue Oct  3 04:21:36 2006
@@ -215,6 +215,31 @@
   public Reset () : void {  }
 }
 
+public class Region
+{
+  public this(location : Location, text : string)
+  {
+    this.location = location;
+    this.text     = if (text == null) string.Empty else text;
+  }
+
+  [Accessor] mutable isComplete : bool;
+  [Accessor] mutable location   : Location;
+  [Accessor]         text       : string;
+
+  internal SetEndRegion(loc : Location) : void
+  {
+    when (isComplete)
+      throw System.InvalidOperationException("region is complete.");
+
+    when (location.FileIndex != loc.FileIndex)
+      throw System.InvalidOperationException("invalid endregion.");
+
+    isComplete = true;
+    location   = Location(location.FileIndex, location.Line, location.Column, loc.Line, loc.Column)
+  }
+}
+
 [ManagerAccess]
 public abstract class LexerBase : IDisposable
 {
@@ -295,6 +320,9 @@
 
   #endregion PREPROCESSOR VARIABLES
   
+  [Accessor] mutable incompleteRegions : list[Region] = [];
+  [Accessor] mutable regions           : list[Region] = [];
+
   public class Error : System.Exception
   {
     public name : string;
@@ -1196,9 +1224,17 @@
         Message.Warning (this.Location, read_to_the_end_of_line ().Trim ());
 
       | "region" =>
-        _ = read_to_the_end_of_line ();
+        incompleteRegions ::= Region(this.Location, read_to_the_end_of_line ().Trim ());
         
       | "endregion" =>
+        match (incompleteRegions)
+        {
+          | h :: t =>
+            h.SetEndRegion(this.Location);
+            regions ::= h;
+            incompleteRegions = t;
+          | [] => throw LexerBase.Error ("Unexpected preprocessor directive")
+        }
         _ = read_to_the_end_of_line ();
 
       | "define" =>

Modified: nemerle/trunk/ncc/parsing/PreParser.n
==============================================================================
--- nemerle/trunk/ncc/parsing/PreParser.n	(original)
+++ nemerle/trunk/ncc/parsing/PreParser.n	Tue Oct  3 04:21:36 2006
@@ -505,6 +505,13 @@
           | Token.Semicolon => finish_current (current_begin); loop ()
 
           | Token.EndOfFile when parent_begin == 0 =>
+            // check #region/#endregion completion
+            match (lexer.IncompleteRegions)
+            {
+              | h :: _ => Message.Error (h.Location, "#endregion directive expected")
+              | [] => ()
+            }
+
             def brace_group = finish_parent (parent_begin, current_begin);
             finished = true;
             last_declaration_token = tok;



More information about the svn mailing list