Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: tools/addlatexhash.dart

Issue 1890973003: pkg/analyzer: support latest pkg/crypto version (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: nits Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/standalone/io/web_socket_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 // 5 //
6 // ---------------------------------------------------------------------- 6 // ----------------------------------------------------------------------
7 // This is a very specialized tool which was created in order to support 7 // This is a very specialized tool which was created in order to support
8 // adding hash values used as location markers in the LaTeX source of the 8 // adding hash values used as location markers in the LaTeX source of the
9 // language specification. It is intended to take its input file as the 9 // language specification. It is intended to take its input file as the
10 // first argument, an output file name as the second argument, and a 10 // first argument, an output file name as the second argument, and a
11 // hash listing file name as the third argument. From docs/language a 11 // hash listing file name as the third argument. From docs/language a
12 // typical usage would be as follows: 12 // typical usage would be as follows:
13 // 13 //
14 // dart ../../tools/addlatexhash.dart dartLangSpec.tex out.tex hash.txt 14 // dart
15 // --package-root=<build dir>/packages \
16 // ../../tools/addlatexhash.dart dartLangSpec.tex out.tex hash.txt
15 // 17 //
16 // This will produce a normalized variant out.tex of the language 18 // This will produce a normalized variant out.tex of the language
17 // specification with hash values filled in, and a listing hash.txt of 19 // specification with hash values filled in, and a listing hash.txt of
18 // all the hash values along with the label of their textual context 20 // all the hash values along with the label of their textual context
19 // (section, subsection, subsubsection, paragraph) . For more details, 21 // (section, subsection, subsubsection, paragraph) . For more details,
20 // please check the language specification source itself. 22 // please check the language specification source itself.
21 // 23 //
22 // NB: This utility assumes UN*X style line endings, \n, in the LaTeX 24 // NB: This utility assumes UN*X style line endings, \n, in the LaTeX
23 // source file receieved as input; it will not work with other styles. 25 // source file receieved as input; it will not work with other styles.
24 26
25 import 'dart:io'; 27 import 'dart:io';
26 import 'dart:convert'; 28 import 'dart:convert';
27 import '../third_party/pkg/utf/lib/utf.dart'; 29
28 import '../third_party/pkg/crypto/lib/crypto.dart'; 30 import 'package:crypto/crypto.dart';
31 import 'package:convert/convert.dart';
32 import 'package:utf/utf.dart';
29 33
30 // ---------------------------------------------------------------------- 34 // ----------------------------------------------------------------------
31 // Normalization of the text: removal or normalization of parts that 35 // Normalization of the text: removal or normalization of parts that
32 // do not affect the output from latex, such as white space. 36 // do not affect the output from latex, such as white space.
33 37
34 final commentRE = new RegExp(r"[^\\]%.*"); // NB: . does not match \n. 38 final commentRE = new RegExp(r"[^\\]%.*"); // NB: . does not match \n.
35 final whitespaceAllRE = new RegExp(r"^\s+$"); 39 final whitespaceAllRE = new RegExp(r"^\s+$");
36 final whitespaceRE = new RegExp(r"(?:(?=\s).){2,}"); // \s except end-of-line 40 final whitespaceRE = new RegExp(r"(?:(?=\s).){2,}"); // \s except end-of-line
37 41
38 /// Removes [match]ing part of [line], adjusting that part with the 42 /// Removes [match]ing part of [line], adjusting that part with the
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 gatherLines(lines, startIndex, nextIndex) => 481 gatherLines(lines, startIndex, nextIndex) =>
478 lines.getRange(startIndex, nextIndex) 482 lines.getRange(startIndex, nextIndex)
479 .takeWhile(isntHashBlockTerminator) 483 .takeWhile(isntHashBlockTerminator)
480 .map(cleanupLine) 484 .map(cleanupLine)
481 .join(" "); 485 .join(" ");
482 486
483 /// Computes the hash value for the line block starting at [startIndex] 487 /// Computes the hash value for the line block starting at [startIndex]
484 /// in [lines], stopping just before [nextIndex]. SIDE EFFECT: 488 /// in [lines], stopping just before [nextIndex]. SIDE EFFECT:
485 /// Outputs the simplified text and its hash value to [listSink]. 489 /// Outputs the simplified text and its hash value to [listSink].
486 computeHashValue(lines, startIndex, nextIndex, listSink) { 490 computeHashValue(lines, startIndex, nextIndex, listSink) {
487 final hashEncoder = new SHA1();
488 final gatheredLine = gatherLines(lines, startIndex, nextIndex); 491 final gatheredLine = gatherLines(lines, startIndex, nextIndex);
489 final simplifiedLine = simplifyLine(gatheredLine); 492 final simplifiedLine = simplifyLine(gatheredLine);
490 listSink.write(" % $simplifiedLine\n"); 493 listSink.write(" % $simplifiedLine\n");
491 hashEncoder.add(encodeUtf8(simplifiedLine)); 494 var digest = sha1.convert(encodeUtf8(simplifiedLine));
492 return hashEncoder.close(); 495 return digest.bytes;
493 } 496 }
494 497
495 computeHashString(lines, startIndex, nextIndex, listSink) => 498 computeHashString(lines, startIndex, nextIndex, listSink) =>
496 CryptoUtils.bytesToHex(computeHashValue(lines, 499 hex.encode(computeHashValue(lines,
497 startIndex, 500 startIndex,
498 nextIndex, 501 nextIndex,
499 listSink)); 502 listSink));
500 503
501 /// Computes and adds hashes to \LMHash{} lines in [lines] (which 504 /// Computes and adds hashes to \LMHash{} lines in [lines] (which
502 /// must be on the line numbers specified in [hashEvents]), and emits 505 /// must be on the line numbers specified in [hashEvents]), and emits
503 /// sectioning markers and hash values to [listSink], along with 506 /// sectioning markers and hash values to [listSink], along with
504 /// "comments" containing the simplified text (using the format 507 /// "comments" containing the simplified text (using the format
505 /// ' % <text>', where the text is one, long line, for easy grepping 508 /// ' % <text>', where the text is one, long line, for easy grepping
506 /// etc.). 509 /// etc.).
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 normalizedLines = multilineNormalize(normalizedLines); 562 normalizedLines = multilineNormalize(normalizedLines);
560 563
561 // Insert hash values. 564 // Insert hash values.
562 var hashEvents = findHashEvents(normalizedLines); 565 var hashEvents = findHashEvents(normalizedLines);
563 addHashMarks(normalizedLines, hashEvents, listSink); 566 addHashMarks(normalizedLines, hashEvents, listSink);
564 567
565 // Produce/finalize output. 568 // Produce/finalize output.
566 outputFile.writeAsStringSync(normalizedLines.join()); 569 outputFile.writeAsStringSync(normalizedLines.join());
567 listSink.close(); 570 listSink.close();
568 } 571 }
OLDNEW
« no previous file with comments | « tests/standalone/io/web_socket_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698