Skip to content

Commit 3815ff3

Browse files
authored
Merge pull request #1658 from dart-lang/merge-string_scanner-package
Merge `package:string_scanner`
2 parents 46cc745 + c72a0ae commit 3815ff3

25 files changed

+2871
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:string_scanner"
3+
about: "Create a bug or file a feature request against package:string_scanner."
4+
labels: "package:string_scanner"
5+
---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Set update schedule for GitHub Actions
2+
# See https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot
3+
4+
version: 2
5+
updates:
6+
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: monthly
11+
labels:
12+
- autosubmit
13+
groups:
14+
github-actions:
15+
patterns:
16+
- "*"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# A CI configuration to auto-publish pub packages.
2+
3+
name: Publish
4+
5+
on:
6+
pull_request:
7+
branches: [ master ]
8+
push:
9+
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]
10+
11+
jobs:
12+
publish:
13+
if: ${{ github.repository_owner == 'dart-lang' }}
14+
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
15+
permissions:
16+
id-token: write # Required for authentication using OIDC
17+
pull-requests: write # Required for writing the pull request note
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Dart CI
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ master ]
7+
pull_request:
8+
branches: [ master ]
9+
schedule:
10+
- cron: "0 0 * * 0"
11+
12+
env:
13+
PUB_ENVIRONMENT: bot.github
14+
15+
jobs:
16+
# Check code formatting and static analysis on a single OS (linux)
17+
# against Dart dev.
18+
analyze:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
sdk: [dev]
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
26+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
27+
with:
28+
sdk: ${{ matrix.sdk }}
29+
- id: install
30+
name: Install dependencies
31+
run: dart pub get
32+
- name: Check formatting
33+
run: dart format --output=none --set-exit-if-changed .
34+
if: always() && steps.install.outcome == 'success'
35+
- name: Analyze code
36+
run: dart analyze --fatal-infos
37+
if: always() && steps.install.outcome == 'success'
38+
39+
# Run tests on a matrix consisting of two dimensions:
40+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
41+
# 2. release channel: dev
42+
test:
43+
needs: analyze
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
# Add macos-latest and/or windows-latest if relevant for this package.
49+
os: [ubuntu-latest]
50+
sdk: [3.1, dev]
51+
steps:
52+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
53+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
54+
with:
55+
sdk: ${{ matrix.sdk }}
56+
- id: install
57+
name: Install dependencies
58+
run: dart pub get
59+
- name: Run VM tests
60+
run: dart test --platform vm
61+
if: always() && steps.install.outcome == 'success'
62+
- name: Run Chrome tests
63+
run: dart test --platform chrome
64+
if: always() && steps.install.outcome == 'success'

pkgs/string_scanner/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Don’t commit the following directories created by pub.
2+
.dart_tool/
3+
.pub/
4+
.packages
5+
pubspec.lock

