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

output.lua (3903B)


  1. -- Copyright 2022-2024 Mitchell. See LICENSE.
  2. -- LPeg lexer for tool output.
  3. -- If a warning or error is recognized, tags its filename, line, column (if available),
  4. -- and message, and sets the line state to 1 for an error (first bit), and 2 for a warning
  5. -- (second bit).
  6. -- This is similar to Lexilla's errorlist lexer.
  7. local lexer = lexer
  8. local starts_line = lexer.starts_line
  9. local P, S = lpeg.P, lpeg.S
  10. local lex = lexer.new(..., {lex_by_line = true})
  11. -- Tags a pattern as plain text.
  12. local function text(patt) return lex:tag(lexer.DEFAULT, patt) end
  13. -- Tags a pattern as a filename.
  14. local function filename(patt) return lex:tag('filename', patt) end
  15. -- Typical line and column number patterns.
  16. local line = text('line ')^-1 * lex:tag('line', lexer.dec_num)
  17. local column = lex:tag('column', lexer.dec_num)
  18. -- Tags a pattern as an error/warning/etc. message.
  19. local function message(patt) return lex:tag('message', patt) end
  20. -- Immediately marks the current line as an error.
  21. -- This should only be specified at the end of a rule, or else LPeg may backtrack and mistakenly
  22. -- mark a non-error line.
  23. local function mark_error(_, pos)
  24. lexer.line_state[lexer.line_from_position(pos)] = 1
  25. return true
  26. end
  27. -- Immediately marks the current line as a warning.
  28. -- This should only be specified at the end of a rule, or else LPeg may backtrack and mistakenly
  29. -- mark a non-warning line.
  30. local function mark_warning(_, pos)
  31. lexer.line_state[lexer.line_from_position(pos)] = 2
  32. return true
  33. end
  34. -- filename:line: message (ruby)
  35. -- filename:line:col: message (c, cpp, go, ...)
  36. -- filename: line X: message (bash)
  37. local c_filename = filename((lexer.nonnewline - ':')^1)
  38. local colon = text(':' * P(' ')^-1)
  39. local warning = message(lexer.to_eol('warning: ')) * mark_warning
  40. local note = message(lexer.to_eol('note: ')) -- do not mark
  41. local error = message(lexer.to_eol()) * mark_error
  42. lex:add_rule('common', starts_line(c_filename) * colon * line * colon * (column * colon)^-1 *
  43. (warning + note + error))
  44. -- prog: filename:line: message (awk, lua)
  45. lex:add_rule('prog', starts_line(text(lexer.word)) * colon * c_filename * colon * line * colon *
  46. (warning + error))
  47. -- File "filename", line X (python)
  48. local py_filename = filename((lexer.nonnewline - '"')^1)
  49. lex:add_rule('python',
  50. starts_line(text('File "'), true) * py_filename * text('", ') * line * mark_error)
  51. -- filename(line): error: message (d, cuda)
  52. local lparen, rparen = text('('), text(')')
  53. local d_filename = filename((lexer.nonnewline - '(')^1)
  54. local d_error = message(lexer.to_eol(S('Ee') * 'rror')) * mark_error
  55. lex:add_rule('dmd', starts_line(d_filename) * lparen * line * rparen * colon * d_error)
  56. -- "filename" line X: message (gnuplot)
  57. local gp_filename = filename((lexer.nonnewline - '"')^1)
  58. lex:add_rule('gnuplot', starts_line(text('"')) * gp_filename * text('" ') * line * colon * error)
  59. -- at com.path(filename:line) (java)
  60. lex:add_rule('java',
  61. starts_line(text('at ' * (lexer.nonnewline - '(')^1), true) * lparen * c_filename * colon * line *
  62. rparen * mark_error)
  63. -- message in filename on line X (php)
  64. lex:add_rule('php', starts_line(message((lexer.nonnewline - ' in ')^1)) * text(' in ') *
  65. filename((lexer.nonnewline - ' on ')^1) * text(' on ') * line * mark_error)
  66. -- filename(line, col): message (vb, csharp, fsharp, ...)
  67. lex:add_rule('vb',
  68. starts_line(filename((lexer.nonnewline - '(')^1)) * lparen * line * text(', ') * column * rparen *
  69. colon * error)
  70. -- message at filename line X (perl)
  71. lex:add_rule('perl', starts_line(message((lexer.nonnewline - ' at ')^1)) * text(' at ') *
  72. filename((lexer.nonnewline - ' line ')^1) * text(' line ') * line * mark_error)
  73. -- CMake Error at filename:line: (cmake)
  74. lex:add_rule('cmake',
  75. starts_line(text('CMake Error at ')) * c_filename * colon * line * colon * mark_error)
  76. lex:add_rule('any_line', lex:tag(lexer.DEFAULT, lexer.to_eol()))
  77. return lex