logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

pkgbuild.lua (2904B)


  1. -- Copyright 2006-2024 gwash. See LICENSE.
  2. -- Archlinux PKGBUILD LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('pkgbuild')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Comments.
  10. lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
  11. -- Strings.
  12. local sq_str = lexer.range("'", false, false)
  13. local dq_str = lexer.range('"')
  14. local ex_str = lexer.range('`')
  15. local heredoc = '<<' * P(function(input, index)
  16. local s, e, _, delimiter = input:find('(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
  17. if s == index and delimiter then
  18. e = select(2, input:find('[\n\r\f]+' .. delimiter, e))
  19. return e and e + 1 or #input + 1
  20. end
  21. end)
  22. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + ex_str + heredoc))
  23. -- Numbers.
  24. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  25. -- Keywords.
  26. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
  27. 'patch', 'cd', 'make', 'patch', 'mkdir', 'cp', 'sed', 'install', 'rm', 'if', 'then', 'elif',
  28. 'else', 'fi', 'case', 'in', 'esac', 'while', 'for', 'do', 'done', 'continue', 'local', 'return',
  29. 'git', 'svn', 'co', 'clone', 'gconf-merge-schema', 'msg', 'echo', 'ln',
  30. -- Operators.
  31. '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-k', '-p', '-r', '-s', '-t', '-u', '-w', '-x',
  32. '-O', '-G', '-L', '-S', '-N', '-nt', '-ot', '-ef', '-o', '-z', '-n', '-eq', '-ne', '-lt', '-le',
  33. '-gt', '-ge', '-Np', '-i'
  34. }))
  35. -- Functions.
  36. lex:add_rule('function',
  37. token(lexer.FUNCTION, word_match('build check package pkgver prepare') * '()'))
  38. -- Constants.
  39. lex:add_rule('constant', token(lexer.CONSTANT, word_match{
  40. -- We do *not* list pkgver srcdir and startdir here.
  41. -- These are defined by makepkg but user should not alter them.
  42. 'arch', 'backup', 'changelog', 'checkdepends', 'conflicts', 'depends', 'epoch', 'groups',
  43. 'install', 'license', 'makedepends', 'md5sums', 'noextract', 'optdepends', 'options', 'pkgbase',
  44. 'pkgdesc', 'pkgname', 'pkgrel', 'pkgver', 'provides', 'replaces', 'sha1sums', 'sha256sums',
  45. 'sha384sums', 'sha512sums', 'source', 'url', 'validpgpkeys'
  46. }))
  47. -- Identifiers.
  48. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  49. -- Variables.
  50. local symbol = S('!#?*@$')
  51. local parens = lexer.range('(', ')', true)
  52. local brackets = lexer.range('[', ']', true)
  53. local braces = lexer.range('{', '}', true)
  54. local backticks = lexer.range('`', true, false)
  55. local number = lexer.dec_num
  56. lex:add_rule('variable', token(lexer.VARIABLE, '$' *
  57. (symbol + parens + brackets + braces + backticks + number + lexer.word)))
  58. -- Operators.
  59. lex:add_rule('operator', token(lexer.OPERATOR, S('=!<>+-/*^~.,:;?()[]{}')))
  60. -- Fold points.
  61. lex:add_fold_point(lexer.OPERATOR, '(', ')')
  62. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  63. lexer.property['scintillua.comment'] = '#'
  64. return lex