retrieving line numbers after rendering?

14 views
Skip to first unread message

dtw....@gmail.com

unread,
Jun 7, 2017, 11:13:51 PM6/7/17
to stringtemplate-discussion
Hi all,

I have my doubts that there is some silver bullet way to do this using stringtemplate but I'll take a shot and ask if anyone has any suggestions regardless (I do hope this is still a valid place to ask questions on ST).

I'm writing a little translator that reads in 'lessons' (small fragments of code) in one language and outputs the same lesson in potentially many different languages (views).

The lessons in the original language include statements that essentially ask students to fill in small pieces of information when asked via with "Confirm" statements.

The confirm statements can be translated to corresponding STs in a given target language. However, for reasons of analysis and user feedback---it seems like I need to be able to map the line number of each Confirm statement in the original source, to its 'translated' counterpart in the resulting output...

Once I have a hierarchy of STs built, is there an easy way to retrieve this sort of information---short of calling render(), then manually string-hacking the resulting output? Realize that I'm generating many target languages that could potentially affect the position appearance of the translated confirm statements.

I realize the STs stored are evaluated/rendered lazily, so it seems unlikely that line number information would/could be stored somewhere statically. Is there some sort of method or technique I can use within stringtemplate to retrieve this sort of information, or would otherwise help me build this mapping?

Zenaan Harkness

unread,
Jul 2, 2017, 4:03:35 AM7/2/17
to stringtempla...@googlegroups.com
I believe you'll have to look into the ST code.

Check out the structures for template storage, then probably add some
instrumentation to store line number offsets, at a low-ish point in
the stack (e.g. at template initial read).

Once you have line counts for each template/fragment, then you might
be able to provide "line number ranges".

That could be a start at least, and from there you'd probably figure
out how to calc every line number.

Good luck,
Reply all
Reply to author
Forward
0 new messages