pkgs/string_scanner/CHANGELOG.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
## 1.4.1
2+
3+
* Move to `dart-lang/tools` monorepo.
4+
5+
## 1.4.0
6+
7+
* Fix `LineScanner`'s handling of `\r\n`'s to preventing errors scanning
8+
zero-length matches when between CR and LF. CR is treated as a new line only
9+
if not immediately followed by a LF.
10+
* Fix `LineScanner`'s updating of `column` when setting `position` if the
11+
current position is not `0`.
12+
13+
## 1.3.0
14+
15+
* Require Dart 3.1.0
16+
17+
* Add a `SpanScanner.spanFromPosition()` method which takes raw code units
18+
rather than `SpanScanner.spanFrom()`'s `LineScannerState`s.
19+
20+
## 1.2.0
21+
22+
* Require Dart 2.18.0
23+
24+
* Add better support for reading code points in the Unicode supplementary plane:
25+
26+
* Added `StringScanner.readCodePoint()`, which consumes an entire Unicode code
27+
point even if it's represented by two UTF-16 code units.
28+
29+
* Added `StringScanner.peekCodePoint()`, which returns an entire Unicode code
30+
point even if it's represented by two UTF-16 code units.
31+
32+
* `StringScanner.scanChar()` and `StringScanner.expectChar()` will now
33+
properly consume two UTF-16 code units if they're passed Unicode code points
34+
in the supplementary plane.
35+
36+
## 1.1.1
37+
38+
* Populate the pubspec `repository` field.
39+
* Switch to `package:lints`.
40+
* Remove a dependency on `package:charcode`.
41+
42+
## 1.1.0
43+
44+
* Stable release for null safety.
45+
46+
## 1.1.0-nullsafety.3
47+
48+
* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release
49+
guidelines.
50+
51+
## 1.1.0-nullsafety.2
52+
53+
* Allow prerelease versions of the 2.12 sdk.
54+
55+
## 1.1.0-nullsafety.1
56+
57+
- Allow 2.10 stable and 2.11.0 dev SDK versions.
58+
59+
## 1.1.0-nullsafety
60+
61+
- Migrate to null safety.
62+
63+
## 1.0.5
64+
65+
- Added an example.
66+
67+
- Update Dart SDK constraint to `>=2.0.0 <3.0.0`.
68+
69+
## 1.0.4
70+
71+
* Add @alwaysThrows annotation to error method.
72+
73+
## 1.0.3
74+
75+
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
76+
77+
## 1.0.2
78+
79+
* `SpanScanner` no longer crashes when creating a span that contains a UTF-16
80+
surrogate pair.
81+
82+
## 1.0.1
83+
84+
* Fix the error text emitted by `StringScanner.expectChar()`.
85+
86+
## 1.0.0
87+
88+
* **Breaking change**: `StringScanner.error()`'s `length` argument now defaults
89+
to `0` rather than `1` when no match data is available.
90+
91+
* **Breaking change**: `StringScanner.lastMatch` and related methods are now
92+
reset when the scanner's position changes without producing a new match.
93+
94+
**Note**: While the changes in `1.0.0` are user-visible, they're unlikely to
95+
actually break any code in practice. Unless you know that your package is
96+
incompatible with 0.1.x, consider using 0.1.5 as your lower bound rather
97+
than 1.0.0. For example, `string_scanner: ">=0.1.5 <2.0.0"`.
98+
99+
## 0.1.5
100+
101+
* Add `new SpanScanner.within()`, which scans within a existing `FileSpan`.
102+
103+
* Add `StringScanner.scanChar()` and `StringScanner.expectChar()`.
104+
105+
## 0.1.4+1
106+
107+
* Remove the dependency on `path`, since we don't actually import it.
108+
109+
## 0.1.4
110+
111+
* Add `new SpanScanner.eager()` for creating a `SpanScanner` that eagerly
112+
computes its current line and column numbers.
113+
114+
## 0.1.3+2
115+
116+
* Fix `LineScanner`'s handling of carriage returns to match that of
117+
`SpanScanner`.
118+
119+
## 0.1.3+1
120+
121+
* Fixed the homepage URL.
122+
123+
## 0.1.3
124+
125+
* Add an optional `endState` argument to `SpanScanner.spanFrom`.
126+
127+
## 0.1.2
128+
129+
* Add `StringScanner.substring`, which returns a substring of the source string.
130+
131+
## 0.1.1
132+
133+
* Declare `SpanScanner`'s exposed `SourceSpan`s and `SourceLocation`s to be
134+
`FileSpan`s and `FileLocation`s. They always were underneath, but callers may
135+
now rely on it.
136+
137+
* Add `SpanScanner.location`, which returns the scanner's current
138+
`SourceLocation`.
139+
140+
## 0.1.0
141+
142+
* Switch from `source_maps`' `Span` class to `source_span`'s `SourceSpan` class.
143+
144+
* `new StringScanner()`'s `sourceUrl` parameter is now named to make it clear
145+
that it can be safely `null`.
146+
147+
* `new StringScannerException()` takes different arguments in a different order
148+
to match `SpanFormatException`.
149+
150+
* `StringScannerException.string` has been renamed to
151+
`StringScannerException.source` to match the `FormatException` interface.
152+
153+
## 0.0.3
154+
155+
* Make `StringScannerException` inherit from source_map's `SpanFormatException`.
156+
157+
## 0.0.2
158+
159+
* `new StringScanner()` now takes an optional `sourceUrl` argument that provides
160+
the URL of the source file. This is used for error reporting.
161+
162+
* Add `StringScanner.readChar()` and `StringScanner.peekChar()` methods for
163+
doing character-by-character scanning.
164+
165+
* Scanners now throw `StringScannerException`s which provide more detailed
166+
access to information about the errors that were thrown and can provide
167+
terminal-colored messages.
168+
169+
* Add a `LineScanner` subclass of `StringScanner` that automatically tracks line
170+
and column information of the text being scanned.
171+
172+
* Add a `SpanScanner` subclass of `LineScanner` that exposes matched ranges as
173+
[source map][] `Span` objects.
174+
175+
[source_map]: https://pub.dev/packages/source_maps

