notationBracketIssues function
The issues of text's brackets, at most one per line, each at its line
and column (1-based).
Lines are joined as the parser joins them: a node {…} or document {…} whose JSON goes on over the next lines is JSON, said where it is
read, and not looked at here; a line that ends with [, ( or , left
open goes on over the next (up to notationOpenLineLimit), read as one
line, its issue at its first line with the column in the joined line.
Implementation
List<NotationIssue> notationBracketIssues(String text) {
final out = <NotationIssue>[];
final lines = [for (final l in text.split('\n')) l.endsWith('\r') ? l.substring(0, l.length - 1) : l];
for (var i = 0; i < lines.length; i++) {
var raw = lines[i];
final t = raw.trimLeft();
if (t.isEmpty || t.startsWith('//') || t.startsWith('```')) continue;
if (_jsonLine.hasMatch(raw) && _opened(raw) > 0) {
while (i + 1 < lines.length && _opened(raw) > 0) {
raw = '$raw\n${lines[++i]}';
}
continue;
}
final start = i;
if (RegExp(r'[\[(,]\s*$').hasMatch(raw) && _opened(raw) > 0) {
while (i + 1 < lines.length && i - start < notationOpenLineLimit && _opened(raw) > 0) {
raw = '${raw.trimRight()} ${lines[++i].trim()}';
}
}
if (_lineIssue(raw) case (final column, final message)) {
out.add(NotationIssue(start + 1, column, i == start ? message : '$message (Lines ${start + 1} to ${i + 1} are read as one line; the column is in it.)'));
}
}
return out;
}