Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generalized versions of <code>oneOf</code>, <code>noneOf</code>, and <code>anyChar</code> can be built out of a generalized <code>satisfy</code>, easily enough:</p> <pre><code>oneOfT :: (Eq t, Show t, Stream s m t) =&gt; [t] -&gt; ParsecT s u m t oneOfT ts = satisfyT (`elem` ts) noneOfT :: (Eq t, Show t, Stream s m t) =&gt; [t] -&gt; ParsecT s u m t noneOfT ts = satisfyT (not . (`elem` ts)) anyT :: (Show t, Stream s m t) =&gt; ParsecT s u m t anyT = satisfyT (const True) satisfyT :: (Show t, Stream s m t) =&gt; (t -&gt; Bool) -&gt; ParsecT s u m t satisfyT p = tokenPrim showTok nextPos testTok where showTok t = show t testTok t = if p t then Just t else Nothing nextPos p t s = -- however you update position for your token stream </code></pre> <p>It might seem that the generalization of these seems missing, but you'll notice that these generalizations here make certain assumptions about the type <code>t</code> that may not be true for someone's token type. It is assumed to be an instance of <code>Show</code> and <code>Eq</code>, yet I can imagine token types for which they are displayed some other way than <code>show</code>, and that membership in a class of tokens might be achieved via some method other than <code>==</code> and <code>elem</code>.</p> <p>Lastly, once your token type is no longer a <code>Char</code>, how you choose to represent position, and thus updated it, is highly dependent on your representation of tokens and streams.</p> <p>Hence, I can see why a more generalized form doesn't exist.</p>
 

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