parseAssumptions method
This parses the assumptions in the "Examples can assume:" block from the
given file
.
Implementation
List<SourceLine> parseAssumptions(File file) {
// Whether or not we're in the file-wide preamble section ("Examples can assume").
bool inPreamble = false;
final List<SourceLine> preamble = <SourceLine>[];
int lineNumber = 0;
int charPosition = 0;
for (final String line in file.readAsLinesSync()) {
if (inPreamble && line.trim().isEmpty) {
// Reached the end of the preamble.
break;
}
if (!line.startsWith('// ')) {
lineNumber++;
charPosition += line.length + 1;
continue;
}
if (line == '// Examples can assume:') {
inPreamble = true;
lineNumber++;
charPosition += line.length + 1;
continue;
}
if (inPreamble) {
preamble.add(SourceLine(
line.substring(3),
startChar: charPosition,
endChar: charPosition + line.length + 1,
element: '#assumptions',
file: file,
line: lineNumber,
));
}
lineNumber++;
charPosition += line.length + 1;
}
return preamble;
}