> 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.

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.

Cheers,

-- 
Manuel

Reply via email to