Skip to content

Commit

Permalink
Merge pull request #1658 from dart-lang/merge-string_scanner-package
Browse files Browse the repository at this point in the history
Merge `package:string_scanner`
  • Loading branch information
mosuem authored Dec 17, 2024
2 parents 46cc745 + c72a0ae commit 3815ff3
Show file tree
Hide file tree
Showing 25 changed files with 2,871 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/string_scanner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:string_scanner"
about: "Create a bug or file a feature request against package:string_scanner."
labels: "package:string_scanner"
---
16 changes: 16 additions & 0 deletions pkgs/string_scanner/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Set update schedule for GitHub Actions
# See https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot

version: 2
updates:

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
labels:
- autosubmit
groups:
github-actions:
patterns:
- "*"
17 changes: 17 additions & 0 deletions pkgs/string_scanner/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# A CI configuration to auto-publish pub packages.

name: Publish

on:
pull_request:
branches: [ master ]
push:
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]

jobs:
publish:
if: ${{ github.repository_owner == 'dart-lang' }}
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
permissions:
id-token: write # Required for authentication using OIDC
pull-requests: write # Required for writing the pull request note
64 changes: 64 additions & 0 deletions pkgs/string_scanner/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Dart CI

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.1, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
5 changes: 5 additions & 0 deletions pkgs/string_scanner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Don’t commit the following directories created by pub.
.dart_tool/
.pub/
.packages
pubspec.lock
175 changes: 175 additions & 0 deletions pkgs/string_scanner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
## 1.4.1

* Move to `dart-lang/tools` monorepo.

## 1.4.0

* Fix `LineScanner`'s handling of `\r\n`'s to preventing errors scanning
zero-length matches when between CR and LF. CR is treated as a new line only
if not immediately followed by a LF.
* Fix `LineScanner`'s updating of `column` when setting `position` if the
current position is not `0`.

## 1.3.0

* Require Dart 3.1.0

* Add a `SpanScanner.spanFromPosition()` method which takes raw code units
rather than `SpanScanner.spanFrom()`'s `LineScannerState`s.

## 1.2.0

* Require Dart 2.18.0

* Add better support for reading code points in the Unicode supplementary plane:

* Added `StringScanner.readCodePoint()`, which consumes an entire Unicode code
point even if it's represented by two UTF-16 code units.

* Added `StringScanner.peekCodePoint()`, which returns an entire Unicode code
point even if it's represented by two UTF-16 code units.

* `StringScanner.scanChar()` and `StringScanner.expectChar()` will now
properly consume two UTF-16 code units if they're passed Unicode code points
in the supplementary plane.

## 1.1.1

* Populate the pubspec `repository` field.
* Switch to `package:lints`.
* Remove a dependency on `package:charcode`.

## 1.1.0

* Stable release for null safety.

## 1.1.0-nullsafety.3

* Update SDK constraints to `>=2.12.0-0 <3.0.0` based on beta release
guidelines.

## 1.1.0-nullsafety.2

* Allow prerelease versions of the 2.12 sdk.

## 1.1.0-nullsafety.1

- Allow 2.10 stable and 2.11.0 dev SDK versions.

## 1.1.0-nullsafety

- Migrate to null safety.

## 1.0.5

- Added an example.

- Update Dart SDK constraint to `>=2.0.0 <3.0.0`.

## 1.0.4

* Add @alwaysThrows annotation to error method.

## 1.0.3

* Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 1.0.2

* `SpanScanner` no longer crashes when creating a span that contains a UTF-16
surrogate pair.

## 1.0.1

* Fix the error text emitted by `StringScanner.expectChar()`.

## 1.0.0

* **Breaking change**: `StringScanner.error()`'s `length` argument now defaults
to `0` rather than `1` when no match data is available.

* **Breaking change**: `StringScanner.lastMatch` and related methods are now
reset when the scanner's position changes without producing a new match.

**Note**: While the changes in `1.0.0` are user-visible, they're unlikely to
actually break any code in practice. Unless you know that your package is
incompatible with 0.1.x, consider using 0.1.5 as your lower bound rather
than 1.0.0. For example, `string_scanner: ">=0.1.5 <2.0.0"`.

## 0.1.5

* Add `new SpanScanner.within()`, which scans within a existing `FileSpan`.

