Hi,<br><br>TokenParser supports two kinds of comments, the multi-line comments (ie. {- -}) and the single line comments (ie. -- \n).<br><br>The language I am trying to parse, however, has comments which are neither.&nbsp; The -- acts like a single line comment which extends to the end of the line usually, but can also be truncated to before the end of the line by another --.&nbsp; For example:<br>
<br>&nbsp; noncomment -- comment comment<br>&nbsp; noncomment -- comment comment -- noncomment noncomment -- comment -- noncomment<br>&nbsp; noncomment<br><br>I haven&#39;t been able to get the TokenParser to work with this style of comment.&nbsp; The best I could do was copy the whole Token module and modify the code:<br>
<br>data LanguageDef st&nbsp; <br>&nbsp;&nbsp;&nbsp; = LanguageDef <br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br>&nbsp;&nbsp;&nbsp; <b>, commentLine&nbsp;&nbsp;&nbsp; :: String</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br>&nbsp;&nbsp;&nbsp; } <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br><br>makeTokenParser languageDef<br>&nbsp;&nbsp;&nbsp; = TokenParser{&nbsp;&nbsp; {- snip -}&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; whiteSpace <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | noLine &amp;&amp; noMulti&nbsp; = skipMany (simpleSpace <b>&lt;|&gt; customComment</b> &lt;?&gt; &quot;&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | noLine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = skipMany (simpleSpace <b>&lt;|&gt; customComment</b> &lt;|&gt; multiLineComment &lt;?&gt; &quot;&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | noMulti&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = skipMany (simpleSpace <b>&lt;|&gt; customComment</b> &lt;|&gt; oneLineComment &lt;?&gt; &quot;&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = skipMany (simpleSpace <b>&lt;|&gt; customComment</b> &lt;|&gt; oneLineComment &lt;|&gt; multiLineComment &lt;?&gt; &quot;&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; noLine&nbsp; = null (commentLine languageDef)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; noMulti = null (commentStart languageDef) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>customComment =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do{commentCustom languageDef<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;return()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b><br>
<br>Then I put my specialised comment parser in the customComment field:<br><br>languageDef = TOKEN.LanguageDef<br>&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br>&nbsp;&nbsp; , TOKEN.commentCustom = customComment<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {- snip -}<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; where<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; customComment = do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string &quot;--&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; untilLineCommentEnd<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; untilLineCommentEnd = do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c &lt;- manyTill anyChar (string &quot;\n&quot; &lt;|&gt; try (string &quot;--&quot;))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ()<br><br>Anyone know of a way I could reuse the TokenParser code rather than copy and tweaking it?<br><br>Thanks<br><br>-John<br><br>