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

diff.lua (987B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Diff LPeg lexer.
  3. local lexer = lexer
  4. local to_eol, starts_line = lexer.to_eol, lexer.starts_line
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new(..., {lex_by_line = true})
  7. -- Text, file headers, and separators.
  8. lex:add_rule('index', lex:tag(lexer.COMMENT, to_eol(starts_line('Index: '))))
  9. lex:add_rule('header', lex:tag(lexer.HEADING, to_eol(starts_line(P('*** ') + '--- ' + '+++ '))))
  10. lex:add_rule('separator', lex:tag(lexer.COMMENT, to_eol(starts_line(P('---') + '****' + '='))))
  11. -- Location.
  12. lex:add_rule('location', lex:tag(lexer.NUMBER, to_eol(starts_line('@@' + lexer.dec_num + '****'))))
  13. -- Additions, deletions, and changes.
  14. lex:add_rule('addition', lex:tag('addition', to_eol(starts_line(S('>+')))))
  15. lex:add_rule('deletion', lex:tag('deletion', to_eol(starts_line(S('<-')))))
  16. lex:add_rule('change', lex:tag('change', to_eol(starts_line('!'))))
  17. lex:add_rule('any_line', lex:tag(lexer.DEFAULT, lexer.to_eol()))
  18. return lex