|
|
|
@ -76,15 +76,15 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
'bool',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
String _src;
|
|
|
|
|
StringScanner _scanner;
|
|
|
|
|
String? _src;
|
|
|
|
|
late StringScanner _scanner;
|
|
|
|
|
|
|
|
|
|
List<_HighlightSpan> _spans;
|
|
|
|
|
late List<_HighlightSpan> _spans;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<CodeSpan> format(String src) {
|
|
|
|
|
List<CodeSpan> format(String? src) {
|
|
|
|
|
_src = src;
|
|
|
|
|
_scanner = StringScanner(_src);
|
|
|
|
|
_scanner = StringScanner(_src!);
|
|
|
|
|
|
|
|
|
|
if (_generateSpans()) {
|
|
|
|
|
// Successfully parsed the code
|
|
|
|
@ -93,19 +93,19 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
|
|
|
|
|
for (final span in _spans) {
|
|
|
|
|
if (currentPosition != span.start) {
|
|
|
|
|
formattedText
|
|
|
|
|
.add(CodeSpan(text: _src.substring(currentPosition, span.start)));
|
|
|
|
|
formattedText.add(
|
|
|
|
|
CodeSpan(text: _src!.substring(currentPosition, span.start)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formattedText
|
|
|
|
|
.add(CodeSpan(type: span.type, text: span.textForSpan(_src)));
|
|
|
|
|
.add(CodeSpan(type: span.type, text: span.textForSpan(_src!)));
|
|
|
|
|
|
|
|
|
|
currentPosition = span.end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentPosition != _src.length) {
|
|
|
|
|
formattedText
|
|
|
|
|
.add(CodeSpan(text: _src.substring(currentPosition, _src.length)));
|
|
|
|
|
if (currentPosition != _src!.length) {
|
|
|
|
|
formattedText.add(
|
|
|
|
|
CodeSpan(text: _src!.substring(currentPosition, _src!.length)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return formattedText;
|
|
|
|
@ -126,23 +126,23 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.comment,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Line comments
|
|
|
|
|
if (_scanner.scan('//')) {
|
|
|
|
|
final startComment = _scanner.lastMatch.start;
|
|
|
|
|
final startComment = _scanner.lastMatch!.start;
|
|
|
|
|
|
|
|
|
|
var eof = false;
|
|
|
|
|
int endComment;
|
|
|
|
|
if (_scanner.scan(RegExp(r'.*\n'))) {
|
|
|
|
|
endComment = _scanner.lastMatch.end - 1;
|
|
|
|
|
endComment = _scanner.lastMatch!.end - 1;
|
|
|
|
|
} else {
|
|
|
|
|
eof = true;
|
|
|
|
|
endComment = _src.length;
|
|
|
|
|
endComment = _src!.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
@ -162,8 +162,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'r".*"'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -172,8 +172,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r"r'.*'"))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -182,8 +182,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -192,8 +192,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -202,8 +202,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -212,8 +212,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.string,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -222,8 +222,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'\d+\.\d+'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.number,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -231,7 +231,7 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
// Integer
|
|
|
|
|
if (_scanner.scan(RegExp(r'\d+'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(_HighlightType.number,
|
|
|
|
|
_scanner.lastMatch.start, _scanner.lastMatch.end));
|
|
|
|
|
_scanner.lastMatch!.start, _scanner.lastMatch!.end));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -239,8 +239,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.punctuation,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -249,17 +249,17 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (_scanner.scan(RegExp(r'@\w+'))) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
_HighlightType.keyword,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Words
|
|
|
|
|
if (_scanner.scan(RegExp(r'\w+'))) {
|
|
|
|
|
_HighlightType type;
|
|
|
|
|
_HighlightType? type;
|
|
|
|
|
|
|
|
|
|
var word = _scanner.lastMatch[0];
|
|
|
|
|
var word = _scanner.lastMatch![0]!;
|
|
|
|
|
if (word.startsWith('_')) {
|
|
|
|
|
word = word.substring(1);
|
|
|
|
|
}
|
|
|
|
@ -279,8 +279,8 @@ class DartSyntaxPrehighlighter extends SyntaxPrehighlighter {
|
|
|
|
|
if (type != null) {
|
|
|
|
|
_spans.add(_HighlightSpan(
|
|
|
|
|
type,
|
|
|
|
|
_scanner.lastMatch.start,
|
|
|
|
|
_scanner.lastMatch.end,
|
|
|
|
|
_scanner.lastMatch!.start,
|
|
|
|
|
_scanner.lastMatch!.end,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -346,13 +346,13 @@ class CodeSpan {
|
|
|
|
|
CodeSpan({this.type = _HighlightType.base, this.text});
|
|
|
|
|
|
|
|
|
|
final _HighlightType type;
|
|
|
|
|
final String text;
|
|
|
|
|
final String? text;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toString() {
|
|
|
|
|
return 'TextSpan('
|
|
|
|
|
'style: codeStyle.${_styleNameOf(type)}, '
|
|
|
|
|
"text: '${_escape(text)}'"
|
|
|
|
|
"text: '${_escape(text!)}'"
|
|
|
|
|
')';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -376,7 +376,6 @@ String _styleNameOf(_HighlightType type) {
|
|
|
|
|
case _HighlightType.base:
|
|
|
|
|
return 'baseStyle';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String _escape(String text) {
|
|
|
|
@ -409,4 +408,4 @@ String _encode(int charCode) {
|
|
|
|
|
String _encodeAndPad(int charCode) {
|
|
|
|
|
final encoded = _encode(charCode);
|
|
|
|
|
return '0' * (4 - encoded.length) + encoded;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|