Hi,
I’m writing a new pluggin for Ledger accounting.
An syntax already exists here, but this assumes English date format, which is not my case.
So I’ve written a new syntax file which looks like this:
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions: [ledger, journal]
scope: source.ledger
variables:
date: "\\d{2}[/-]\\d{2}[/-]\\d{4}"
account: "\\w[\\w:\\s_-]+"
payee: "[^*]+"
contexts:
main:
# Commentary
- match: ^\s*(;.*)$
scope: comment.line
# Non-cleared entry
- match: ^({{date}})([=]?)({{date}})?\s+({{payee}})$
scope: invalid.invalid
# Cleared entry
- match: ^({{date}})([=]?)({{date}})?\s+\*\s+({{payee}})$
captures:
1: string.other.date
2: punctuation.separator
3: string.other.edate
4: markup.italic.desc.cleared
# Account with amount
- match: ^\s+({{account}})\s+([-$£¥€¢\d.,_\w]+.*)$
captures:
1: markup.bold.account
2: variable.other.amount
# Account without amount
- match: ^\s+({{account}})\s*$
scope: markup.bold.account
# Account
- match: ^(account) ({{account}})\s*$
captures:
1: keyword.other
2: markup.bold.account
- match: ^(payee) ({{payee}})\s*$
captures:
1: keyword.other
2: markup.italic.desc
# Periodic transaction
- match: ^(~)\s(.*?)$
captures:
1: punctuation.section.period
2: constant.other.expression
# Automatic transaction
- match: ^(=)\s(.*?)$
captures:
1: punctuation.section.automated
2: string.regexp.expression
My problems:
- I don’t want to change the syntax each time a new person wants to use another date format.
- You can see in the file two matches which look pretty the same. Indeed, a star can be added in the entry line to tell the entry has been cleared (it appears on your account register). What I want is the entry to be highlighted if this is not cleared (I did not managed to do something better that telling that’s invalid. I should have a look to making a additional color map layer). Yet, this behavior is always desired.
Conclusion: I’d like to know if this is possible to create one or two varibles in the configuration file so that it impacts the syntax file in both cases.
Thanks for your help !