Le 2015-04-22 08:44, manuel.serr...@inria.fr a écrit :

Well, I wrote a little grammar (see attachment), but I don't see any way to pass the pattern as an argument to the grammar, is it possible?

You cannot as REGULAR-GRAMMARs are compiled. If you need to compute new grammars at runtime, you will have to use eval :-(. For instance, you can use something such as:

  (define (mk-regular-grammar pattern)
     (eval `(regular-grammar () (,pattern "blabla"))))

Although not recommended in general, this solution will deliver decent performance in your case.

As the system we try to emulate is a Python library, the performance should be comparable.

The other solution would be to use pregexp (your first intuition) but as pregexp requires a string, you will have to read the whole file in memory first, which means that this solution will only work for toy examples.

As a side note, if your pattern is basic regular expression only made of sequences of characters, then you might prefer using KPM and mmap.

KMP, I suppose? We need Regexps more complex than just strings. But I am curious about the way Perl manages multi-lines queries, we would do the same.

Cheers.

--
Laurent Bloch - http://www.laurentbloch.org/ - l...@laurentbloch.org

Reply via email to