diff options
author | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
commit | 519b7328b66c4c84f03893a31e4be5ba6b1395f2 (patch) | |
tree | 2055cd79006357e94c185f341d0df17b9a8769eb /lexlua/django.lua | |
parent | c0373e036e965a70045971e2abc582cb4bf12a4e (diff) | |
download | scintilla-mirror-519b7328b66c4c84f03893a31e4be5ba6b1395f2.tar.gz |
Added optional Lua lexer support.
This support is disabled by default and must be enabled via compile-time option.
Diffstat (limited to 'lexlua/django.lua')
-rw-r--r-- | lexlua/django.lua | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lexlua/django.lua b/lexlua/django.lua new file mode 100644 index 000000000..88406e1f8 --- /dev/null +++ b/lexlua/django.lua @@ -0,0 +1,55 @@ +-- Copyright 2006-2018 Mitchell mitchell.att.foicica.com. See License.txt. +-- Django LPeg lexer. + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('django') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ + as block blocktrans by endblock endblocktrans comment endcomment cycle date + debug else extends filter endfilter firstof for endfor if endif ifchanged + endifchanged ifnotequal endifnotequal in load not now or parsed regroup ssi + trans with widthratio +]])) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match[[ + add addslashes capfirst center cut date default dictsort dictsortreversed + divisibleby escape filesizeformat first fix_ampersands floatformat get_digit + join length length_is linebreaks linebreaksbr linenumbers ljust lower + make_list phone2numeric pluralize pprint random removetags rjust slice slugify + stringformat striptags time timesince title truncatewords unordered_list upper + urlencode urlize urlizetrunc wordcount wordwrap yesno +]])) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, + lexer.delimited_range('"', false, true))) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S(':,.|'))) + +-- Embed Django in HTML. +local html = lexer.load('html') +local html_comment = '<!--' * (lexer.any - '-->')^0 * P('-->')^-1 +local django_comment = '{#' * (lexer.any - lexer.newline - '#}')^0 * P('#}')^-1 +html:modify_rule('comment', token(lexer.COMMENT, html_comment + django_comment)) +local django_start_rule = token('django_tag', '{' * S('{%')) +local django_end_rule = token('django_tag', S('%}') * '}') +html:embed(lex, django_start_rule, django_end_rule) +lex:add_style('django_tag', lexer.STYLE_EMBEDDED) + +-- Fold points. +lex:add_fold_point('django_tag', '{{', '}}') +lex:add_fold_point('django_tag', '{%', '%}') + +return lex |