Skip to content

Instantly share code, notes, and snippets.

@azrdev
Created April 4, 2019 16:41
Show Gist options
  • Select an option

  • Save azrdev/afe6c2290bb86a6f86a046c85fca292f to your computer and use it in GitHub Desktop.

Select an option

Save azrdev/afe6c2290bb86a6f86a046c85fca292f to your computer and use it in GitHub Desktop.

Revisions

  1. azrdev created this gist Apr 4, 2019.
    75 changes: 75 additions & 0 deletions ledger.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    <?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="[email protected]" 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>