diff options
author | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
commit | 519b7328b66c4c84f03893a31e4be5ba6b1395f2 (patch) | |
tree | 2055cd79006357e94c185f341d0df17b9a8769eb /lexlua/ledger.lua | |
parent | c0373e036e965a70045971e2abc582cb4bf12a4e (diff) | |
download | scintilla-mirror-519b7328b66c4c84f03893a31e4be5ba6b1395f2.tar.gz |
Added optional Lua lexer support.
This support is disabled by default and must be enabled via compile-time option.
Diffstat (limited to 'lexlua/ledger.lua')
-rw-r--r-- | lexlua/ledger.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lexlua/ledger.lua b/lexlua/ledger.lua new file mode 100644 index 000000000..a697a6d8b --- /dev/null +++ b/lexlua/ledger.lua @@ -0,0 +1,48 @@ +-- Copyright 2015-2018 Charles Lehner. See License.txt. +-- ledger journal LPeg lexer, see http://www.ledger-cli.org/ + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('ledger', {lex_by_line = true}) + +local delim = P('\t') + P(' ') + +-- Account. +lex:add_rule('account', token(lexer.VARIABLE, + lexer.starts_line(S(' \t')^1 * + (lexer.print - delim)^1))) + +-- Amount. +lex:add_rule('amount', token(lexer.NUMBER, delim * (1 - S(';\r\n'))^1)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, S(';#') * lexer.nonnewline^0)) + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Strings. +local sq_str = lexer.delimited_range("'") +local dq_str = lexer.delimited_range('"') +local label = lexer.delimited_range('[]', true, true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + label)) + +-- Date. +lex:add_rule('date', token(lexer.CONSTANT, + lexer.starts_line((lexer.digit + S('/-'))^1))) + +-- Automated transactions. +lex:add_rule('auto_tx', token(lexer.PREPROCESSOR, + lexer.starts_line(S('=~') * lexer.nonnewline^0))) + +-- Directives. +local directive_word = word_match[[ + account alias assert bucket capture check comment commodity define end fixed + endfixed include payee apply tag test year +]] + S('AYNDCIiOobh') +lex:add_rule('directive', token(lexer.KEYWORD, + lexer.starts_line(S('!@')^-1 * directive_word))) + +return lex |