Closed alandonovan closed 3 years ago
Another approach would be to support #line filename:line:column comments in the scanner. That would be more general, but more complicated of course.
That's a good point, though my experience of line directives in several languages is that they create a great deal of complexity: some clients want the raw line numbers, others want the cooked. They also break the invariant that all the statements within a given file have the same filename, but I suppose that's fixable by making them line-and-column directives instead of file-and-line directives.
The new FilePortion type, which may be provided to the scanner, parser, or ExecFile functions, combines a piece of text with its start line/column numbers, for applications that extract a Starlark expression from the middle of a larger file.
Fixes https://github.com/google/starlark-go/issues/346