decorate AST with input line numbers?

32 views
Skip to first unread message

stefan

unread,
Mar 26, 2017, 10:31:15 PM3/26/17
to marpa parser
Hi, folks. 

I'm a MARPA newbie, so my apologies if I am asking a question which is too obvious.

I have a prototype parser for a DSL - my customer needs me to deliver an AST for it, where each node knows the line number (and perhaps even column number) at which that expression or construct began in the input stream.

I have pored over the copious MARPA documentation and commentary by users, but I haven't yet understood how I can do this.

I thought perhaps I could attach an event to every terminal, and have the event callback ask the parser where it is in the input stream? If so, I'm not even sure how to do that.

I would be grateful for any advice.

-stefan

 

Jeffrey Kegler

unread,
Mar 26, 2017, 10:40:30 PM3/26/17
to Marpa Parser Mailing LIst
I'm actually rusty at this, but I think the most direct way is to use the "start" and "length" item descriptors in an array descriptor to get input stream start location and length in characters: http://search.cpan.org/~jkegl/Marpa-R2/pod/Semantics.pod#Array_descriptor_actions

To convert input stream locations to line/column locations, you can use the $recce->line_column() method: http://search.cpan.org/~jkegl/Marpa-R2/pod/Scanless/R.pod#line_column()

I hope this helps! -- jeffrey

--
You received this message because you are subscribed to the Google Groups "marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email to marpa-parser+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron Savage

unread,
Mar 27, 2017, 6:29:33 PM3/27/17
to marpa parser
Reply all
Reply to author
Forward
0 new messages