local lexer = require('lexer') local token, word_match = lexer.token, lexer.word_match local P, S, B = lpeg.P, lpeg.S, lpeg.B local lex = lexer.new('asciidoc') -- AsciiDoc blocks: ==== and ---- local adoc_block = lexer.range('====', '====', true, true, true) + lexer.range('----', '----', true, true, true) lex:add_rule('block', token(lexer.PREPROCESSOR, lexer.range('====', '====', true, true, true) + lexer.range('----', '----', true, true, true))) --lex:add_rule('block', token(lexer.EMPH, adoc_block)) -- Block: ---- must match full line --lex:add_rule('block', token(lexer.EMPH, P('----') * P('\n') * (lexer.any - P('----'))^0 * P('----'))) -- Headers: Must be at start of line lex:add_rule('header', token(lexer.KEYWORD, B('\n')^-1 * P('=')^1 * ' ' * lexer.nonnewline^1)) -- Bold: Prevent overlap with other syntax lex:add_rule('bold', token(lexer.BOLD, P('*') * (lexer.any - S('*\n'))^1 * P('*'))) -- Italic lex:add_rule('italic', token(lexer.ITALIC, P('_') * (lexer.any - S('_\n'))^1 * P('_'))) -- Links lex:add_rule('link', token(lexer.CONSTANT, 'https?://' * lexer.nonnewline^1)) -- Comments lex:add_rule('comment', token(lexer.COMMENT, P('//') * lexer.nonnewline^0)) -- Identifier (last) lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) return lex