<div dir="ltr">Assuming you have a constructor Binary Op Pos Expr Expr, you can do:<div><br>Infix (Binary Multiply <$> getPosition <* reservedOp "*") AssocLeft</div><div><br></div><div>See Control.Applicative for the operators.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 18, 2016 at 4:28 PM, Olivier Duhart <span dir="ltr"><<a href="mailto:olivier.duhart@gmail.com" target="_blank">olivier.duhart@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">thanks for your answer, exactly what I was looking for. Now I have parsers like this :<div><br></div><div><div>ifStmt :: Parser Stmt</div><div>ifStmt =</div><div> do reserved "if"</div><div> <b>pos <- getPosition</b></div><div> cond <- expression</div><div> reserved "then"</div><div> stmt1 <- statement</div><div> reserved "else"</div><div> stmt2 <- statement</div><div> return $ If cond stmt1 stmt2 <b>pos</b></div><div><br></div><div>My AST is not fully "positioned" though as I don't get how to add position in expression (more precisely on operators).</div><div>I am using the buildExpressionParser to build expression parsers so I have</div><div><br></div><div><div>operators = [ [Prefix (reservedOp "-" >> return (Neg )) ]</div><div> , [Infix (reservedOp "*" >> return (Binary Multiply)) AssocLeft, .....</div></div><div><br></div><div>And I dont known how to tell parsec to add a SourcePos to my operators.</div><div><br></div><div>Any suggestion please ?</div><div><div class="h5"><div><br></div><div><br></div><div><br><br>Le dimanche 17 juillet 2016 19:09:32 UTC+2, Francesco Ariis a écrit :<blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Jul 17, 2016 at 09:50:27AM -0700, Olivier Duhart wrote:<br>> is ther a way to get the line numbers at parsers level?<p>Hi Olivier,<br> maybe you are looking for</p><p> <a href="http://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec.html#v:getPosition" rel="nofollow" target="_blank">http://hackage.haskell.org/package/parsec-3.1.11/docs/Text-Parsec.html#v:getPosition</a></p><p>(which is very simple and used mainly for error reporting) or you could<br>just keep track of `currLine` into a State of your choice (the 's' in<br>ParsecT s ...).<br>Does that help?<br>-F<br>_______________________________________________<br>Haskell-Cafe mailing list<br>To (un)subscribe, modify options or view archives go to:<br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="nofollow" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>Only members subscribed via the mailman list are allowed to post.</p><p></p><p></p></blockquote></div></div></div></div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>