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,
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
When parsing code from a file,
SourceFile is useful. Not only does it provide
an efficient means of computing line and column numbers,
FileSpans that are able to provide more context for their
SourceSpan.highlight(), which returns just the highlighted text that would be included in
SourceSpanWithContext.contextto be overridden in strong mode.
FileSpan.end. In 1.2.0 these were mistakenly changed from
SourceLocation directly is deprecated. Instead,
extend the new
SourceLocationBase class or mix in the new
Dramatically improve the performance of
SourceFilewhen repeatedly called.
FileSpan.unioncould throw an exception for external implementations of
==, but not
no longer throw exceptions for external implementations of
FileSpan.hashCode now fully agrees with
SourceSpanWithContextto allow multiple occurrences of
FileSpan's context to include the full span text, not just the first line of it.
SourceSpanWithContext: a span that also includes the full line of text that contains the span.
Avoid unintentionally allocating extra objects for internal
SourceSpan.operator== works on arbitrary
This package was extracted from the
source_maps package, but the
API has many differences. Among them:
Span has been renamed to
Location has been renamed to
SourceLocation to clarify their purpose and maintain consistency with the
package name. Likewise,
SpanException is now
SpanFormatException is not
FixedLocation have been rolled into the
Location classes, respectively.
SourceFile is more aggressive about validating its arguments. Out-of-bounds
lines, columns, and offsets will now throw errors rather than be silently
Uri objects rather than
Strings. The constructors allow either
SourceFile.getLocationMessage are now
SourceFile.message, respectively. Rather than
taking both a
useColor and a
color parameter, they now take a single
color parameter that controls both whether and which color is used.
Span.isIdentifier has been removed. This property doesn't make sense outside
of a source map context.
SourceFileSegment has been removed. This class wasn't widely used and was
inconsistent in its choice of which parameters were considered relative and
Add this to your package's pubspec.yaml file:
dependencies: source_span: ^1.3.1
You can install packages from the command line:
$ pub get
Alternatively, your editor might support
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|1.5.5||Feb 28, 2019|
|1.5.4||Jan 29, 2019|
|1.5.3||Jan 24, 2019|
|1.5.2||Jan 17, 2019|
|1.5.1||Jan 14, 2019|
|1.5.0||Jan 10, 2019|
|1.4.1||Jul 18, 2018|
|1.4.0||May 17, 2017|
|1.3.1||Jan 7, 2017|
|1.3.0||Nov 8, 2016|