[gtksourceview] Add lang file for (basic) CSV



commit 9a31304764239d37e1cbfc6b6eba52ff62a29587
Author: Martin Blanchard <tchaik gmx com>
Date:   Wed Apr 15 20:46:28 2015 +0200

    Add lang file for (basic) CSV
    
    Detect CSV files using MIME type (text/csv) or filename's extension
    (.csv) and highlight double-quoted strings, as per described by rfc4180.
    Integer and floating-point number are also supported. A test file is
    provided.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747129

 data/language-specs/Makefile.am    |    1 +
 data/language-specs/csv.lang       |   74 ++++++++++++++++++++++++++++++++++++
 tests/syntax-highlighting/file.csv |    4 ++
 3 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/data/language-specs/Makefile.am b/data/language-specs/Makefile.am
index f784387..27dba3c 100644
--- a/data/language-specs/Makefile.am
+++ b/data/language-specs/Makefile.am
@@ -20,6 +20,7 @@ LANGUAGES =                   \
        cpp.lang                \
        csharp.lang             \
        css.lang                \
+       csv.lang                \
        cuda.lang               \
        def.lang                \
        desktop.lang            \
diff --git a/data/language-specs/csv.lang b/data/language-specs/csv.lang
new file mode 100644
index 0000000..dcca0fb
--- /dev/null
+++ b/data/language-specs/csv.lang
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ This file is part of GtkSourceView
+
+ Author: Martin Blanchard <tchaik gmx com>
+ Copyright (C) 2015 Martin Blanchard <tchaik gmx 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, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+-->
+<language id="csv" _name="CSV" version="2.0" _section="Other">
+  <metadata>
+    <property name="mimetypes">text/csv</property>
+    <property name="globs">*.csv</property>
+  </metadata>
+
+  <styles>
+    <style id="decimal"           _name="Decimal number"        map-to="def:decimal"/>
+    <style id="escaped-character" _name="Escaped character"     map-to="def:special-char"/>
+    <style id="floating-point"    _name="Floating point number" map-to="def:floating-point"/>
+    <style id="string"            _name="String"                map-to="def:string"/>
+  </styles>
+
+  <definitions>
+    <context id="decimal" style-ref="decimal">
+      <match extended="true">
+        (?&lt;![\w\.])
+        [0-9]+
+        (?![\w\.])
+      </match>
+    </context>
+
+    <context id="floating-point" style-ref="floating-point">
+      <match extended="true">
+        (?&lt;![\w\.])
+        ((\.[0-9]+ | [0-9]+\.[0-9]*) ([Ee][+-]?[0-9]*)? | ([0-9]+[Ee][+-]?[0-9]*))
+        (?![\w\.])
+      </match>
+    </context>
+
+    <context id="string" style-ref="string" class="string" class-disabled="no-spell-check">
+      <start>"</start>
+      <end>"</end>
+      <include>
+        <context id="escaped-character" style-ref="escaped-character">
+          <match extended="true">
+            \"\"   # escaped double-quote
+          </match>
+        </context>
+      </include>
+    </context>
+
+    <context id="csv" class="no-spell-check">
+      <include>
+        <context ref="decimal"/>
+        <context ref="floating-point"/>
+        <context ref="string"/>
+      </include>
+    </context>
+  </definitions>
+</language>
diff --git a/tests/syntax-highlighting/file.csv b/tests/syntax-highlighting/file.csv
new file mode 100644
index 0000000..8e68893
--- /dev/null
+++ b/tests/syntax-highlighting/file.csv
@@ -0,0 +1,4 @@
+01,47.498333,19.040833,Unquoted field
+02,60.317222,24.963333,"Double-quoted field"
+03,51.507222,-.1275,"Punctuated , double-quoted, field."
+04,472.181E-01, -1.5528e+00,"""Escaped"" double quote in double-quoted field"


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