Skip to content

Instantly share code, notes, and snippets.

@azrdev
Created April 4, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azrdev/afe6c2290bb86a6f86a046c85fca292f to your computer and use it in GitHub Desktop.
Save azrdev/afe6c2290bb86a6f86a046c85fca292f to your computer and use it in GitHub Desktop.
kde syntax highlighting for ledger files
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd"
[
<!ENTITY more "(_\d+)*">
<!ENTITY int "[+-]?(0|[1-9]\d*)&more;">
<!ENTITY frac "\.\d+&more;">
<!ENTITY exp "[eE][+-]?\d+&more;">
<!ENTITY offset "[+-]\d\d:\d\d">
<!ENTITY time "\d\d:\d\d:\d\d(\.\d+)?(&offset;|Z)?">
<!ENTITY datetime "\d\d\d\d-\d\d-\d\d(T&time;)?">
]>
<language name="Ledger" section="Other" extensions="*.ledger" version="1" kateversion="5.0" author="azrdev@googlemail.com" license="MIT">
<!-- https://www.ledger-cli.org/3.0/doc/ledger3.html#Journal-File-Format-for-Developers -->
<highlighting>
<contexts>
<context attribute="Error" lineEndContext="#stay" name="Ledger">
<DetectSpaces attribute="Whitespace"/>
<AnyChar String="0123456789" column="0" lookAhead="true" attribute="Date" context="TransactionHeader" endRegion="Transaction" beginRegion="Transaction"/>
<AnyChar String="=~" attribute="Clearing" context="TransactionHeader" />
<IncludeRules context="DetectComment" endRegion="Transaction" />
</context>
<context attribute="Error" lineEndContext="Transaction" name="TransactionHeader">
<RegExpr String="\d\d\d\d[/-]\d\d[/-]\d\d" attribute="Date" />
<DetectSpaces attribute="Whitespace"/>
<DetectChar char="!" attribute="Clearing"/>
<DetectChar char="*" attribute="Clearing"/>
<DetectChar char="=" attribute="Clearing"/>
<RegExpr String=".*$" attribute="Header"/>
</context>
<context attribute="Error" lineEndContext="TransactionContinue" name="Transaction">
<DetectSpaces attribute="Whitespace"/>
<DetectIdentifier attribute="Account"/>
<DetectChar char=":" attribute="AccountSeparator"/>
<RegExpr String="-?\s*\d+([,\.]\d*)?\s*.?" attribute="Amount" />
<IncludeRules context="DetectComment" />
</context>
<context attribute="Error" lineEndContext="#stay" name="TransactionContinue">
<DetectSpaces attribute="Whitespace" context="Transaction" />
<IncludeRules context="Ledger" />
</context>
<context attribute="Comment" name="DetectComment">
<AnyChar String=";#%|*" attribute="Comment" context="Comment" firstNonSpace="true" />
</context>
<context attribute="Comment" lineEndContext="#pop" name="Comment">
<DetectSpaces/>
<DetectIdentifier/>
</context>
</contexts>
<itemDatas>
<itemData name="Normal Text" defStyleNum="dsNormal"/>
<itemData name="Date" defStyleNum="dsBaseN"/>
<itemData name="Clearing" defStyleNum="dsNormal"/>
<itemData name="Header" defStyleNum="dsFunction"/>
<itemData name="Account" defStyleNum="dsVariable"/>
<itemData name="AccountSeparator" defStyleNum="dsNormal"/>
<itemData name="Amount" defStyleNum="dsFloat"/>
<itemData name="Whitespace" defStyleNum="dsNormal"/>
<itemData name="Error" defStyleNum="dsError"/>
<itemData name="Comment" defStyleNum="dsComment"/>
</itemDatas>
</highlighting>
<general>
<comments>
<comment name="singleLine" start=";" />
<comment name="singleLine" start="#" /> <!-- TODO: those actually only if at start of line -->
<comment name="singleLine" start="%" />
<comment name="singleLine" start="|" />
<comment name="singleLine" start="*" />
</comments>
<keywords casesensitive="false" wordWrapDeleiminator="" />
<folding indentationsensitive="true" />
</general>
</language>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment