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

mediawiki.lua (1750B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- MediaWiki LPeg lexer.
  3. -- Contributed by Alexander Misel.
  4. local lexer = require('lexer')
  5. local token, word_match = lexer.token, lexer.word_match
  6. local P, S, B = lpeg.P, lpeg.S, lpeg.B
  7. local lex = lexer.new('mediawiki')
  8. -- Comments.
  9. lex:add_rule('comment', token(lexer.COMMENT, lexer.range('<!--', '-->')))
  10. -- HTML-like tags
  11. local tag_start = token(lexer.TAG, '<' * P('/')^-1 * lexer.alnum^1 * lexer.space^0)
  12. local dq_str = '"' * ((lexer.any - S('>"\\')) + ('\\' * lexer.any))^0 * '"'
  13. local tag_attr = token(lexer.ATTRIBUTE, lexer.alpha^1 * lexer.space^0 *
  14. ('=' * lexer.space^0 * (dq_str + (lexer.any - lexer.space - '>')^0)^-1)^0 * lexer.space^0)
  15. local tag_end = token(lexer.TAG, P('/')^-1 * '>')
  16. lex:add_rule('tag', tag_start * tag_attr^0 * tag_end)
  17. -- Link
  18. lex:add_rule('link', token(lexer.STRING, S('[]')))
  19. lex:add_rule('internal_link', B('[[') * token(lexer.LINK, (lexer.any - '|' - ']]')^1))
  20. -- Templates and parser functions.
  21. lex:add_rule('template', token(lexer.OPERATOR, S('{}')))
  22. lex:add_rule('parser_func',
  23. B('{{') * token(lexer.FUNCTION, '#' * lexer.alpha^1 + lexer.upper^1 * ':'))
  24. lex:add_rule('template_name', B('{{') * token(lexer.LINK, (lexer.any - S('{}|'))^1))
  25. -- Operators.
  26. lex:add_rule('operator', token(lexer.OPERATOR, S('-=|#~!')))
  27. -- Behavior switches
  28. local start_pat = P(function(_, pos) return pos == 1 end)
  29. lex:add_rule('behavior_switch', (B(lexer.space) + start_pat) * token('behavior_switch', word_match(
  30. '__TOC__ __FORCETOC__ __NOTOC__ __NOEDITSECTION__ __NOCC__ __NOINDEX__')) * #lexer.space)
  31. lex:add_style('behavior_switch', lexer.styles.keyword)
  32. lexer.property['scintillua.comment'] = '<!--|-->'
  33. lexer.property['scintillua.angle.braces'] = '1'
  34. return lex