This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Rewritten Syntax Highlighting File for Biblatex/Jabref

Tags: None
(comma "," separated)
martinknopp
Registered Member
Posts
1
Karma
0
Hello,

I rewrote the Syntax Highlighting file done by Jeroen Wijnhout and Thomas Braun to accommodate BibLaTeX entry types and field types as well as some non standard elements used by the JabRef bibliography tool (only up to version 3.8.2 so far).

The rewritten syntax highlighting offers:
- entry types and field types according to latest version of biblatex (v. 3.14 - https://ctan.org/pkg/biblatex)
- accepts only valid field types
- folding and highlighting for the JabRef groupstree

This is my first time contributing to an open source project, so any hint on how to submit this for review is highly appreciated. Also feel free to point out errors I have made or features missing. Is there a better solution for the groupstree-folding?

Cheers
Martin

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
     [
     <!ENTITY stringVariable      "[a-zA-Z0-9\-]+">
     <!ENTITY latexCmd        "\\([a-zA-Z@]+|[^ ])">
     <!ENTITY refKeyFormat     "[a-zA-Z0-9_@\\-\\:]+"> <!--taken from kile 2.0.3-->
     ]>
<language name="BibLaTeX-Jabref-Style" version="1" kateversion="5.0" extensions="*.bib" section="Markup" mimetype="text/x-bib" casesensitive="1" author="Martin Knopp+Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)+Thomas Braun (thomas.braun@virtuell-zuhause.de)" license="LGPL">
    <!--
    based on BibLaTeX v. 3.14 dated 2019-12-01,
    see documentaton at: https://ctan.org/pkg/biblatex
    in addition:
    * highlighting of JabRef 3.8.2 groups and groupstree (Files generated by later versions of JabRef use a different syntax in the groupstree. Replace all occurances of "ExplicitGroup" to "StaticGroup", and "groupstree" (casesensitive!) to "grouping")
    * folding of the JabRef 3.8.2 groupstree
    -->
  <highlighting>
      <list name="kw_entry">                      <!-- ENTRY TYPES BibLaTeX v. 3.14 2019-12-01-->
      <item>@article</item>
      <item>@book</item>
      <item>@mvbook</item>
      <item>@inbook</item>
      <item>@bookinbook</item>
      <item>@suppbook</item>
      <item>@booklet</item>
      <item>@collection</item>
      <item>@mvcollection</item>
      <item>@incollection</item>
      <item>@suppcollection</item>
      <item>dataset</item>
      <item>@manual</item>
      <item>@misc</item>
      <item>@online</item>
      <item>@patent</item>
      <item>@periodical</item>
      <item>@suppperiodical</item>
      <item>@proceedings</item>
      <item>@mvproceedings</item>
      <item>@inproceedings</item>
      <item>@reference</item>
      <item>@mvreference</item>
      <item>@inreference</item>
      <item>@report</item>
      <item>@set</item>
      <item>@software</item>
      <item>@thesis</item>
      <item>@unpublished</item>
      <item>@xdata</item>
      <item>@conference</item>                  <!-- ALIASES-->
      <item>@electronic</item>
      <item>@mastersthesis</item>
      <item>@phdthesis</item>
      <item>@techreport</item>
      <item>@www</item>
      <item>@artwork</item>                      <!--NON-STANDARD TYPES-->
      <item>@audio</item>
      <item>@bibnote</item>
      <item>commentary</item>
      <item>image</item>
      <item>jurisdiction</item>
      <item>legislation</item>
      <item>legal</item>
      <item>letter</item>
      <item>movie</item>
      <item>music</item>
      <item>performance</item>
      <item>review</item>
      <item>standard</item>
      <item>video</item>
    </list>
   
    <list name="field_list">                    <!-- DATA FIELDS Biblatex v. 3.14 2019-12-01 -->
        <item>abstract</item>
        <item>addendum</item>
        <item>afterword</item>
        <item>annotation</item>
        <item>annotator</item>
        <item>author</item>
        <item>authortype</item>
        <item>bookauthor</item>
        <item>bookpagination</item>
        <item>booksubtitle</item>
        <item>booktitle</item>
        <item>booktitleaddon</item>
        <item>chapter</item>
        <item>commentator</item>
        <item>date</item>
        <item>doi</item>
        <item>edition</item>
        <item>editor</item>
        <item>editora</item>
        <item>editorb</item>
        <item>editorc</item>
        <item>editortype</item>
        <item>editoratype</item>
        <item>editorbtype</item>
        <item>editorctype</item>
        <item>eid</item>
        <item>entrysubtype</item>
        <item>eprint</item>
        <item>eprintclass</item>
        <item>eprinttype</item>
        <item>eventdate</item>
        <item>eventtitle</item>
        <item>eventtitleaddon</item>
        <item>file</item>
        <item>forword</item>
        <item>holder</item>
        <item>howpublished</item>
        <item>indextitle</item>
        <item>institution</item>
        <item>introduction</item>
        <item>isan</item>
        <item>isbn</item>
        <item>ismn</item>
        <item>isrn</item>
        <item>issn</item>
        <item>issue</item>
        <item>issuesubtitle</item>
        <item>issuetitle</item>
        <item>iswc</item>
        <item>journalsubtitle</item>
        <item>journaltitle</item>
        <item>label</item>
        <item>language</item>
        <item>library</item>
        <item>location</item>
        <item>mainsubtitle</item>
        <item>maintitle</item>
        <item>maintitleaddon</item>
        <item>month</item>
        <item>nameaddon</item>
        <item>note</item>
        <item>number</item>
        <item>organization</item>
        <item>origdate</item>
        <item>origlanguage</item>
        <item>origlocation</item>
        <item>origpublisher</item>
        <item>origtitle</item>
        <item>pages</item>
        <item>pagetotal</item>
        <item>pagination</item>
        <item>part</item>
        <item>publisher</item>
        <item>pubstate</item>
        <item>reprinttitle</item>
        <item>series</item>
        <item>shortauthor</item>
        <item>shorteditor</item>
        <item>shorthand</item>
        <item>shorthandintro</item>
        <item>shortjournal</item>
        <item>shortseries</item>
        <item>shorttitle</item>
        <item>subtitle</item>
        <item>title</item>
        <item>titleaddon</item>
        <item>translator</item>
        <item>type</item>
        <item>url</item>
        <item>urldate</item>
        <item>venue</item>
        <item>version</item>
        <item>volume</item>
        <item>volumes</item>
        <item>year</item>
        <item>crossref</item>                   <!-- SPECIAL FIELDS: -->
        <item>entryset</item>
        <item>execute</item>
        <item>gender</item>
        <item>langid</item>
        <item>langidopts</item>
        <item>ids</item>
        <item>indexsorttitle</item>
        <item>keywords</item>
        <item>options</item>
        <item>presort</item>
        <item>related</item>
        <item>relatedoptions</item>
        <item>relatedtype</item>
        <item>relatedstring</item>
        <item>sortkey</item>
        <item>sortname</item>
        <item>sortshorthand</item>
        <item>sorttitle</item>
        <item>sortyear</item>
        <item>xdata</item>
        <item>xref</item>
        <item>address</item>                     <!-- ALIASES-->
        <item>annote</item>
        <item>archiveprefix</item>
        <item>journal</item>
        <item>key</item>
        <item>pdf</item>
        <item>primaryclass</item>
        <item>school</item>
        <item>groups</item>                     <!-- used by JabRef to link entry to GroupsTree-->
    </list>
   
    <contexts>
    <context name="Normal" attribute="Comment" lineEndContext="#stay">
        <keyword String="kw_entry" attribute="Entry" context="Entry"/>
        <StringDetect String="@string" attribute="Command" insensitive="true" context="StringCommand"/>
        <StringDetect String="@preamble" attribute="Command" insensitive="true" context="PreambleCommand"/>
        <StringDetect String="@comment" attribute="Comment" insensitive="true" context="Comment"/>              <!-- used by JabRef to store GroupsTree -->
    </context>
   
    <!-- Highlighting and folding of JabRef GroupsTree (JabRef v3.8.2 for JabRef 4 and later "ExplicitGroup" changes to "StaticGroup")
    This solution for folding the GroupsTree is certainly higly inefficent because nearly every line gets checked multiple times just to close all Regions properly -->
    <context name="Comment" attribute="Normal Text" fallthrough="true" fallthroughContext="#pop" lineEndContext="#stay" >
        <DetectChar char="{" context="#stay"/>
        <StringDetect String="jabref-meta: " insensitive="true" context="#stay"/>
        <StringDetect String="groupstree:" context="GroupsTree"/>
        <DetectChar char="}" context="#pop"/>
    </context>

        <context name="GroupsTree" attribute="Normal Text" fallthrough="true" fallthroughContext="#pop" lineEndContext="#stay" >
            <StringDetect String="0 AllEntriesGroup:;" context="#stay"/>
            <StringDetect String="1 ExplicitGroup" attribute="Klass1" context="Klass1" beginRegion="Klass1"/>
        </context>
   
            <context name="Klass1" attribute="Klass1" lineEndContext="#stay">
                <StringDetect String="2 ExplicitGroup" attribute="Klass2" context="Klass2" beginRegion="Klass2"/>
                <StringDetect String="1 ExplicitGroup" context="GroupsTree" endRegion="Klass1" lookAhead="true"/>
            </context>
   
                <context name="Klass2" attribute="Klass2" lineEndContext="#stay" >
                    <StringDetect String="3 ExplicitGroup" attribute="Klass3" context="Klass3" beginRegion="Klass3"/>
                    <StringDetect String="2 ExplicitGroup" context="Klass1" endRegion="Klass2" lookAhead="true"/>
                    <StringDetect String="1 ExplicitGroup" context="Klass1" endRegion="Klass2" lookAhead="true"/>
                </context>
   
                    <context name="Klass3" attribute="Klass3" lineEndContext="#stay" >
                        <StringDetect String="4 ExplicitGroup" attribute="Klass4" context="Klass4" beginRegion="Klass4"/>
                        <StringDetect String="3 ExplicitGroup" context="Klass2" endRegion="Klass3" lookAhead="true"/>
                        <StringDetect String="2 ExplicitGroup" context="Klass2" endRegion="Klass3" lookAhead="true"/>
                        <StringDetect String="1 ExplicitGroup" context="Klass2" endRegion="Klass3" lookAhead="true"/>
                    </context>
   
                        <context name="Klass4" attribute="Klass4" lineEndContext="#stay" >
                            <StringDetect String="5 ExplicitGroup" attribute="Klass5" context="Klass5" beginRegion="Klass5"/>
                            <StringDetect String="4 ExplicitGroup" context="Klass3" endRegion="Klass4" lookAhead="true"/>
                            <StringDetect String="3 ExplicitGroup" context="Klass3" endRegion="Klass4" lookAhead="true"/>
                            <StringDetect String="2 ExplicitGroup" context="Klass3" endRegion="Klass4" lookAhead="true"/>
                            <StringDetect String="1 ExplicitGroup" context="Klass3" endRegion="Klass4" lookAhead="true"/>
                        </context>
   
                            <context name="Klass5" attribute="Klass5" lineEndContext="#stay" >
                                <StringDetect String="6 ExplicitGroup" attribute="Klass6" context="Klass6" beginRegion="Klass6"/>
                                <StringDetect String="5 ExplicitGroup" context="Klass4" endRegion="Klass5" lookAhead="true"/>
                                <StringDetect String="4 ExplicitGroup" context="Klass4" endRegion="Klass5" lookAhead="true"/>
                                <StringDetect String="3 ExplicitGroup" context="Klass4" endRegion="Klass5" lookAhead="true"/>
                                <StringDetect String="2 ExplicitGroup" context="Klass4" endRegion="Klass5" lookAhead="true"/>
                                <StringDetect String="1 ExplicitGroup" context="Klass4" endRegion="Klass5" lookAhead="true"/>
                            </context>
   
                                <context name="Klass6" attribute="Klass6" lineEndContext="#stay" >
                                    <StringDetect String="7 ExplicitGroup" attribute="Klass7" context="Klass7" />
                                    <StringDetect String="6 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                    <StringDetect String="5 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                    <StringDetect String="4 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                    <StringDetect String="3 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                    <StringDetect String="2 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                    <StringDetect String="1 ExplicitGroup" context="Klass5" endRegion="Klass6" lookAhead="true"/>
                                </context>
   
                                    <context name="Klass7" attribute="Klass7" lineEndContext="#stay" >
                                        <StringDetect String="6 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                        <StringDetect String="5 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                        <StringDetect String="4 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                        <StringDetect String="3 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                        <StringDetect String="2 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                        <StringDetect String="1 ExplicitGroup" context="Klass6" endRegion="Klass7" lookAhead="true"/>
                                    </context>

   <context name="PreambleCommand" attribute="Normal Text" fallthrough="true" fallthroughContext="#pop" lineEndContext="#stay" >
      <DetectChar char="{" context="CurlyBracket" />
   </context>
   
   <context name="StringCommand" attribute="Normal Text" fallthrough="true" fallthroughContext="#pop" lineEndContext="#stay" >
      <DetectChar char="{" context="CurlyBracket" />
      <RegExpr String="&stringVariable;" attribute="String" context="CurlyBracket"/>
      </context>

      <context name="Entry" attribute="Normal Text" lineEndContext="#stay">
         <DetectChar char="{"  context="#stay" beginRegion="block" />
         <RegExpr String="&refKeyFormat;" attribute="Ref Key" context="#stay"/>
         <DetectChar char="," context="Field"/>
         <DetectChar char="}" attribute="Normal Text" context="#pop" endRegion="block" />
      </context>

      <context name="Field" attribute="Normal Text" lineEndContext="#stay">
          <keyword String="field_list" attribute="Field" firstNonSpace="true" />
         <DetectSpaces/>
         <DetectChar char="=" context="#stay"/>
         <DetectSpaces/>
         <DetectChar char="{" context="CurlyBracket"/>
         <DetectChar char="}" context="#pop" lookAhead="true"/>
         <DetectChar char="&quot;"  attribute="Normal Text" context="QuotedText"/>
         <DetectChar char="," context="#stay"/>
         <DetectChar char="#" context="#stay"/> <!-- the bibtex string concatenate character -->
         <RegExpr String="[0-9]+" context="#stay"/>
         <RegExpr String="&stringVariable;" attribute="String" /> <!-- assume this is a variable created with @String -->
         <DetectSpaces/>
         <RegExpr String="." attribute="Error" context="#stay"/> <!--this rule catches all errors-->
      </context>

      <context name="CurlyBracket" attribute="Normal Text" lineEndContext="#stay">
         <DetectChar char="{" context="CurlyBracket"/>
         <RegExpr String="&latexCmd;" attribute="LatexCommand" context="#stay"/>
         <RegExpr String="}$" context="#pop#pop"/>
         <DetectChar char="}" context="#pop"/>
      </context>

      <context name="QuotedText" attribute="String" lineEndContext="#stay">
         <DetectChar char="&quot;" attribute="Normal Text" context="#pop"/>
         <RegExpr String="&latexCmd;" attribute="LatexCommand" context="#stay"/>
      </context>
     
    </contexts>

    <itemDatas>
      <itemData name="Normal Text" defStyleNum="dsNormal"/>
      <itemData name="Entry" defStyleNum="dsVariable" spellChecking="false"/>       <!-- used for Entry Types (@article etc.) -->
      <itemData name="Command" defStyleNum="dsFunction" spellChecking="false"/>     <!-- used for @string und @preamble -->
      <itemData name="Field" defStyleNum="dsDataType" spellChecking="false"/>       <!-- used for Data Fields (author, title etc.) -->
      <itemData name="Ref Key" defStyleNum="dsOthers" underline="true" bold="true" spellChecking="false"/>       <!-- used for BibTex-Key -->
      <itemData name="LatexCommand" defStyleNum="dsChar" spellChecking="false"/>    <!-- used for Latex-Code in Data -->
      <itemData name="Comment" defStyleNum="dsComment" spellChecking="false"/>      <!-- used for Text before the first Entry or in @comment-Tags -->
      <itemData name="Error" defStyleNum="dsError" spellChecking="false"/>          <!-- used for Syntax Errors -->
      <itemData name="String" defStyleNum="dsString" spellChecking="true"/>         <!-- used for Data in curly Brackets -->
      <itemData name="Klass1" color="#e2be2e" backgroundColor="#333333" bold="true" underline="true" spellChecking="false"/>   <!-- used for JabRef GroupsTree -->
      <itemData name="Klass2" color="#ffffd7" backgroundColor="#666666" bold="true" underline="false" spellChecking="false"/>
      <itemData name="Klass3" color="#000000" backgroundColor="#b2b2b2" bold="true" underline="false" spellChecking="false"/>
      <itemData name="Klass4" color="#000000" backgroundColor="#cccccc" bold="false" underline="false" spellChecking="false"/>
      <itemData name="Klass5" color="#000000" backgroundColor="#e9e9e9" bold="false" underline="false" spellChecking="false"/>
      <itemData name="Klass6" color="#fc77fc" bold="false" underline="false" spellChecking="false"/>
      <itemData name="Klass7" color="#fc77fc" bold="false" underline="false" spellChecking="false"/>

               
</itemDatas>
  </highlighting>
  <general>
   <keywords casesensitive="0" weakDeliminator="\" wordWrapDeliminator=",{}[]"/>
  </general>
</language>


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]