* Add `StringScanner.scanChar()` and `StringScanner.expectChar()`.

## 0.1.4+1

* Remove the dependency on `path`, since we don't actually import it.

## 0.1.4

* Add `new SpanScanner.eager()` for creating a `SpanScanner` that eagerly
computes its current line and column numbers.

## 0.1.3+2

* Fix `LineScanner`'s handling of carriage returns to match that of
`SpanScanner`.

## 0.1.3+1

* Fixed the homepage URL.

## 0.1.3

* Add an optional `endState` argument to `SpanScanner.spanFrom`.

## 0.1.2

* Add `StringScanner.substring`, which returns a substring of the source string.

## 0.1.1

* Declare `SpanScanner`'s exposed `SourceSpan`s and `SourceLocation`s to be
`FileSpan`s and `FileLocation`s. They always were underneath, but callers may
now rely on it.

* Add `SpanScanner.location`, which returns the scanner's current
`SourceLocation`.

## 0.1.0

* Switch from `source_maps`' `Span` class to `source_span`'s `SourceSpan` class.

* `new StringScanner()`'s `sourceUrl` parameter is now named to make it clear
that it can be safely `null`.

* `new StringScannerException()` takes different arguments in a different order
to match `SpanFormatException`.

* `StringScannerException.string` has been renamed to
`StringScannerException.source` to match the `FormatException` interface.

## 0.0.3

* Make `StringScannerException` inherit from source_map's `SpanFormatException`.

## 0.0.2

* `new StringScanner()` now takes an optional `sourceUrl` argument that provides
the URL of the source file. This is used for error reporting.

* Add `StringScanner.readChar()` and `StringScanner.peekChar()` methods for
doing character-by-character scanning.

* Scanners now throw `StringScannerException`s which provide more detailed
access to information about the errors that were thrown and can provide
terminal-colored messages.

* Add a `LineScanner` subclass of `StringScanner` that automatically tracks line
and column information of the text being scanned.

* Add a `SpanScanner` subclass of `LineScanner` that exposes matched ranges as
[source map][] `Span` objects.

[source_map]: https://pub.dev/packages/source_maps
27 changes: 27 additions & 0 deletions pkgs/string_scanner/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2014, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 changes: 41 additions & 0 deletions pkgs/string_scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[![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)
[![pub package](https://img.shields.io/pub/v/string_scanner.svg)](https://pub.dev/packages/string_scanner)
[![package publisher](https://img.shields.io/pub/publisher/string_scanner.svg)](https://pub.dev/packages/string_scanner/publisher)

This package exposes a `StringScanner` type that makes it easy to parse a string
using a series of `Pattern`s. For example:

```dart
import 'dart:math' as math;
import 'package:string_scanner/string_scanner.dart';
num parseNumber(String source) {
// Scan a number ("1", "1.5", "-3").
final scanner = StringScanner(source);
// [Scanner.scan] tries to consume a [Pattern] and returns whether or not it
// succeeded. It will move the scan pointer past the end of the pattern.
final negative = scanner.scan('-');
// [Scanner.expect] consumes a [Pattern] and throws a [FormatError] if it
// fails. Like [Scanner.scan], it will move the scan pointer forward.
scanner.expect(RegExp(r'\d+'));
// [Scanner.lastMatch] holds the [MatchData] for the most recent call to
// [Scanner.scan], [Scanner.expect], or [Scanner.matches].
var number = num.parse(scanner.lastMatch![0]!);
if (scanner.scan('.')) {
scanner.expect(RegExp(r'\d+'));
final decimal = scanner.lastMatch![0]!;
number += int.parse(decimal) / math.pow(10, decimal.length);
}
// [Scanner.expectDone] will throw a [FormatError] if there's any input that
// hasn't yet been consumed.
scanner.expectDone();
return (negative ? -1 : 1) * number;
}
```
32 changes: 32 additions & 0 deletions pkgs/string_scanner/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# https://dart.dev/guides/language/analysis-options
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_this
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- join_return_with_assignment
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- unnecessary_await_in_return
- unnecessary_raw_strings
- use_if_null_to_convert_nulls_to_bools
- use_raw_strings
- use_string_buffers
Loading

0 comments on commit 3815ff3

Please sign in to comment.