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