[gtksourceview] ftl.lang: Add support for Mozilla's Fluent ftl file format



commit b68b72db4f7cf6c5fba4c471f31d8641e49b5ce9
Author: Tobias Schönberg <tobias47n9e gmail com>
Date:   Tue Nov 12 02:30:32 2019 +0000

    ftl.lang: Add support for Mozilla's Fluent ftl file format

 data/language-specs/ftl.lang       | 97 ++++++++++++++++++++++++++++++++++++++
 tests/syntax-highlighting/file.ftl | 40 ++++++++++++++++
 2 files changed, 137 insertions(+)
---
diff --git a/data/language-specs/ftl.lang b/data/language-specs/ftl.lang
new file mode 100644
index 00000000..70cd43a3
--- /dev/null
+++ b/data/language-specs/ftl.lang
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ This file is part of GtkSourceView
+
+ Author: Tobias Schönberg <tobias47n9e gmail com>
+ Copyright (C) 2019 Tobias Schönberg <tobias47n9e gmail com>
+
+ 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="ftl" name="Fluent" version="2.0" _section="Other">
+  <metadata>
+    <property name="mimetypes">text/x-fluent</property>
+    <property name="globs">*.ftl</property>
+    <property name="line-comment-start">#</property>
+  </metadata>
+
+  <styles>
+    <style id="quoted-text" name="Text in quotes" map-to="def:string"/>
+    <style id="term" name="Term" map-to="def:keyword"/>
+    <style id="variable" name="Variable" map-to="def:identifier"/>
+    <style id="attribute" name="Attribute" map-to="def:operator"/>
+    <style id="variant-key" name="Variant key" map-to="def:identifier"/>
+    <style id="function" name="Function" map-to="def:function"/>
+  </styles>
+
+  <definitions>
+    <context id="quoted-text" style-ref="quoted-text" class="string">
+      <start>"</start>
+      <end>"</end>
+    </context>
+
+    <context id="term" style-ref="term" extend-parent="false">
+      <match>(?&lt;!\w)-[\w-]*\b</match>
+    </context>
+
+    <context id="variable" style-ref="variable" extend-parent="false">
+      <match>\$[a-zA-Z][a-zA-Z0-9_-]*\b</match>
+    </context>
+
+    <context id="attribute" style-ref="attribute" extend-parent="false">
+      <match>(?&lt;= )\.[a-zA-Z-]*\b</match>
+    </context>
+
+    <context id="variant-key" style-ref="variant-key" class="string">
+      <start>\*?\[</start>
+      <end>\]</end>
+    </context>
+
+    <context id="function" style-ref="function">
+      <keyword>DATETIME</keyword>
+      <keyword>NUMBER</keyword>
+    </context>
+
+    <context id="placeable" class="string">
+      <start>\{</start>
+      <end>\}</end>
+      <include>
+        <context ref="variant-key"/>
+        <context ref="variable"/>
+        <context ref="term"/>
+        <context ref="function"/>
+        <context ref="quoted-text"/>
+        <context ref="placeable"/>
+      </include>
+    </context>
+
+    <context id="value" class="string" class-disabled="no-spell-check">
+      <start>(?&lt;==)</start>
+      <end>^(?! )</end>
+      <include>
+        <context ref="placeable"/>
+        <context ref="attribute"/>
+      </include>
+    </context>
+
+    <context id="ftl" class="no-spell-check">
+      <include>
+        <context ref="value"/>
+        <context ref="term"/>
+        <context ref="def:shell-like-comment"/>
+      </include>
+    </context>
+  </definitions>
+</language>
diff --git a/tests/syntax-highlighting/file.ftl b/tests/syntax-highlighting/file.ftl
new file mode 100644
index 00000000..f920f3b8
--- /dev/null
+++ b/tests/syntax-highlighting/file.ftl
@@ -0,0 +1,40 @@
+# Comment
+
+## Multiline
+
+multi = Text can also span multiple lines
+    as long as each new line is indented
+    by at least one space.
+single = This is a single line message
+
+## Terms
+
+-brand-name = Gnome
+installing = Installing { -brand-name }
+
+## Special characters
+
+spaces = {"    "}This message starts with 3 spaces
+tears-of-joy = Use {"\U01F602"} or 😂
+
+## Varibles
+
+unread-emails = { $user } has { $email-count } unread emails
+
+## Selectors & Functions
+
+your-rank = { NUMBER($pos, type: "ordinal") ->
+   [1] You finished first!
+   [one] You finished {$pos}st
+   [two] You finished { $pos }nd
+   [few] You finished {$pos}rd
+  *[other] You finished {$pos}th
+}
+
+## Attributes
+
+login-input = Predefined value
+    .placeholder = email example com
+    .aria-label = Login input value
+    .title = Type your login email
+


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