updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / textadept / pkgbuild.lua
blobb61ebbdad645f19e3a0b65f077554d2138b9b946
1 local l = lexer
2 local token, style, color, word_match = l.token, l.style, l.color, l.word_match
3 local P, R, S = l.lpeg.P, l.lpeg.R, l.lpeg.S
5 module(...)
7 local ws = token('whitespace', l.space^1)
9 -- comments
10 local comment = token('comment', '#' * l.nonnewline^0)
12 -- strings
13 local sq_str = l.delimited_range("'", nil, true)
14 local dq_str = l.delimited_range('"', '\\', true)
15 local ex_str = l.delimited_range('`', '\\', true)
16 local heredoc = '<<' * P(function(input, index)
17 local s, e, _, delimiter = input:find('(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
18 if s == index and delimiter then
19 local _, e = input:find('[\n\r\f]+'..delimiter, e)
20 return e and e + 1 or #input + 1
21 end
22 end)
23 local string = token('string', sq_str + dq_str + ex_str + heredoc)
25 -- numbers
26 local number = token('number', l.float + l.integer)
28 -- keywords
29 local keyword = token('keyword', word_match({
30 'patch', 'cd', 'make', 'patch', 'mkdir', 'cp', 'sed', 'install', 'rm',
31 'if', 'then', 'elif', 'else', 'fi', 'case', 'in', 'esac', 'while', 'for',
32 'do', 'done', 'continue', 'local', 'return', 'git', 'svn', 'co', 'clone',
33 'gconf-merge-schema', 'msg', 'echo', 'ln',
34 -- operators
35 '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-k', '-p', '-r', '-s', '-t',
36 '-u', '-w', '-x', '-O', '-G', '-L', '-S', '-N', '-nt', '-ot', '-ef', '-o',
37 '-z', '-n', '-eq', '-ne', '-lt', '-le', '-gt', '-ge', '-i', '-sf'
38 }, '-'))
40 -- functions
41 local func = token('function', word_match {
42 'build', 'package', 'pre_install', 'post_install', 'pre_upgrade', 'post_upgrade', 'pre_remove',
43 'post_remove'
46 -- constants
47 local constant = token('constant', word_match {
48 'pkgname', 'pkgbase', 'pkgver', 'pkgrel', 'pkgdesc', 'arch', 'url',
49 'license', 'optdepends', 'depends', 'makedepends', 'provides',
50 'conflicts', 'replaces', 'options', 'install', 'source', 'md5sums',
51 'pkgdir', 'srcdir'
54 -- identifiers
55 local identifier = token('identifier', l.word)
57 -- variables
58 local variable = token('variable', '$' * (S('!#?*@$') +
59 l.delimited_range('()', nil, true, false, '\n') +
60 l.delimited_range('[]', nil, true, false, '\n') +
61 l.delimited_range('{}', nil, true, false, '\n') +
62 l.delimited_range('`', nil, true, false, '\n') +
63 l.digit^1 +
64 l.word))
66 -- operators
67 local operator = token('operator', S('=!<>+-/*^~.,:;?()[]{}'))
69 _rules = {
70 { 'whitespace', ws },
71 { 'keyword', keyword },
72 { 'function', func },
73 { 'constant', constant },
74 { 'identifier', identifier },
75 { 'string', string },
76 { 'comment', comment },
77 { 'number', number },
78 { 'variable', variable },
79 { 'operator', operator },
80 { 'any_char', l.any_char },