notation3 parser error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

notation3 parser error

rzeno-2
hi,

n3 parser fail when a literal delimited with """ ends in " or "" as in
this cases:

:a :b """ some text "quoted text here"""" .

or

:a :b """ some text """"" .

I solved the problem changing the notation3.py. The patch is for the
current notation3.py from CVS and cwm 1.197 from cwm-1.2.1:

--- notation3.py.orig 2010-10-18 17:40:04.000000000 +0300
+++ notation3.py 2010-10-18 18:00:23.000000000 +0300
@@ -1048,14 +1048,28 @@
         ustr = u""   # Empty unicode string
         startline = self.lines # Remember where for error messages
         while j<len(str):
-            i = j + len(delim)
-            if str[j:i] == delim: # done.
-                return i, ustr
-
-            if str[j] == '"':
-                ustr = ustr + '"'
-                j = j + 1
-                continue
+                if delim == '"': # done when delim is "
+                    i = j + 1
+                    return i, ustr
+                if delim == '"""': # done when delim is """ and ...
+                    if str[j:j+5] == '"""""': # ... we have "" before
+                        i = j + 5
+                        ustr = ustr + '""'
+                        return i, ustr
+                    if str[j:j+4] == '""""': # ... we have " before
+                        i = j + 4
+                        ustr = ustr + '"'
+                        return i, ustr
+                    if str[j:j+3] == '"""': # ... current " is part of delim
+                        i = j + 3
+                        ustr = ustr + '"'
+                        return i, ustr
+
+                    # we are inside of the string and current char is "
+                    j = j + 1
+                    ustr = ustr + '"'
+                    continue
+                    
             m = interesting.search(str, j)  # was str[j:].
             # Note for pos param to work, MUST be compiled  ... re bug?
             assert m , "Quote expected in string at ^ in %s^%s" %(




Reply | Threaded
Open this post in threaded view
|

Re: notation3 parser error

rzeno-2
On Mon, Oct 18, 2010 at 06:06:53PM +0300, rzeno wrote:

> hi,
>
> n3 parser fail when a literal delimited with """ ends in " or "" as in
> this cases:
>
> :a :b """ some text "quoted text here"""" .
>
> or
>
> :a :b """ some text """"" .
>
> I solved the problem changing the notation3.py. The patch is for the
> current notation3.py from CVS and cwm 1.197 from cwm-1.2.1:
>
> --- notation3.py.orig 2010-10-18 17:40:04.000000000 +0300
> +++ notation3.py 2010-10-18 18:00:23.000000000 +0300
> @@ -1048,14 +1048,28 @@
>          ustr = u""   # Empty unicode string
>          startline = self.lines # Remember where for error messages
>          while j<len(str):
> -            i = j + len(delim)
> -            if str[j:i] == delim: # done.
> -                return i, ustr
> -
> -            if str[j] == '"':
> -                ustr = ustr + '"'
> -                j = j + 1
> -                continue
> +                if delim == '"': # done when delim is "
> +                    i = j + 1
> +                    return i, ustr
> +                if delim == '"""': # done when delim is """ and ...
> +                    if str[j:j+5] == '"""""': # ... we have "" before
> +                        i = j + 5
> +                        ustr = ustr + '""'
> +                        return i, ustr
> +                    if str[j:j+4] == '""""': # ... we have " before
> +                        i = j + 4
> +                        ustr = ustr + '"'
> +                        return i, ustr
> +                    if str[j:j+3] == '"""': # ... current " is part of delim
> +                        i = j + 3
> +                        ustr = ustr + '"'
> +                        return i, ustr
> +
> +                    # we are inside of the string and current char is "
> +                    j = j + 1
> +                    ustr = ustr + '"'
> +                    continue
> +                    
>              m = interesting.search(str, j)  # was str[j:].
>              # Note for pos param to work, MUST be compiled  ... re bug?
>              assert m , "Quote expected in string at ^ in %s^%s" %(
>
i apologise, this was a old patch with a error, my mistake.

The correct patch for notation3.py 1.200, tested with cwm 1.197 ( from
cwm-1.2.1) is:

--- notation3.py.orig 2010-10-18 03:48:29.000000000 +0300
+++ notation3.py 2010-10-18 18:59:45.000000000 +0300
@@ -1048,14 +1048,27 @@
         ustr = u""   # Empty unicode string
         startline = self.lines # Remember where for error messages
         while j<len(str):
-            i = j + len(delim)
-            if str[j:i] == delim: # done.
-                return i, ustr
-
-            if str[j] == '"':
-                ustr = ustr + '"'
-                j = j + 1
-                continue
+                if delim == '"': # done when delim is "
+                    i = j + 1
+                    return i, ustr
+                if delim == '"""': # done when delim is """ and ...
+                    if str[j:j+5] == '"""""': # ... we have "" before
+                        i = j + 5
+                        ustr = ustr + '""'
+                        return i, ustr
+                    if str[j:j+4] == '""""': # ... we have " before
+                        i = j + 4
+                        ustr = ustr + '"'
+                        return i, ustr
+                    if str[j:j+3] == '"""': # ... current " is part of delim
+                        i = j + 3
+                        return i, ustr
+
+                    # we are inside of the string and current char is "
+                    j = j + 1
+                    ustr = ustr + '"'
+                    continue
+                    
             m = interesting.search(str, j)  # was str[j:].
             # Note for pos param to work, MUST be compiled  ... re bug?
             assert m , "Quote expected in string at ^ in %s^%s" %(


notation3.py.patch (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: notation3 parser error

rzeno-2
hi,

some times is better to sleep, :)

i apologise for first two wrong patches, i have a bad day.

diff -u notation3.py.orig notation3.py

inside cwm-1.2.1/swap/,  where notation3.py.orig is the original notation3.py, ver 1.200,
give this patch( also as attachement):

--- notation3.py.orig 2010-10-18 03:48:29.000000000 +0300
+++ notation3.py 2010-10-18 19:33:05.000000000 +0300
@@ -1048,14 +1048,28 @@
         ustr = u""   # Empty unicode string
         startline = self.lines # Remember where for error messages
         while j<len(str):
-            i = j + len(delim)
-            if str[j:i] == delim: # done.
-                return i, ustr
-
             if str[j] == '"':
-                ustr = ustr + '"'
-                j = j + 1
-                continue
+                if delim == '"': # done when delim is "
+                    i = j + 1
+                    return i, ustr
+                if delim == '"""': # done when delim is """ and ...
+                    if str[j:j+5] == '"""""': # ... we have "" before
+                        i = j + 5
+                        ustr = ustr + '""'
+                        return i, ustr
+                    if str[j:j+4] == '""""': # ... we have " before
+                        i = j + 4
+                        ustr = ustr + '"'
+                        return i, ustr
+                    if str[j:j+3] == '"""': # ... current " is part of delim
+                        i = j + 3
+                        return i, ustr
+                
+                    # we are inside of the string and current char is "
+                    j = j + 1
+                    ustr = ustr + '"'
+                    continue
+            
             m = interesting.search(str, j)  # was str[j:].
             # Note for pos param to work, MUST be compiled  ... re bug?
             assert m , "Quote expected in string at ^ in %s^%s" %(

sorry again and best regards


notation3.py.patch (1K) Download Attachment