File tree Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1
1
# 1.9.2-dev
2
2
3
3
* Require Dart 2.18
4
+ * Add an API usage example in ` example/ ` .
4
5
5
6
# 1.9.1
6
7
201
202
# 1.0.0
202
203
203
204
This package was extracted from the
204
- [ ` source_maps ` ] ( http ://pub.dartlang.org /packages/source_maps) package, but the
205
+ [ ` source_maps ` ] ( https ://pub.dev /packages/source_maps) package, but the
205
206
API has many differences. Among them:
206
207
207
208
* ` Span ` has been renamed to ` SourceSpan ` and ` Location ` has been renamed to
Original file line number Diff line number Diff line change 2
2
[ ![ pub package] ( https://img.shields.io/pub/v/source_span.svg )] ( https://pub.dev/packages/source_span )
3
3
[ ![ package publisher] ( https://img.shields.io/pub/publisher/source_span.svg )] ( https://pub.dev/packages/source_span/publisher )
4
4
5
+ ## About this package
6
+
5
7
` source_span ` is a library for tracking locations in source code. It's designed
6
8
to provide a standard representation for source code locations and spans so that
7
9
disparate packages can easily pass them among one another, and to make it easy
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2
+ // for details. All rights reserved. Use of this source code is governed by a
3
+ // BSD-style license that can be found in the LICENSE file.
4
+
5
+ import 'dart:io' ;
6
+
7
+ import 'package:source_span/source_span.dart' ;
8
+
9
+ void main (List <String > args) {
10
+ final file = File ('README.md' );
11
+ final contents = file.readAsStringSync ();
12
+
13
+ final sourceFile = SourceFile .fromString (contents, url: file.uri);
14
+ final spans = _parseFile (contents, sourceFile);
15
+
16
+ for (var span in spans.take (30 )) {
17
+ print ('[${span .start .line + 1 }:${span .start .column + 1 }] ${span .text }' );
18
+ }
19
+ }
20
+
21
+ Iterable <SourceSpan > _parseFile (String contents, SourceFile sourceFile) sync * {
22
+ var wordStart = 0 ;
23
+ var inWhiteSpace = true ;
24
+
25
+ for (var i = 0 ; i < contents.length; i++ ) {
26
+ final codeUnit = contents.codeUnitAt (i);
27
+
28
+ if (codeUnit == _eol || codeUnit == _space) {
29
+ if (! inWhiteSpace) {
30
+ inWhiteSpace = true ;
31
+
32
+ // emit a word
33
+ yield sourceFile.span (wordStart, i);
34
+ }
35
+ } else {
36
+ if (inWhiteSpace) {
37
+ inWhiteSpace = false ;
38
+
39
+ wordStart = i;
40
+ }
41
+ }
42
+ }
43
+
44
+ if (! inWhiteSpace) {
45
+ // emit a word
46
+ yield sourceFile.span (wordStart, contents.length);
47
+ }
48
+ }
49
+
50
+ const int _eol = 10 ;
51
+ const int _space = 32 ;
Original file line number Diff line number Diff line change 1
1
name : source_span
2
2
version : 1.9.2-dev
3
- description : A library for identifying source spans and locations.
3
+ description : >-
4
+ Provides a standard representation for source code locations and spans.
4
5
repository : https://github.com/dart-lang/source_span
5
6
6
7
environment :
You can’t perform that action at this time.
0 commit comments