commit | 99c896531be515cee7ce504661987d8d896c6ae6 | [log] [tgz] |
---|---|---|
author | Natalie Weizenbaum <nweiz@google.com> | Fri Jan 11 17:07:30 2019 -0800 |
committer | Natalie Weizenbaum <nweiz@google.com> | Fri Jan 11 17:07:30 2019 -0800 |
tree | 7c4701f3e69586ff6ece7b1b4a60f22913dfca3b | |
parent | bfe039a234dd984346322be2d0dfd7208f46231c [diff] |
Improve FileSpan.context Previously, if FileSpan.end was directly after a newline, FileSpan.context would include the entire next line in the span. Then when this span was highlighted, the end would point confusingly to the beginning of that next line.
source_span
is a library for tracking locations in source code. It's designed to provide a standard representation for source code locations and spans so that disparate packages can easily pass them among one another, and to make it easy to generate human-friendly messages associated with a given piece of code.
The most commonly-used class is the package's namesake, SourceSpan
. It represents a span of characters in some source file, and is often attached to an object that has been parsed to indicate where it was parsed from. It provides access to the text of the span via SourceSpan.text
and can be used to produce human-friendly messages using SourceSpan.message()
.
When parsing code from a file, SourceFile
is useful. Not only does it provide an efficient means of computing line and column numbers, SourceFile.span()
returns special FileSpan
s that are able to provide more context for their error messages.