commit | 905a167351abd9f1b5e1b26b046df05c35c9b6a6 | [log] [tgz] |
---|---|---|
author | Natalie Weizenbaum <nweiz@google.com> | Wed Apr 05 16:52:39 2023 -0700 |
committer | GitHub <noreply@github.com> | Wed Apr 05 16:52:39 2023 -0700 |
tree | 8f21fc9eff32d57b654aa08f4743f7f04d846e01 | |
parent | 1806578a3868bb955ae86b79f85407827b6e834e [diff] |
Add public access to a SourceFile's code units (#93) * Add public access to a SourceFile's code units This makes it possible to efficiently reparse information from around a `FileSpan`, such as to expand it through surrounding whitespace characters. Otherwise, a caller would have to call `getText()` which can be very expensive in a tight loop. * Fix lints * Update CHANGELOG.md Co-authored-by: Devon Carew <devoncarew@google.com> --------- Co-authored-by: Devon Carew <devoncarew@google.com>
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.