[gtksourceview] dart.lang: add support for Dart language



commit 4bcd4858a81a8cac7891c006d9e726bc188fc15d
Author: Olzhas Suleimen <amajisenpai gmail com>
Date:   Fri Feb 8 16:06:13 2019 +0600

    dart.lang: add support for Dart language

 data/language-specs/Makefile.am     |   1 +
 data/language-specs/dart.lang       | 311 ++++++++++++++++++++++++++++++++++++
 tests/syntax-highlighting/file.dart |  43 +++++
 3 files changed, 355 insertions(+)
---
diff --git a/data/language-specs/Makefile.am b/data/language-specs/Makefile.am
index 6862cfda..335a274b 100644
--- a/data/language-specs/Makefile.am
+++ b/data/language-specs/Makefile.am
@@ -24,6 +24,7 @@ LANGUAGES =                   \
        css.lang                \
        csv.lang                \
        cuda.lang               \
+       dart.lang               \
        def.lang                \
        desktop.lang            \
        diff.lang               \
diff --git a/data/language-specs/dart.lang b/data/language-specs/dart.lang
new file mode 100644
index 00000000..12e747ae
--- /dev/null
+++ b/data/language-specs/dart.lang
@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ This file is part of GtkSourceView
+
+ Copyright (C) 2019 Olzhas Suleimen
+
+ GtkSourceView is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ GtkSourceView is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, see <http://www.gnu.org/licenses/>.
+
+-->
+<language id="dart" name="Dart" version="2.0" _section="Source">
+
+  <metadata>
+    <property name="mimetypes">application/dart;application/x-dart;text/x-dart;text/dart</property>
+    <property name="globs">*.dart</property>
+    <property name="line-comment-start">//</property>
+    <property name="block-comment-start">/*</property>
+    <property name="block-comment-end">*/</property>
+  </metadata>
+
+  <styles>
+    <style id="comment" name="Comment" map-to="def:comment"/>
+    <style id="error" name="Error" map-to="def:error"/>
+    <style id="escaped" name="Escaped" map-to="def:special-char"/>
+    <style id="string" name="String" map-to="def:string" />
+    <style id="null-value" name="Null" map-to="def:special-constant"/>
+    <style id="bool" name="Boolean" map-to="def:boolean"/>
+    <style id="num" name="Numeric" map-to="def:decimal"/>
+    <style id="external" name="Externals" map-to="def:preprocessor"/>
+    <style id="keyword" name="Keywords" map-to="def:keyword"/>
+    <style id="type" name="Data Types" map-to="def:type"/>
+  </styles>
+
+  <definitions>
+
+    <context id="data" style-ref="string">
+      <start>`</start>
+      <end>`</end>
+    </context>
+
+    <context id="field" style-ref="type">
+      <start>\[</start>
+      <end>\]</end>
+    </context>
+
+    <context id="line-doc-comment" style-ref="comment" end-at-line-end="true" class="comment" 
class-disabled="no-spell-check">
+      <start>///</start>
+      <include>
+        <context ref="data"/>
+        <context ref="field"/>
+        <context ref="def:in-line-comment"/>
+      </include>
+    </context>
+
+    <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" 
class-disabled="no-spell-check">
+      <start>//</start>
+      <include>
+        <context ref="def:in-line-comment"/>
+      </include>
+    </context>
+
+    <context id="block-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
+      <start>/\*</start>
+      <end>\*/</end>
+      <include>
+        <context ref="data"/>
+        <context ref="field"/>
+        <context ref="def:in-comment"/>
+      </include>
+    </context>
+
+    <context id="close-comment-outside-comment" style-ref="error">
+      <match>\*/(?!\*)</match>
+    </context>
+
+    <context id="escaped" style-ref="escaped">
+      <match>\\([\\\"\'nrbtf]|[0-9]{1,3}|u[a-fA-f0-9]{1,4}|u{?[a-fA-f0-9]{1,6}}?)</match>
+    </context>
+
+    <context id="expression-identifier" style-ref="escaped">
+      <match>\$_?\w+</match>
+    </context>
+
+    <context id="expression" style-ref="escaped">
+      <start>\$\{</start>
+      <end>\}</end>
+    </context>
+
+    <context id="single-quoted-string" style-ref="string" end-at-line-end="true" class="string" 
class-disabled="no-spell-check">
+      <start>'</start>
+      <end>'</end>
+      <include>
+        <context ref="escaped" />
+        <context ref="expression-identifier" />
+        <context ref="expression" />
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="double-quoted-string" style-ref="string" end-at-line-end="true" class="string" 
class-disabled="no-spell-check">
+      <start>"</start>
+      <end>"</end>
+      <include>
+        <context ref="escaped" />
+        <context ref="expression-identifier" />
+        <context ref="expression" />
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="raw-single-quoted-string" style-ref="string" end-at-line-end="true" class="string" 
class-disabled="no-spell-check">
+      <start>r'</start>
+      <end>'</end>
+      <include>
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="raw-double-quoted-string" style-ref="string" end-at-line-end="true" class="string" 
class-disabled="no-spell-check">
+      <start>r"</start>
+      <end>"</end>
+      <include>
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="multiline-single-quoted-string" style-ref="string" class="string" 
class-disabled="no-spell-check">
+      <start>'''</start>
+      <end>'''</end>
+      <include>
+        <context ref="escaped" />
+        <context ref="expression-identifier" />
+        <context ref="expression" />
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="multiline-double-quoted-string" style-ref="string" class="string" 
class-disabled="no-spell-check">
+      <start>"""</start>
+      <end>"""</end>
+      <include>
+        <context ref="escaped" />
+        <context ref="expression-identifier" />
+        <context ref="expression" />
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="raw-multiline-single-quoted-string" style-ref="string" class="string" 
class-disabled="no-spell-check">
+      <start>r'''</start>
+      <end>'''</end>
+      <include>
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="raw-multiline-double-quoted-string" style-ref="string" class="string" 
class-disabled="no-spell-check">
+      <start>r"""</start>
+      <end>"""</end>
+      <include>
+        <context ref="def:line-continue"/>
+      </include>
+    </context>
+
+    <context id="null-value" style-ref="null-value">
+      <keyword>null</keyword>
+    </context>
+
+    <context id="bool" style-ref="bool">
+      <keyword>true</keyword>
+      <keyword>false</keyword>
+    </context>
+
+    <context id="numeric" style-ref="num">
+      <match 
extended="true">(\b([0-9]+|0[xX][0-9a-fA-F]+)\b|\b([0-9]+[Ee][-]?[0-9]+|([0-9]*\.[0-9]+|[0-9]+\.)([Ee][-]?[0-9]+)?))</match>
+    </context>
+
+    <context id="external" style-ref="external">
+      <keyword>import</keyword>
+      <keyword>export</keyword>
+      <keyword>library</keyword>
+      <keyword>part of</keyword>
+      <keyword>part</keyword>
+      <keyword>hide</keyword>
+      <keyword>show</keyword>
+      <keyword>deferred</keyword>
+    </context>
+
+    <context id="keyword" style-ref="keyword">
+      <keyword>abstract</keyword>
+      <keyword>mixin</keyword>
+      <keyword>extends</keyword>
+      <keyword>class</keyword>
+      <keyword>enum</keyword>
+      <keyword>factory</keyword>
+      <keyword>implements</keyword>
+      <keyword>interface</keyword>
+      <keyword>with</keyword>
+
+      <keyword>async</keyword>
+      <keyword>await</keyword>
+      <keyword>yield</keyword>
+      <keyword>sync</keyword>
+
+      <keyword>covariant</keyword>
+
+      <keyword>if</keyword>
+      <keyword>else</keyword>
+      <keyword>continue</keyword>
+      <keyword>break</keyword>
+      <keyword>for</keyword>
+      <keyword>while</keyword>
+      <keyword>do</keyword>
+      <keyword>case</keyword>
+      <keyword>switch</keyword>
+      <keyword>default</keyword>
+
+      <keyword>try</keyword>
+      <keyword>catch</keyword>
+      <keyword>throw</keyword>
+      <keyword>rethrow</keyword>
+      <keyword>finally</keyword>
+
+      <keyword>this</keyword>
+      <keyword>super</keyword>
+      <keyword>get</keyword>
+      <keyword>set</keyword>
+      <keyword>operator</keyword>
+
+      <keyword>as</keyword>
+      <keyword>is</keyword>
+
+      <keyword>in</keyword>
+
+      <keyword>on</keyword>
+
+      <keyword>return</keyword>
+
+      <keyword>assert</keyword>
+      <keyword>print</keyword>
+    </context>
+
+    <context id="annotation" style-ref="keyword">
+      <match extended="true">
+        @_?\w+\b
+      </match>
+    </context>
+
+    <context id="type" style-ref="type">
+      <keyword>void</keyword>
+      <keyword>dynamic</keyword>
+      <keyword>bool</keyword>
+      <keyword>int</keyword>
+      <keyword>double</keyword>
+      <keyword>num</keyword>
+
+      <keyword>var</keyword>
+      <keyword>final</keyword>
+      <keyword>static</keyword>
+
+      <keyword>new</keyword>
+      <keyword>const</keyword>
+
+      <keyword>typedef</keyword>
+    </context>
+
+    <context id="type-class" style-ref="type">
+      <match extended="true">
+        \b_?[A-Z]\w*\b
+      </match>
+    </context>
+
+    <context id="dart" class="no-spell-check">
+      <include>
+        <context ref="line-doc-comment"/>
+        <context ref="line-comment"/>
+        <context ref="block-comment"/>
+        <context ref="close-comment-outside-comment"/>
+        <context ref="raw-multiline-single-quoted-string"/>
+        <context ref="raw-multiline-double-quoted-string"/>
+        <context ref="multiline-single-quoted-string"/>
+        <context ref="multiline-double-quoted-string"/>
+        <context ref="raw-single-quoted-string"/>
+        <context ref="raw-double-quoted-string"/>
+        <context ref="single-quoted-string"/>
+        <context ref="double-quoted-string"/>
+        <context ref="null-value"/>
+        <context ref="bool"/>
+        <context ref="numeric"/>
+        <context ref="external"/>
+        <context ref="keyword"/>
+        <context ref="annotation"/>
+        <context ref="type"/>
+        <context ref="type-class"/>
+      </include>
+    </context>
+
+  </definitions>
+
+</language>
diff --git a/tests/syntax-highlighting/file.dart b/tests/syntax-highlighting/file.dart
new file mode 100644
index 00000000..c141216e
--- /dev/null
+++ b/tests/syntax-highlighting/file.dart
@@ -0,0 +1,43 @@
+import 'dart:math' show Random;
+
+Future<void> main() async {
+  print('Compute π using the Monte Carlo method.');
+  await for (var estimate in computePi().take(500)) {
+    print('π ≅ $estimate');
+  }
+}
+
+/// Generates a [Stream] of increasingly accurate estimates of `π`.
+Stream<double> computePi({int batch = 100000}) async* {
+  var total = 0;
+  var count = 0;
+  while (true) {
+    var points = generateRandom().take(batch);
+    var inside = points.where((p) => p.isInsideUnitCircle);
+    total += batch;
+    count += inside.length;
+    var ratio = count / total;
+    // Area of a circle is A = π⋅r², therefore π = A/r².
+    // So, when given random points with x ∈ <0,1>,
+    // y ∈ <0,1>, the ratio of those inside a unit circle
+    // should approach π / 4. Therefore, the value of π
+    // should be:
+    yield ratio * 4;
+  }
+}
+
+Iterable<Point> generateRandom([int seed]) sync* {
+  final random = Random(seed);
+  while (true) {
+    yield Point(random.nextDouble(), random.nextDouble());
+  }
+}
+
+class Point {
+  final double x, y;
+  const Point(this.x, this.y);
+  bool get isInsideUnitCircle => x * x + y * y <= 1;
+
+  @override
+  String toString() => 'Point($x, $y)';
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]