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>
3 files changed
tree: 8f21fc9eff32d57b654aa08f4743f7f04d846e01
  1. .github/
  2. example/
  3. lib/
  4. test/
  5. .gitignore
  6. analysis_options.yaml
  7. CHANGELOG.md
  8. LICENSE
  9. pubspec.yaml
  10. README.md
README.md

Dart CI pub package package publisher

About this package

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 FileSpans that are able to provide more context for their error messages.