logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

vis-0.4_ebuild_lexer.patch (3557B)


  1. diff --git a/lua/lexers/ebuild.lua b/lua/lexers/ebuild.lua
  2. new file mode 100644
  3. index 0000000..9ecb7d8
  4. --- /dev/null
  5. +++ b/lua/lexers/ebuild.lua
  6. @@ -0,0 +1,87 @@
  7. +-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
  8. +-- Shell LPeg lexer.
  9. +
  10. +local l = require('lexer')
  11. +local token, word_match = l.token, l.word_match
  12. +local P, R, S = lpeg.P, lpeg.R, lpeg.S
  13. +
  14. +local M = {_NAME = 'ebuild'}
  15. +
  16. +-- Whitespace.
  17. +local ws = token(l.WHITESPACE, l.space^1)
  18. +
  19. +-- Comments.
  20. +local comment = token(l.COMMENT, '#' * l.nonnewline^0)
  21. +
  22. +-- Strings.
  23. +local sq_str = l.delimited_range("'", false, true)
  24. +local dq_str = l.delimited_range('"')
  25. +local ex_str = l.delimited_range('`')
  26. +local heredoc = '<<' * P(function(input, index)
  27. + local s, e, _, delimiter =
  28. + input:find('%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
  29. + if s == index and delimiter then
  30. + local _, e = input:find('[\n\r\f]+'..delimiter, e)
  31. + return e and e + 1 or #input + 1
  32. + end
  33. +end)
  34. +local string = token(l.STRING, sq_str + dq_str + ex_str + heredoc)
  35. +
  36. +-- Numbers.
  37. +local number = token(l.NUMBER, l.float + l.integer)
  38. +
  39. +-- Keywords.
  40. +local keyword = token(l.KEYWORD, word_match({
  41. + -- Bash keywords
  42. + 'if', 'then', 'elif', 'else', 'fi', 'case', 'in', 'esac', 'while', 'for',
  43. + 'do', 'done', 'continue', 'local', 'return', 'select',
  44. + -- Ebuild keywords
  45. + 'use', 'has_version', 'best_version', 'use_width', 'use_enable',
  46. + 'keepdir', 'econf', 'die', 'einstall', 'einfo', 'ewarn', 'eerror', 'diropts',
  47. + 'dobin', 'docinto', 'dodoc', 'doexe', 'doheader', 'doinfo', 'doins',
  48. + 'dolib', 'dolib.a', 'dolib.so', 'doman', 'dosbin', 'dosym', 'emake', 'exeinto',
  49. + 'exeopts', 'fowners', 'fperms', 'insinto', 'insopts', 'into', 'libopts', 'newbin',
  50. + 'newexe', 'newheader', 'newins', 'newman', 'newsbin', 'has', 'unpack', 'into',
  51. + 'doinitd', 'doconfd', 'doenvd', 'domo', 'dodir', 'ebegin', 'eend',
  52. + 'newconfd', 'newdoc', 'newenvd', 'newinitd', 'newlib.a', 'newlib.so',
  53. + 'hasv', 'usev', 'usex', 'elog', 'eapply', 'eapply_user',
  54. + 'einstalldocs', 'in_iuse', 'get_libdir',
  55. + 'addread', 'addwrite', 'adddeny', 'addpredict',
  56. + -- Operators.
  57. + '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-k', '-p', '-r', '-s', '-t',
  58. + '-u', '-w', '-x', '-O', '-G', '-L', '-S', '-N', '-nt', '-ot', '-ef', '-o',
  59. + '-z', '-n', '-eq', '-ne', '-lt', '-le', '-gt', '-ge'
  60. +}, '-'))
  61. +
  62. +-- Identifiers.
  63. +local identifier = token(l.IDENTIFIER, l.word)
  64. +
  65. +-- Variables.
  66. +local variable = token(l.VARIABLE,
  67. + '$' * (S('!#?*@$') + l.digit^1 + l.word +
  68. + l.delimited_range('{}', true, true, true)))
  69. +
  70. +-- Operators.
  71. +local operator = token(l.OPERATOR, S('=!<>+-/*^&|~.,:;?()[]{}'))
  72. +
  73. +M._rules = {
  74. + {'whitespace', ws},
  75. + {'keyword', keyword},
  76. + {'identifier', identifier},
  77. + {'string', string},
  78. + {'comment', comment},
  79. + {'number', number},
  80. + {'variable', variable},
  81. + {'operator', operator},
  82. +}
  83. +
  84. +M._foldsymbols = {
  85. + _patterns = {'[a-z]+', '[{}]', '#'},
  86. + [l.KEYWORD] = {
  87. + ['if'] = 1, fi = -1, case = 1, esac = -1, ['do'] = 1, done = -1
  88. + },
  89. + [l.OPERATOR] = {['{'] = 1, ['}'] = -1},
  90. + [l.COMMENT] = {['#'] = l.fold_line_comments('#')}
  91. +}
  92. +
  93. +return M
  94. diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua
  95. index 52eef25..539513f 100644
  96. --- a/lua/plugins/filetype.lua
  97. +++ b/lua/plugins/filetype.lua
  98. @@ -107,6 +107,9 @@ vis.ftdetect.filetypes = {
  99. dsv = {
  100. ext = { "group", "gshadow", "passwd", "shadow" },
  101. },
  102. + ebuild = {
  103. + ext = { "%.ebuild$" },
  104. + },
  105. eiffel = {
  106. ext = { "%.e$", "%.eif$" },
  107. },