Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution to this question asks for too much code for it to be practical to answer here, but the outline goes as follows.</p> <p>First, you want to parse your regular expression--you can look into parser combinators for this, for example. You'll then have an evaluation tree that looks like, for example,</p> <pre><code>List( Constant("abc"), ZeroOrOne(Constant("d")), Constant("efg"), OneOf(Constant("h"),List(Constant("ij"),ZeroOrOne(Constant("klmnop")))), Constant("qrs"), AnyChar() ) </code></pre> <p>Rather than running this expression tree as a <em>matcher</em>, you can run it as a <em>generator</em> by defining a generate method on each term. For some terms, (e.g. <code>ZeroOrOne(Constant("d"))</code>), there will be multiple options, so you can define an iterator. One way to do this is to store internal state in each term and pass in either an "advance" flag or a "reset" flag. On "reset", the generator returns the first possible match (e.g. <code>""</code>); on advance, it goes to the next one and returns that (e.g. <code>"d"</code>) while consuming the advance flag (leaving the rest to evaluate with no flags). If there are no more items, it produces a reset instead for everything inside itself and leaves the advance flag intact for the next item. You start by running with a reset; on each iteration, you put an advance in, and stop when you get it out again.</p> <p>Of course, some regex constructs like <code>"d+"</code> can produce infinitely many values, so you'll probably want to limit them in some way (or at some point return e.g. <code>d...d</code> meaning "lots"); and others have very many possible values (e.g. <code>.</code> matches any char, but do you really want all 64k chars, or howevermany unicode code points there are?), and you may wish to restrict those also.</p> <p>Anyway, this, though time-consuming, will result in a working generator. And, as an aside, you'll also have a working regex matcher, if you write a match routine for each piece of the parsed tree.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload