Skip to content

Commit

Permalink
Add desktop entry lexer (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobDev committed Dec 19, 2023
1 parent f130045 commit 016768b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 |
Expand Down
17 changes: 17 additions & 0 deletions 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>
8 changes: 8 additions & 0 deletions 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
31 changes: 31 additions & 0 deletions 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"}
]

0 comments on commit 016768b

Please sign in to comment.