Skip to content

Commit

Permalink
Update Dart lexer to 3.0, implement JSON like property highlighting f…
Browse files Browse the repository at this point in the history
…or Map literal.
  • Loading branch information
zufuliu committed May 20, 2023
1 parent f17623f commit 91c692e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Latest development builds (artifacts in Release configuration for each compiler
* Apache Configuration File
* [CSV File](https://www.rfc-editor.org/rfc/rfc4180)
* [D](tools/lang/D.d), up to D language 2.0.
* [Dart](tools/lang/Dart.dart), up to Dart 2.12.
* [Dart](tools/lang/Dart.dart), up to Dart 3.0.
* Diff/Patch File
* F#
* [Fortran](tools/lang/Fortran.f), up to Fortran 2018.
Expand Down
1 change: 1 addition & 0 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@
#define SCE_DART_WORD2 28
#define SCE_DART_CLASS 29
#define SCE_DART_ENUM 30
#define SCE_DART_KEY 31
#define SCE_SWIFT_DEFAULT 0
#define SCE_SWIFT_COMMENTLINE 1
#define SCE_SWIFT_COMMENTLINEDOC 2
Expand Down
1 change: 1 addition & 0 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,7 @@ val SCE_DART_WORD=
val SCE_DART_WORD2=
val SCE_DART_CLASS=
val SCE_DART_ENUM=
val SCE_DART_KEY=
# Lexical states for SCLEX_SWIFT
lex Swift=SCLEX_SWIFT SCE_SWIFT_
val SCE_SWIFT_DEFAULT=
Expand Down
25 changes: 23 additions & 2 deletions scintilla/lexers/LexDart.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
int chBefore = 0;
int visibleCharsBefore = 0;
int chPrevNonWhite = 0;
bool simpleStringInterpolation = false;
EscapeSequence escSeq;

StyleContext sc(startPos, lengthDoc, initStyle, styler);
Expand Down Expand Up @@ -191,7 +192,9 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
} else if (keywordLists[KeywordIndex_Enumeration].InList(s)) {
sc.ChangeState(SCE_DART_ENUM);
} else if (sc.ch == ':') {
if (IsJumpLabelPrevChar(chBefore)) {
if (chBefore == ',' || chBefore == '{') {
sc.ChangeState(SCE_DART_KEY);
} else if (IsJumpLabelPrevChar(chBefore)) {
sc.ChangeState(SCE_DART_LABEL);
}
} else if (sc.ch != '.') {
Expand Down Expand Up @@ -300,6 +303,10 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
nestedState.push_back(sc.state);
sc.SetState(SCE_DART_OPERATOR2);
sc.Forward();
} else if (sc.chNext == '(') {
simpleStringInterpolation = true;
escSeq.outerState = sc.state;
sc.SetState(SCE_DART_OPERATOR2);
} else if (IsIdentifierStartEx(sc.chNext)) {
escSeq.outerState = sc.state;
sc.SetState(SCE_DART_VARIABLE2);
Expand All @@ -309,7 +316,14 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
if (sc.state == SCE_DART_TRIPLE_STRING_SQ || sc.state == SCE_DART_TRIPLE_STRING_DQ) {
sc.Advance(2);
}
sc.ForwardSetState(SCE_DART_DEFAULT);
sc.Forward();
if ((sc.state == SCE_DART_STRING_SQ || sc.state == SCE_DART_STRING_DQ) && (chBefore == ',' || chBefore == '{')) {
const int chNext = sc.GetLineNextChar();
if (chNext == ':') {
sc.ChangeState(SCE_DART_KEY);
}
}
sc.SetState(SCE_DART_DEFAULT);
}
break;

Expand Down Expand Up @@ -359,13 +373,15 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
sc.SetState(SCE_DART_TRIPLE_STRING_DQ);
sc.Advance(2);
} else {
chBefore = chPrevNonWhite;
sc.SetState(SCE_DART_STRING_DQ);
}
} else if (sc.ch == '\'') {
if (sc.MatchNext('\'', '\'')) {
sc.SetState(SCE_DART_TRIPLE_STRING_SQ);
sc.Advance(2);
} else {
chBefore = chPrevNonWhite;
sc.SetState(SCE_DART_STRING_SQ);
}
} else if (IsNumberStart(sc.ch, sc.chNext)) {
Expand All @@ -386,6 +402,11 @@ void ColouriseDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt
sc.SetState(SCE_DART_IDENTIFIER);
} else if (isoperator(sc.ch)) {
sc.SetState(SCE_DART_OPERATOR);
if (simpleStringInterpolation && sc.ch == ')') {
simpleStringInterpolation = false;
sc.ForwardSetState(escSeq.outerState);
continue;
}
if (!nestedState.empty()) {
if (sc.ch == '{') {
nestedState.push_back(SCE_DART_DEFAULT);
Expand Down
18 changes: 9 additions & 9 deletions src/EditLexers/stlDart.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@

static KEYWORDLIST Keywords_Dart = {{
//++Autogenerated -- start of section automatically generated
"abstract as assert async await break case catch class const continue covariant default deferred do "
"abstract as assert async await base break case catch class const continue covariant default deferred do "
"else enum export extends extension external factory false final finally for get hide "
"if implements import in interface is late library mixin native new null of on operator part required rethrow return "
"set show static super switch sync this throw true try typedef var while with yield "
"sealed set show static super switch sync this throw true try typedef var when while with yield "

, // 1 types
"Function bool double dynamic int num void "
"Function Never bool double dynamic int num void "

, // 2 class
"BidirectionalIterator BigInt Comparable Comparator Completer "
"DateTime Deprecated Directory DoubleLinkedQueue DoubleLinkedQueueEntry Duration Error Exception Expando "
"File FileStat FileSystemEntity FileSystemEvent Future FutureOr HasNextIterator HashMap HashSet "
"IOException Invocation Iterable IterableBase IterableMixin Iterator "
"BigInt Comparable Comparator Completer DateTime Deprecated Directory DoubleLinkedQueue Duration "
"Enum Error Exception Expando File FileLock FileMode FileStat FileSystemEntity FileSystemEvent Future FutureOr "
"HashMap HashSet IOException Invocation Iterable IterableBase IterableMixin Iterator "
"LinkedHashMap LinkedHashSet LinkedList LinkedListEntry List ListBase ListMixin ListQueue "
"Map MapBase MapEntry MapMixin MapView Match Null OSError Object Pattern Platform Point Process Queue "
"Random RawSocket RawSocketEvent Rectangle RegExp RegExpMatch RuneIterator Runes "
"Random RawSocket RawSocketEvent Record Rectangle RegExp RegExpMatch RuneIterator Runes "
"ServerSocket Set SetBase SetMixin Sink Socket SocketException SplayTreeMap SplayTreeSet "
"StackTrace Stopwatch Stream String StringBuffer StringSink Symbol SystemHash "
"Timer Type Uri UriData "
"Timer Type Uri UriData WeakReference "

, // 3 enumeration
NULL
Expand Down Expand Up @@ -52,6 +51,7 @@ static EDITSTYLE Styles_Dart[] = {
{ MULTI_STYLE(SCE_DART_TRIPLE_STRING_SQ, SCE_DART_TRIPLE_STRING_DQ, 0, 0), NP2StyleX_TripleQuotedString, L"fore:#F08000" },
{ MULTI_STYLE(SCE_DART_RAWSTRING_SQ, SCE_DART_RAWSTRING_DQ, SCE_DART_TRIPLE_RAWSTRING_SQ, SCE_DART_TRIPLE_RAWSTRING_DQ), NP2StyleX_RawString, L"fore:#F08000" },
{ SCE_DART_ESCAPECHAR, NP2StyleX_EscapeSequence, L"fore:#0080C0" },
{ SCE_DART_KEY, NP2StyleX_Property, L"fore:#648000" },
{ SCE_DART_LABEL, NP2StyleX_Label, L"back:#FFC040" },
{ SCE_DART_NUMBER, NP2StyleX_Number, L"fore:#FF0000" },
{ MULTI_STYLE(SCE_DART_VARIABLE, SCE_DART_VARIABLE2, 0, 0), NP2StyleX_Variable, L"fore:#9E4D2A" },
Expand Down
48 changes: 24 additions & 24 deletions tools/lang/Dart.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 2.12 https://dart.dev/
// 3.0 https://dart.dev/
// https://dart.dev/guides/language/language-tour
// 2.8 https://dart.dev/guides/language/spec
// 2.13 https://dart.dev/guides/language/spec
// https://github.com/dart-lang/language
// https://github.com/dart-lang/sdk

//! keywords ===========================================================
// https://dart.dev/guides/language/language-tour#keywords
abstract as assert async await
break
base break
case catch class const continue covariant
default deferred do
else enum export extends extension external
Expand All @@ -21,15 +21,15 @@ native new null
of on operator
part
rethrow return required
set show static super switch sync
sealed set show static super switch sync
this throw true try typedef
var
while with
when while with
yield

//! types ===========================================================
// https://dart.dev/guides/language/language-tour#built-in-types
dynamic void Function
dynamic void Function Never
int double
bool num

Expand All @@ -44,23 +44,22 @@ library dart._internal {
library dart.core {
main()
@pragma()
abstract class BigInt implements Comparable<BigInt>
typedef Comparator<T>
abstract class Comparable<T>
class DateTime implements Comparable<DateTime>
class Deprecated
@Deprecated()
@deprecated
@override
abstract class BigInt implements Comparable<BigInt>
typedef Comparator<T>
abstract class Comparable<T>
class DateTime implements Comparable<DateTime>
class Duration implements Comparable<Duration>
abstract class Enum
class Error
abstract class Exception
class Expando<T extends Object>
external bool identical(Object? a, Object? b);
external int identityHashCode(Object? object);
abstract class Invocation
abstract class Iterable<E>
abstract class BidirectionalIterator<E> implements Iterator<E>
abstract class Iterator<E>
abstract class List<E> implements EfficientLengthIterable<E>
abstract class Map<K, V>
Expand All @@ -70,23 +69,24 @@ library dart.core {
abstract class Pattern
abstract class Match
void print(Object? object)
abstract class Record
abstract class RegExp implements Pattern
abstract class RegExpMatch implements Match
class RuneIterator implements BidirectionalIterator<int>
class Runes extends Iterable<int>
abstract class Set<E> extends EfficientLengthIterable<E>
abstract class Sink<T>
abstract class StackTrace
class Stopwatch
abstract class String implements Comparable<String>, Pattern
class Runes extends Iterable<int>
class RuneIterator implements BidirectionalIterator<int>
class RuneIterator implements Iterator<int>
class StringBuffer implements StringSink
abstract class StringSink
abstract class Symbol
abstract class Type
abstract class Uri
class UriData
class Expando<T extends Object>
abstract class WeakReference<T extends Object>
}

library dart.async {
Expand All @@ -100,24 +100,22 @@ library dart.async {
library dart.collection {
abstract class HashMap<K, V> implements Map<K, V>
abstract class HashSet<E> implements Set<E>
abstract class IterableMixin<E> implements Iterable<E>
abstract class IterableBase<E> extends Iterable<E>
class HasNextIterator<E>
typedef IterableMixin<E> = Iterable<E>
typedef IterableBase<E> = Iterable<E>
abstract class LinkedHashMap<K, V> implements Map<K, V>
abstract class LinkedHashSet<E> implements Set<E>
class LinkedList<E extends LinkedListEntry<E>> extends Iterable<E>
abstract class LinkedListEntry<E extends LinkedListEntry<E>>
abstract class ListBase<E> extends Object with ListMixin<E>
abstract class ListMixin<E> implements List<E>
abstract class ListBase<E> implements List<E>
typedef ListMixin<E> = ListBase<E>
abstract class MapBase<K, V> extends MapMixin<K, V>
abstract class MapMixin<K, V> implements Map<K, V>
typedef MapMixin<K, V> = MapBase<K, V>
class MapView<K, V> implements Map<K, V>
abstract class Queue<E> implements EfficientLengthIterable<E>
class DoubleLinkedQueueEntry<E> extends _DoubleLink<DoubleLinkedQueueEntry<E>>
class DoubleLinkedQueue<E> extends Iterable<E> implements Queue<E>
class ListQueue<E> extends ListIterable<E> implements Queue<E>
abstract class SetMixin<E> implements Set<E>
abstract class SetBase<E> with SetMixin<E>
abstract class SetBase<E> implements Set<E>
typedef SetMixin<E> = SetBase<E>
class SplayTreeMap<K, V> extends _SplayTree<K, _SplayTreeMapNode<K, V>>
class SplayTreeSet<E> extends _SplayTree<E, _SplayTreeSetNode<E>>
}
Expand All @@ -126,6 +124,8 @@ library dart.io {
abstract class IOException implements Exception
class OSError implements Exception
abstract class Directory implements FileSystemEntity
class FileMode
class FileLock
abstract class File implements FileSystemEntity
class FileStat
abstract class FileSystemEntity
Expand Down

0 comments on commit 91c692e

Please sign in to comment.