error when using split-regex

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

error when using split-regex

Damien Mattei
Hi,

i have got an error in code when using regex-split,
here is the code tested here at REPL in kawa 2.1:

(require 'regex)

(define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
(define wds-data-str &<{&[wds-url]})  ;; could take a few seconds to GET file
(define wds-data-str-split (regex-split wds-data-str (string #\return)))

result in this error at some point of splitting:

                  ^
        at java.util.regex.Pattern.error(Pattern.java:1955)
        at java.util.regex.Pattern.sequence(Pattern.java:2123)
        at java.util.regex.Pattern.expr(Pattern.java:1996)
        at java.util.regex.Pattern.group0(Pattern.java:2905)
        at java.util.regex.Pattern.sequence(Pattern.java:2051)
        at java.util.regex.Pattern.expr(Pattern.java:1996)
        at java.util.regex.Pattern.compile(Pattern.java:1696)
        at java.util.regex.Pattern.<init>(Pattern.java:1351)
        at java.util.regex.Pattern.compile(Pattern.java:1028)
        at kawa.lib.kawa.regex.regexSplit(regex.scm:51)
        at atInteractiveLevel-6.run(stdin:6)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:293)
        at gnu.expr.ModuleExp.evalModule(ModuleExp.java:212)
        at kawa.Shell.run(Shell.java:291)
        at kawa.Shell.run(Shell.java:203)
        at kawa.Shell.run(Shell.java:184)
        at kawa.repl.processArgs(repl.java:687)
        at kawa.repl.main(repl.java:793)

also tested it with #\linefeed and same error, also tested with " " and "A" : error

i did not look in the contain of the file and i will do it,but anyway the result should not be an error?
does the newest version of kawa give a different result?

Regards,
Damien
--
[hidden email], [hidden email], UNS / OCA / CNRS
Reply | Threaded
Open this post in threaded view
|

Re: error when using split-regex

Per Bothner
On 03/09/2017 02:31 AM, Damien MATTEI wrote:
> Hi,
>
> i have got an error in code when using regex-split,
> here is the code tested here at REPL in kawa 2.1:
>
> (require 'regex)
>
> (define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")

That web-site is currently not available.

> (define wds-data-str &<{&[wds-url]})  ;; could take a few seconds to GET file
> (define wds-data-str-split (regex-split wds-data-str (string #\return)))
>
> result in this error at some point of splitting:
>
>                   ^
>         at java.util.regex.Pattern.error(Pattern.java:1955)

What is the exception thrown?

--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: error when using split-regex

Per Bothner
In reply to this post by Damien Mattei
On 03/09/2017 02:31 AM, Damien MATTEI wrote:

> Hi,
>
> i have got an error in code when using regex-split,
> here is the code tested here at REPL in kawa 2.1:
>
> (require 'regex)
>
> (define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
> (define wds-data-str &<{&[wds-url]})  ;; could take a few seconds to GET file
> (define wds-data-str-split (regex-split wds-data-str (string #\return)))

Try switching the order of the arguments to regex-split.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: error when using split-regex

Per Bothner
On 03/09/2017 11:42 AM, Per Bothner wrote:

> On 03/09/2017 02:31 AM, Damien MATTEI wrote:
>> Hi,
>>
>> i have got an error in code when using regex-split,
>> here is the code tested here at REPL in kawa 2.1:
>>
>> (require 'regex)
>>
>> (define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
>> (define wds-data-str &<{&[wds-url]})  ;; could take a few seconds to GET file
>> (define wds-data-str-split (regex-split wds-data-str (string #\return)))
>
> Try switching the order of the arguments to regex-split.

What I did is I saved the file, and then trimmed it down until the output
would fit in the scroll-back buffer. Then I saw:

java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 4730

That was the clue that the arguments were switched.  Confirmed by checking the manual.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: error when using split-regex

Damien Mattei
Le Thursday 09 March 2017 20:46:11 Per Bothner, vous avez écrit :

> On 03/09/2017 11:42 AM, Per Bothner wrote:
> > On 03/09/2017 02:31 AM, Damien MATTEI wrote:
> >> Hi,
> >>
> >> i have got an error in code when using regex-split,
> >> here is the code tested here at REPL in kawa 2.1:
> >>
> >> (require 'regex)
> >>
> >> (define wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
> >> (define wds-data-str &<{&[wds-url]})  ;; could take a few seconds to GET file
> >> (define wds-data-str-split (regex-split wds-data-str (string #\return)))
> >
> > Try switching the order of the arguments to regex-split.
>
> What I did is I saved the file, and then trimmed it down until the output
> would fit in the scroll-back buffer. Then I saw:
>
> java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 4730
>
> That was the clue that the arguments were switched.  Confirmed by checking the manual.

thank you Per ,
 it works now, i had swapped the args and  the line separator was LF and not CR:

 (let* ((marequete "SELECT * FROM Obs ORDER BY Auteur")
         
          (rs ::java.sql.ResultSet #!null)
          (total '())
          (result '())
          (wds-url "http://ad.usno.navy.mil/wds/Webtextfiles/wdsnewref.txt")
          (wds-data-str &<{&[wds-url]})
          (str1 (substring wds-data-str 0 30))
          (len-wds-data-str (string-length wds-data-str))
          ;;(wds-data-str-split (regex-split (string #\return) wds-data-str))
          (wds-data-str-split (regex-split (string #\linefeed) wds-data-str))
          )
     
     (display-msg-var-nl  "DBtoWebObserversKawa : work : str1 = " str1)
     (display-msg-var-nl  "DBtoWebObserversKawa : work : length wds-data-str = " len-wds-data-str)
     (display-msg-var-nl  "DBtoWebObserversKawa : work : (car wds-data-str-split) = " (car wds-data-str-split))

output in Tomcat log:

Aujourd'hui 10:37:21
   
DBtoWebObserversKawa : work : str1 = WDS Astrometry, Interferometri
DBtoWebObserversKawa : work : length wds-data-str = 2723073
DBtoWebObserversKawa : work : (car wds-data-str-split) = WDS Astrometry, Interferometric, Linear, Orbit, and DM Catalogs: References

Regards,
Damien

--
[hidden email], [hidden email], UNS / OCA / CNRS