pkgs/string_scanner/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/string_scanner/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[![Dart CI](https://github.com/dart-lang/string_scanner/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/string_scanner/actions/workflows/test-package.yml)
2+
[![pub package](https://img.shields.io/pub/v/string_scanner.svg)](https://pub.dev/packages/string_scanner)
3+
[![package publisher](https://img.shields.io/pub/publisher/string_scanner.svg)](https://pub.dev/packages/string_scanner/publisher)
4+
5+
This package exposes a `StringScanner` type that makes it easy to parse a string
6+
using a series of `Pattern`s. For example:
7+
8+
```dart
9+
import 'dart:math' as math;
10+
11+
import 'package:string_scanner/string_scanner.dart';
12+
13+
num parseNumber(String source) {
14+
// Scan a number ("1", "1.5", "-3").
15+
final scanner = StringScanner(source);
16+
17+
// [Scanner.scan] tries to consume a [Pattern] and returns whether or not it
18+
// succeeded. It will move the scan pointer past the end of the pattern.
19+
final negative = scanner.scan('-');
20+
21+
// [Scanner.expect] consumes a [Pattern] and throws a [FormatError] if it
22+
// fails. Like [Scanner.scan], it will move the scan pointer forward.
23+
scanner.expect(RegExp(r'\d+'));
24+
25+
// [Scanner.lastMatch] holds the [MatchData] for the most recent call to
26+
// [Scanner.scan], [Scanner.expect], or [Scanner.matches].
27+
var number = num.parse(scanner.lastMatch![0]!);
28+
29+
if (scanner.scan('.')) {
30+
scanner.expect(RegExp(r'\d+'));
31+
final decimal = scanner.lastMatch![0]!;
32+
number += int.parse(decimal) / math.pow(10, decimal.length);
33+
}
34+
35+
// [Scanner.expectDone] will throw a [FormatError] if there's any input that
36+
// hasn't yet been consumed.
37+
scanner.expectDone();
38+
39+
return (negative ? -1 : 1) * number;
40+
}
41+
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://dart.dev/guides/language/analysis-options
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
strict-inference: true
8+
strict-raw-types: true
9+
10+
linter:
11+
rules:
12+
- avoid_bool_literals_in_conditional_expressions
13+
- avoid_classes_with_only_static_members
14+
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
16+
- avoid_returning_this
17+
- avoid_unused_constructor_parameters
18+
- avoid_void_async
19+
- cancel_subscriptions
20+
- join_return_with_assignment
21+
- literal_only_boolean_expressions
22+
- missing_whitespace_between_adjacent_strings
23+
- no_adjacent_strings_in_list
24+
- no_runtimeType_toString
25+
- prefer_const_declarations
26+
- prefer_expression_function_bodies
27+
- prefer_final_locals
28+
- unnecessary_await_in_return
29+
- unnecessary_raw_strings
30+
- use_if_null_to_convert_nulls_to_bools
31+
- use_raw_strings
32+
- use_string_buffers

0 commit comments

Comments
 (0)