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

Side by Side Diff: lib/src/parser.dart

Issue 1843173003: Fix strong mode warnings and errors. (Closed) Base URL: git@github.com:dart-lang/glob@master
Patch Set: 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 | « lib/src/list_tree.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:path/path.dart' as p; 5 import 'package:path/path.dart' as p;
6 import 'package:string_scanner/string_scanner.dart'; 6 import 'package:string_scanner/string_scanner.dart';
7 7
8 import 'ast.dart'; 8 import 'ast.dart';
9 import 'utils.dart'; 9 import 'utils.dart';
10 10
(...skipping 15 matching lines...) Expand all
26 : _scanner = new StringScanner(component), 26 : _scanner = new StringScanner(component),
27 _caseSensitive = caseSensitive; 27 _caseSensitive = caseSensitive;
28 28
29 /// Parses an entire glob. 29 /// Parses an entire glob.
30 SequenceNode parse() => _parseSequence(); 30 SequenceNode parse() => _parseSequence();
31 31
32 /// Parses a [SequenceNode]. 32 /// Parses a [SequenceNode].
33 /// 33 ///
34 /// If [inOptions] is true, this is parsing within an [OptionsNode]. 34 /// If [inOptions] is true, this is parsing within an [OptionsNode].
35 SequenceNode _parseSequence({bool inOptions: false}) { 35 SequenceNode _parseSequence({bool inOptions: false}) {
36 var nodes = []; 36 var nodes = <AstNode>[];
37 37
38 if (_scanner.isDone) { 38 if (_scanner.isDone) {
39 _scanner.error('expected a glob.', position: 0, length: 0); 39 _scanner.error('expected a glob.', position: 0, length: 0);
40 } 40 }
41 41
42 while (!_scanner.isDone) { 42 while (!_scanner.isDone) {
43 if (inOptions && (_scanner.matches(',') || _scanner.matches('}'))) break; 43 if (inOptions && (_scanner.matches(',') || _scanner.matches('}'))) break;
44 nodes.add(_parseNode(inOptions: inOptions)); 44 nodes.add(_parseNode(inOptions: inOptions));
45 } 45 }
46 46
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 if (_scanner.matches(']')) _scanner.error('unexpected "]".'); 92 if (_scanner.matches(']')) _scanner.error('unexpected "]".');
93 var negated = _scanner.scan('!') || _scanner.scan('^'); 93 var negated = _scanner.scan('!') || _scanner.scan('^');
94 94
95 readRangeChar() { 95 readRangeChar() {
96 var char = _scanner.readChar(); 96 var char = _scanner.readChar();
97 if (negated || char != _SLASH) return char; 97 if (negated || char != _SLASH) return char;
98 _scanner.error('"/" may not be used in a range.', 98 _scanner.error('"/" may not be used in a range.',
99 position: _scanner.position - 1); 99 position: _scanner.position - 1);
100 } 100 }
101 101
102 var ranges = []; 102 var ranges = <Range>[];
103 while (!_scanner.scan(']')) { 103 while (!_scanner.scan(']')) {
104 var start = _scanner.position; 104 var start = _scanner.position;
105 // Allow a backslash to escape a character. 105 // Allow a backslash to escape a character.
106 _scanner.scan('\\'); 106 _scanner.scan('\\');
107 var char = readRangeChar(); 107 var char = readRangeChar();
108 108
109 if (_scanner.scan('-')) { 109 if (_scanner.scan('-')) {
110 if (_scanner.matches(']')) { 110 if (_scanner.matches(']')) {
111 ranges.add(new Range.singleton(char)); 111 ranges.add(new Range.singleton(char));
112 ranges.add(new Range.singleton(_HYPHEN)); 112 ranges.add(new Range.singleton(_HYPHEN));
(...skipping 20 matching lines...) Expand all
133 negated: negated, caseSensitive: _caseSensitive); 133 negated: negated, caseSensitive: _caseSensitive);
134 } 134 }
135 135
136 /// Tries to parse an [OptionsNode]. 136 /// Tries to parse an [OptionsNode].
137 /// 137 ///
138 /// Returns `null` if there's not one to parse. 138 /// Returns `null` if there's not one to parse.
139 AstNode _parseOptions() { 139 AstNode _parseOptions() {
140 if (!_scanner.scan('{')) return null; 140 if (!_scanner.scan('{')) return null;
141 if (_scanner.matches('}')) _scanner.error('unexpected "}".'); 141 if (_scanner.matches('}')) _scanner.error('unexpected "}".');
142 142
143 var options = []; 143 var options = <SequenceNode>[];
144 do { 144 do {
145 options.add(_parseSequence(inOptions: true)); 145 options.add(_parseSequence(inOptions: true));
146 } while (_scanner.scan(',')); 146 } while (_scanner.scan(','));
147 147
148 // Don't allow single-option blocks. 148 // Don't allow single-option blocks.
149 if (options.length == 1) _scanner.expect(','); 149 if (options.length == 1) _scanner.expect(',');
150 _scanner.expect('}'); 150 _scanner.expect('}');
151 151
152 return new OptionsNode(options, caseSensitive: _caseSensitive); 152 return new OptionsNode(options, caseSensitive: _caseSensitive);
153 } 153 }
(...skipping 16 matching lines...) Expand all
170 170
171 for (var char in const [']', '(', ')']) { 171 for (var char in const [']', '(', ')']) {
172 if (_scanner.matches(char)) _scanner.error('unexpected "$char"'); 172 if (_scanner.matches(char)) _scanner.error('unexpected "$char"');
173 } 173 }
174 if (!inOptions && _scanner.matches('}')) _scanner.error('unexpected "}"'); 174 if (!inOptions && _scanner.matches('}')) _scanner.error('unexpected "}"');
175 175
176 return new LiteralNode(buffer.toString(), 176 return new LiteralNode(buffer.toString(),
177 context: _context, caseSensitive: _caseSensitive); 177 context: _context, caseSensitive: _caseSensitive);
178 } 178 }
179 } 179 }
OLDNEW
« no previous file with comments | « lib/src/list_tree.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698