pub repository
mirror.p-hatan.irstring_scanner
0.1.0A class for parsing strings using a sequence of patterns.
Readme
This package exposes a StringScanner type that makes it easy to parse a string
using a series of Patterns. For example:
import 'dart:math';
import 'package:string_scanner/string_scanner.dart';
num parseNumber(String source) {
// Scan a number ("1", "1.5", "-3").
var scanner = new 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.
var 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(new RegExp(r"\d+"));
// [Scanner.lastMatch] holds the [MatchData] for the most recent call to
// [Scanner.scan], [Scanner.expect], or [Scanner.matches].
var number = int.parse(scanner.lastMatch[0]);
if (scanner.scan(".")) {
scanner.expect(new RegExp(r"\d+"));
var 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;
}
Changelog
0.1.0
-
Switch from
source_maps'Spanclass tosource_span'sSourceSpanclass. -
new StringScanner()'ssourceUrlparameter is now named to make it clear that it can be safelynull. -
new StringScannerException()takes different arguments in a different order to matchSpanFormatException. -
StringScannerException.stringhas been renamed toStringScannerException.sourceto match theFormatExceptioninterface.
0.0.3
- Make
StringScannerExceptioninherit from source_map's [SpanFormatException][].
0.0.2
-
new StringScanner()now takes an optionalsourceUrlargument that provides the URL of the source file. This is used for error reporting. -
Add
StringScanner.readChar()andStringScanner.peekChar()methods for doing character-by-character scanning. -
Scanners now throw
StringScannerExceptions which provide more detailed access to information about the errors that were thrown and can provide terminal-colored messages. -
Add a
LineScannersubclass ofStringScannerthat automatically tracks line and column information of the text being scanned. -
Add a
SpanScannersubclass ofLineScannerthat exposes matched ranges as [source map][]Spanobjects.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add string_scannerpubspec.yaml
name: string_scanner
version: 0.1.0
author: "Dart Team <misc@dartlang.org>"
homepage: http://www.dartlang.org
description: >
A class for parsing strings using a sequence of patterns.
dependencies:
path: ">=1.2.0 <2.0.0"
source_span: ">=1.0.0 <2.0.0"
dev_dependencies:
unittest: ">=0.10.0 <0.11.0"
environment:
sdk: ">=1.2.0 <2.0.0"
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | 2014-04-02T20:59:47.066710Z | Download | fe91c1bccedd418967b9ad2e8c6b35ca49410ea4bf67667a02ce60589528c640 |
| 0.0.2 | 2014-05-30T00:53:43.270050Z | Download | 2b8b76a254c708db6f9d6d40cd2090b778848bbcfbe84790f8776484f6ea63ad |
| 0.0.3 | 2014-06-23T21:11:28.461470Z | Download | 0528a32b7e584f28efec89bd3b4913c26d784856b22b0b3f4ac05a8495c94a21 |
| 0.1.0 | 2014-07-24T03:10:44.466070Z | Download | aeb37f2a6f2a0dbb8b57befebbe4554043b38f99aceff7afb08ff35c79348a0e |
| 0.1.1 | 2014-10-29T00:53:53.506420Z | Download | 5e1edb65fb34bbd376a360161a13f4a8066c91e5079429d2217fd2f16c4add88 |
| 0.1.2 | 2014-11-05T23:41:55.713160Z | Download | 53425dd139e873b343b4caaecbbafa0dee8e94d3439e00ec5419a1cc616ba5c8 |
| 0.1.3 | 2014-12-12T01:40:31.568750Z | Download | 094a2073980a09a31cf8f7eebb3505c8acf2aad4736943e462a389049e44793e |
| 0.1.3+1 | 2015-03-30T22:25:16.558510Z | Download | 865c9a2f5aac974dd2b5d9df6eb12b52d399e331ea9d8317ddc057b8e99e10fb |
| 0.1.3+2 | 2015-09-02T00:29:50.320Z | Download | 2662dffda7ae5216419788bd1f8d31062417862a6363bcb3fa1a72ddb0507c96 |
| 0.1.4 | 2015-09-02T18:45:57.724Z | Download | 6f5c3996c852825e99a4c9cfb580c76b21ad178d55ed58cb772fffb5a37e2aae |
| 0.1.4+1 | 2016-01-15T00:34:16.276Z | Download | 1e2d1bfcdd4106dc25a8faaeb37cab8ae76bbb931c59c6a931b01163eae892cf |
| 0.1.5 | 2016-06-06T23:52:28.189Z | Download | bfbbbe6914587a83fe41a6cc1a70bb0c54f42aaacad18653e8d7306c4970aaad |
| 1.0.0 | 2016-06-14T23:21:48.009Z | Download | 41de49fb03f38fd84dc0a341d54d139757531e40ad267fd353af46497f5050f8 |
| 1.0.1 | 2016-11-02T22:12:48.016Z | Download | 204cdb66eb0a8b933cb88f7504640e6dccdc35e15a2ec05a7aebfbe53b7a2fe8 |
| 1.0.2 | 2017-05-22T19:51:33.942816Z | Download | a6bf454b08968f966a5c99aeca09f5ab0e86b0654e5e63045d9da6212fc6ebcd |
| 1.0.3 | 2018-07-18T19:31:40.796230Z | Download | 5addee8c61b2038bbb59aff4cf3a1b1540a2b581f75d9a8cebdb666d5a7af6dd |
| 1.0.4 | 2018-08-13T19:34:54.805889Z | Download | 10f97d3f82093cdcc5c18afcb9e4a4b8c20da7bd9ca03999b69c1eb3c0833ce6 |
| 1.0.5 | 2019-07-31T20:18:04.223091Z | Download | 43a5dd314205bbc0aeb8fccd8587f9986d79911fdb469476211eaef856b38d66 |
| 1.1.0-nullsafety | 2020-07-29T16:01:36.464304Z | Download | 6a67bc8cdefb6287842ff20cb3a69fa371d7ae4d6ba92f754035d1a6178d72bf |
| 1.1.0-nullsafety.1 | 2020-09-22T16:20:09.152273Z | Download | 9c6bfb585bd920598625ffb79136ff8375ada24b1bb9f8b1b492f9b02b376c5f |
| 1.1.0-nullsafety.2 | 2020-10-23T21:32:54.442267Z | Download | d68ff7df906448d4e11280c8d50d5e96b38a4e6370ed6a85bc1890b060b7ec08 |
| 1.1.0-nullsafety.3 | 2020-11-03T22:35:52.697298Z | Download | c36d2a9e401e97522ab53a72f443bea143344e818e5bb7f96d52c5c4e32a2ea1 |
| 1.1.0 | 2021-02-02T23:50:11.994548Z | Download | dd11571b8a03f7cadcf91ec26a77e02bfbd6bbba2a512924d3116646b4198fc4 |
| 1.1.1 | 2022-05-12T18:00:08.033022Z | Download | 862015c5db1f3f3c4ea3b94dc2490363a84262994b88902315ed74be1155612f |
| 1.2.0 | 2022-10-31T19:18:22.647998Z | Download | 556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde |
| 1.3.0 | 2024-07-11T16:51:35.514514Z | Download | 688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3 |
| 1.4.0 | 2024-10-16T17:36:29.459064Z | Download | 0bd04f5bb74fcd6ff0606a888a30e917af9bd52820b178eaa464beb11dca84b6 |
| 1.4.1 | 2024-12-17T10:00:43.322120Z | Download | 921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43 |
Dependencies
path "\u003e=1.2.0 \u003c2.0.0"
source_span "\u003e=1.0.0 \u003c2.0.0"