Hello Shane, Another way to preserve line information in preprocessing or multiple-stage parsing is to insert the equivalent of `#line` entries at the output of intermediate phases. The next space would use those to alter the "original position" when producing the AST.
Regards, On Fri, Apr 26, 2019 at 12:59 AM Shane Ryoo <shane.r...@gmail.com> wrote: > Hello, > > I've inherited some code that does source-to-source translation, with > five different passes (each with a different .peg) that take a single > long string as input and emits a string as output. I've been > requested to add source line information to the results, some way or > another. Currently the code strips out all comments from the source > and never adds/handles any. > > My question: what would be best practice here for retaining source > line information? I've thrown around some ideas like supporting > comments throughout the grammars, breaking up the single string format > and adding line data per string, unifying the grammars so it's a > single pass, but nothing proposed has been entirely satisfactory. My > previous experience is entirely flex-bison with a single grammar going > to an IR. > > Thanks in advance. > > _______________________________________________ > PEG mailing list > PEG@lists.csail.mit.edu > https://lists.csail.mit.edu/mailman/listinfo/peg > -- Juancarlo *Añez*
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg