Support external implementations of FileSpan.
Support external implementations of FileSpan.

Previously, several FileSpan methods assumed that all FileSpans were
implementations of this package's FileSpan class. However, this may not
always be true. It can be useful to create FileSpans without first
creating a SourceFile when efficient representations of line/column
information are already available, and the user doesn't want to eagerly
do the parsing necessary to create a full SourceFile.

This also fixes an inconsistency between FileSpan.== and
FileSpan.hashCode.

R=sigmund@google.com

Review URL: https://codereview.chromium.org//1298093002 .
3 files changed
tree: fd5f091f70003663f4e29fae88dbb3fcf2baccf4
  1. .gitignore
  2. .test_config
  3. CHANGELOG.md
  4. LICENSE
  5. README.md
  6. codereview.settings
  7. lib/
  8. pubspec.yaml
  9. test/
README.md

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.