p-hatan/ mirror

pub repository

mirror.p-hatan.ir

string_scanner

0.1.2

A class for parsing strings using a sequence of patterns.

Download archive

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.2

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

0.1.1

  • Declare SpanScanner's exposed SourceSpans and SourceLocations to be FileSpans and FileLocations. 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 StringScannerExceptions 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.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add string_scanner
pubspec.yaml
name: string_scanner
version: 0.1.2
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

VersionPublishedArchiveSHA-256
0.0.12014-04-02T20:59:47.066710ZDownloadfe91c1bccedd418967b9ad2e8c6b35ca49410ea4bf67667a02ce60589528c640
0.0.22014-05-30T00:53:43.270050ZDownload2b8b76a254c708db6f9d6d40cd2090b778848bbcfbe84790f8776484f6ea63ad
0.0.32014-06-23T21:11:28.461470ZDownload0528a32b7e584f28efec89bd3b4913c26d784856b22b0b3f4ac05a8495c94a21
0.1.02014-07-24T03:10:44.466070ZDownloadaeb37f2a6f2a0dbb8b57befebbe4554043b38f99aceff7afb08ff35c79348a0e
0.1.12014-10-29T00:53:53.506420ZDownload5e1edb65fb34bbd376a360161a13f4a8066c91e5079429d2217fd2f16c4add88
0.1.22014-11-05T23:41:55.713160ZDownload53425dd139e873b343b4caaecbbafa0dee8e94d3439e00ec5419a1cc616ba5c8
0.1.32014-12-12T01:40:31.568750ZDownload094a2073980a09a31cf8f7eebb3505c8acf2aad4736943e462a389049e44793e
0.1.3+12015-03-30T22:25:16.558510ZDownload865c9a2f5aac974dd2b5d9df6eb12b52d399e331ea9d8317ddc057b8e99e10fb
0.1.3+22015-09-02T00:29:50.320ZDownload2662dffda7ae5216419788bd1f8d31062417862a6363bcb3fa1a72ddb0507c96
0.1.42015-09-02T18:45:57.724ZDownload6f5c3996c852825e99a4c9cfb580c76b21ad178d55ed58cb772fffb5a37e2aae
0.1.4+12016-01-15T00:34:16.276ZDownload1e2d1bfcdd4106dc25a8faaeb37cab8ae76bbb931c59c6a931b01163eae892cf
0.1.52016-06-06T23:52:28.189ZDownloadbfbbbe6914587a83fe41a6cc1a70bb0c54f42aaacad18653e8d7306c4970aaad
1.0.02016-06-14T23:21:48.009ZDownload41de49fb03f38fd84dc0a341d54d139757531e40ad267fd353af46497f5050f8
1.0.12016-11-02T22:12:48.016ZDownload204cdb66eb0a8b933cb88f7504640e6dccdc35e15a2ec05a7aebfbe53b7a2fe8
1.0.22017-05-22T19:51:33.942816ZDownloada6bf454b08968f966a5c99aeca09f5ab0e86b0654e5e63045d9da6212fc6ebcd
1.0.32018-07-18T19:31:40.796230ZDownload5addee8c61b2038bbb59aff4cf3a1b1540a2b581f75d9a8cebdb666d5a7af6dd
1.0.42018-08-13T19:34:54.805889ZDownload10f97d3f82093cdcc5c18afcb9e4a4b8c20da7bd9ca03999b69c1eb3c0833ce6
1.0.52019-07-31T20:18:04.223091ZDownload43a5dd314205bbc0aeb8fccd8587f9986d79911fdb469476211eaef856b38d66
1.1.0-nullsafety2020-07-29T16:01:36.464304ZDownload6a67bc8cdefb6287842ff20cb3a69fa371d7ae4d6ba92f754035d1a6178d72bf
1.1.0-nullsafety.12020-09-22T16:20:09.152273ZDownload9c6bfb585bd920598625ffb79136ff8375ada24b1bb9f8b1b492f9b02b376c5f
1.1.0-nullsafety.22020-10-23T21:32:54.442267ZDownloadd68ff7df906448d4e11280c8d50d5e96b38a4e6370ed6a85bc1890b060b7ec08
1.1.0-nullsafety.32020-11-03T22:35:52.697298ZDownloadc36d2a9e401e97522ab53a72f443bea143344e818e5bb7f96d52c5c4e32a2ea1
1.1.02021-02-02T23:50:11.994548ZDownloaddd11571b8a03f7cadcf91ec26a77e02bfbd6bbba2a512924d3116646b4198fc4
1.1.12022-05-12T18:00:08.033022ZDownload862015c5db1f3f3c4ea3b94dc2490363a84262994b88902315ed74be1155612f
1.2.02022-10-31T19:18:22.647998ZDownload556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde
1.3.02024-07-11T16:51:35.514514ZDownload688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3
1.4.02024-10-16T17:36:29.459064ZDownload0bd04f5bb74fcd6ff0606a888a30e917af9bd52820b178eaa464beb11dca84b6
1.4.12024-12-17T10:00:43.322120ZDownload921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43

Dependencies

path "\u003e=1.2.0 \u003c2.0.0"

source_span "\u003e=1.0.0 \u003c2.0.0"