[svn] r7703: nemerle/trunk/ncc: parsing/Lexer.n testsuite/positive/recursive-string.n

VladD2 svnadmin at nemerle.org
Thu Jun 14 01:18:12 CEST 2007


Log:
1. Fixed bug 1000 ($<# ... #> strings don't work)
2. Add positive tests for recursive string.

Author: VladD2
Date: Thu Jun 14 01:18:10 2007
New Revision: 7703

Added:
   nemerle/trunk/ncc/testsuite/positive/recursive-string.n
Modified:
   nemerle/trunk/ncc/parsing/Lexer.n

Modified: nemerle/trunk/ncc/parsing/Lexer.n
==============================================================================
--- nemerle/trunk/ncc/parsing/Lexer.n	(original)
+++ nemerle/trunk/ncc/parsing/Lexer.n	Thu Jun 14 01:18:10 2007
@@ -469,6 +469,20 @@
     clear_id_buffer ();
     _ = id_buffer.Append (first_ch);
 
+    continue_get_op ()
+  }
+
+  protected get_op (first_ch : char, second_ch : char) : Token
+  {
+    clear_id_buffer ();
+    _ = id_buffer.Append (first_ch);
+    _ = id_buffer.Append (second_ch);
+
+    continue_get_op ()
+  }
+
+  continue_get_op () : Token
+  {
     mutable go = true;
     while (go) {
       if (IsOperatorChar (peek_or_white ())) {
@@ -907,8 +921,8 @@
   {
     mutable nestingLevel = 1;
     def buf = Text.StringBuilder (1024);
-    //_ = buf.Append ("<#");
-    def (startLine, startCol) = (line, col/* - 2*/);
+    def startLine = line;
+    def startCol  = col;
     def loop (ch)
     {
       | '<' when peek () == '#' => _ = read (); nestingLevel++; _ = buf.Append ("<#"); loop (read ())
@@ -1108,21 +1122,40 @@
         Fake();
         def startLine = this.Location.Line;
         def startCol  = this.Location.Column;
-        _ = eat_whitespace ();
+        def isWhitespaceExists = eat_whitespace ();
         def next = peek ();
 
         match (next)
         {
-          | '"' | '@' | '<' when peek () == '#' =>
+          | '"' | '@' | '<' =>
             // we will not warn about $ in string literal in this mode
             def strStartLoc = this.Location;
             def c = read ();
+            def next = peek ();
             
+            if (c == '<' && next != '#')
+            { // emulate parse operator
+              if (isWhitespaceExists)
+              { // emulate parse 2 operators ($ and <...
+                def op = get_op ('<');
+                def dolLoc = Location(strStartLoc.FileIndex, startLine, startCol - 1, startLine, startCol);
+                def groupLok = dolLoc + op.Location;
+                def dolTok = Token.Operator (dolLoc, "$");
+                dolTok.Next = op;
+                Token.RoundGroup (groupLok, Token.LooseGroup (groupLok, dolTok))
+              }
+              else get_op ('$', '<')
+            }
+            else
+            {
             def str =
               if (c == '"')
                 get_string (c, true)
-              else if (c == '<' && peek () == '#')
+                else if (c == '<' && next == '#')
+                {
+                  ignore (read ());
                 get_recursive_string ()
+                }
               else
               {
                 unless (read () == '"')
@@ -1137,8 +1170,11 @@
             def dolTok = Token.Operator (dolLoc, "$");
             dolTok.Next = str;
             Token.RoundGroup (groupLok, Token.LooseGroup (groupLok, dolTok))
+            }
 
-          | _ => get_op (ch)
+          | _ => 
+            if (isWhitespaceExists) Token.Operator ("$")
+            else                    get_op ('$')
         }
                               
       | '^' | '~' | '?' | '#'

Added: nemerle/trunk/ncc/testsuite/positive/recursive-string.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/positive/recursive-string.n	Thu Jun 14 01:18:10 2007
@@ -0,0 +1,51 @@
+using System.Console;
+
+module Program
+{
+  Main() : void
+  {
+    def sss = $<#$("qwe")#>;
+    WriteLine(sss);
+    def sss = <#$("qwe")#>;
+    WriteLine(sss);
+    def sss = $ <#$("qwe")#>;
+    WriteLine(sss);
+    def sss = $ 
+      <#$("qwe")#>;
+    WriteLine(sss);
+    def sss = 
+      <#>>>>>>>>>>>>>>>>>
+        line 1 of multiline string
+        line 2 <# nested string <# very nested string :) #> #>
+        line 3 @" - this no monkey string!
+        line 4 " " " we can use "-charasters witout any problem!#>;
+    WriteLine(sss);
+    mutable i = 0;
+    def sss = $
+      <#>>>>>>>>>>>>>>>>>
+        line $({i++; i}) of multiline string
+        line $({i++; i}) <# nested string <# very nested string :) #> #>
+        line $({i++; i}) @" - this no monkey string!
+        line $({i++; i}) " " " we can use "-charasters witout any problem!#>;
+    WriteLine(sss);
+  }
+}
+
+/*
+BEGIN-OUTPUT
+qwe
+$("qwe")
+qwe
+qwe
+>>>>>>>>>>>>>>>>>
+        line 1 of multiline string
+        line 2 <# nested string <# very nested string :) #> #>
+        line 3 @" - this no monkey string!
+        line 4 " " " we can use "-charasters witout any problem!
+>>>>>>>>>>>>>>>>>
+        line 1 of multiline string
+        line 2 <# nested string <# very nested string :) #> #>
+        line 3 @" - this no monkey string!
+        line 4 " " " we can use "-charasters witout any problem!
+END-OUTPUT
+*/



More information about the svn mailing list