Repository: alecthomas/chroma
Pull request #903 (2023-12-19 11:21:27)

Add desktop entry lexer
This lexer was generated from `pygments.lexers.configs.DesktopLexer`.


Patch:
diff --git a/README.md b/README.md
index 6a7c77d..c272c03 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ translators for Pygments lexers and styles.
 |   A    | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, AutoHotkey, AutoIt, Awk                                                                             |
 |   B    | Ballerina, Bash, Bash Session, Batchfile, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck                                                                                                                                             |
 |   C    | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython                    |
-|   D    | D, Dart, Dax, Diff, Django/Jinja, dns, Docker, DTD, Dylan                                                                                                                                                                                 |
+|   D    | D, Dart, Dax, Desktop Entry, Diff, Django/Jinja, dns, Docker, DTD, Dylan                                                                                                                                                                                 |
 |   E    | EBNF, Elixir, Elm, EmacsLisp, Erlang                                                                                                                                                                                                 |
 |   F    | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp                                                                                                                                                                           |
 |   G    | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy                                                                                              |
diff --git a/lexers/embedded/desktop_entry.xml b/lexers/embedded/desktop_entry.xml
new file mode 100644
index 0000000..ad71ad4
--- /dev/null
+++ b/lexers/embedded/desktop_entry.xml
@@ -0,0 +1,17 @@
+<lexer>
+  <config>
+    <name>Desktop file</name>
+    <alias>desktop</alias>
+    <alias>desktop_entry</alias>
+    <filename>*.desktop</filename>
+    <mime_type>application/x-desktop</mime_type>
+  </config>
+  <rules>
+    <state name="root">
+      <rule pattern="^[ \t]*\n"><token type="TextWhitespace"/></rule>
+      <rule pattern="^(#.*)(\n)"><bygroups><token type="CommentSingle"/><token type="TextWhitespace"/></bygroups></rule>
+      <rule pattern="(\[[^\]\n]+\])(\n)"><bygroups><token type="Keyword"/><token type="TextWhitespace"/></bygroups></rule>
+      <rule pattern="([-A-Za-z0-9]+)(\[[^\] \t=]+\])?([ \t]*)(=)([ \t]*)([^\n]*)([ \t\n]*\n)"><bygroups><token type="NameAttribute"/><token type="NameNamespace"/><token type="TextWhitespace"/><token type="Operator"/><token type="TextWhitespace"/><token type="LiteralString"/><token type="TextWhitespace"/></bygroups></rule>
+    </state>
+  </rules>
+</lexer>
\ No newline at end of file


Test patch:
diff --git a/lexers/testdata/desktop_entry.actual b/lexers/testdata/desktop_entry.actual
new file mode 100644
index 0000000..1c2a468
--- /dev/null
+++ b/lexers/testdata/desktop_entry.actual
@@ -0,0 +1,8 @@
+# Created with jdDesktopEntryEdit 1.3
+[Desktop Entry]
+Type=Application
+Name=Chroma
+Comment= A general purpose syntax highlighter in pure Go
+TryExec=chroma
+Exec=chroma
+Terminal=true
diff --git a/lexers/testdata/desktop_entry.expected b/lexers/testdata/desktop_entry.expected
new file mode 100644
index 0000000..be9442e
--- /dev/null
+++ b/lexers/testdata/desktop_entry.expected
@@ -0,0 +1,31 @@
+[
+  {"type":"CommentSingle","value":"# Created with jdDesktopEntryEdit 1.3"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"Keyword","value":"[Desktop Entry]"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"Type"},
+  {"type":"Operator","value":"="},
+  {"type":"LiteralString","value":"Application"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"Name"},
+  {"type":"Operator","value":"="},
+  {"type":"LiteralString","value":"Chroma"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"Comment"},
+  {"type":"Operator","value":"="},
+  {"type":"TextWhitespace","value":" "},
+  {"type":"LiteralString","value":"A general purpose syntax highlighter in pure Go"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"TryExec"},
+  {"type":"Operator","value":"="},
+  {"type":"LiteralString","value":"chroma"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"Exec"},
+  {"type":"Operator","value":"="},
+  {"type":"LiteralString","value":"chroma"},
+  {"type":"TextWhitespace","value":"\n"},
+  {"type":"NameAttribute","value":"Terminal"},
+  {"type":"Operator","value":"="},
+  {"type":"LiteralString","value":"true"},
+  {"type":"TextWhitespace","value":"\n"}
+]