aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/django.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-11 01:27:32 +0200
committerRandy Palamar <randy@rnpnr.xyz>2024-03-27 06:04:21 -0600
commit4c4392d29df777ff702dfe99b4f3c23142976e05 (patch)
tree5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/django.lua
parent95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff)
downloadvis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz
vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab everything as is.
Diffstat (limited to 'lua/lexers/django.lua')
-rw-r--r--lua/lexers/django.lua74
1 files changed, 41 insertions, 33 deletions
diff --git a/lua/lexers/django.lua b/lua/lexers/django.lua
index 2147853..75b2d28 100644
--- a/lua/lexers/django.lua
+++ b/lua/lexers/django.lua
@@ -1,55 +1,63 @@
--- Copyright 2006-2022 Mitchell. See LICENSE.
+-- Copyright 2006-2024 Mitchell. See LICENSE.
-- Django LPeg lexer.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
+local lexer = lexer
local P, S = lpeg.P, lpeg.S
-local lex = lexer.new('django')
-
--- Whitespace.
-lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+local lex = lexer.new(...)
-- 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'
-}))
+lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
-- 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'
-}))
+lex:add_rule('function',
+ lpeg.B('|') * lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)))
-- Identifiers.
-lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
+lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
-- Strings.
-lex:add_rule('string', token(lexer.STRING, lexer.range('"', false, false)))
+lex:add_rule('string', lex:tag(lexer.STRING, lexer.range('"', false, false)))
-- Operators.
-lex:add_rule('operator', token(lexer.OPERATOR, S(':,.|')))
+lex:add_rule('operator', lex:tag(lexer.OPERATOR, S(':,.|')))
-- Embed Django in HTML.
local html = lexer.load('html')
-local html_comment = lexer.range('<!--', '-->')
-local django_comment = lexer.range('{#', '#}', true)
-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:add_rule('django_comment', lex:tag(lexer.COMMENT, lexer.range('{#', '#}', true)))
+local django_start_rule = lex:tag(lexer.PREPROCESSOR, '{' * S('{%'))
+local django_end_rule = lex:tag(lexer.PREPROCESSOR, S('%}') * '}')
html:embed(lex, django_start_rule, django_end_rule)
-lex:add_style('django_tag', lexer.styles.embedded)
-- Fold points.
-lex:add_fold_point('django_tag', '{{', '}}')
-lex:add_fold_point('django_tag', '{%', '%}')
+lex:add_fold_point(lexer.PREPROCESSOR, '{{', '}}')
+lex:add_fold_point(lexer.PREPROCESSOR, '{%', '%}')
+
+-- Word lists.
+lex:set_word_list(lexer.KEYWORD, {
+ 'autoescape', 'endautoescape', 'block', 'endblock', 'comment', 'endcomment', 'csrf_token',
+ 'cycle', 'as', 'debug', 'extends', 'filter', 'endfilter', 'firstof', 'for', 'in', 'endfor',
+ 'empty', 'if', 'elif', 'else', 'endif', 'and', 'or', 'not', 'is', 'ifchanged', 'endifchanged',
+ 'include', 'load', 'lorem', 'now', 'regroup', 'resetcycle', 'spaceless', 'endspaceless',
+ 'templatetag', 'url', 'verbatim', 'endverbatim', 'widthratio', 'with', 'endwith', --
+ 'blocktranslate', 'endblocktranslate', 'translate', 'language', 'get_available_languages',
+ 'get_current_language', 'get_current_language_bidi', 'get_language_info',
+ 'get_language_info_list', --
+ 'get_static_prefix', 'get_media_prefix'
+})
+
+lex:set_word_list(lexer.FUNCTION_BUILTIN, {
+ 'add', 'addslashes', 'capfirst', 'center', 'cut', 'date', 'default', 'default_if_none',
+ 'dictsort', 'dictsortreversed', 'divisibleby', 'escape', 'escapejs', 'filesizeformat', 'first',
+ 'floatformat', 'force_escape', 'get_digit', 'iriencode', 'join', 'json_script', 'last', 'length',
+ 'length_is', 'linebreaks', 'linebreaksbr', 'linenumbers', 'ljust', 'lower', 'make_list',
+ 'phone2numeric', 'pluralize', 'pprint', 'random', 'rjust', 'safe', 'safeseq', 'slice', 'slugify',
+ 'stringformat', 'striptags', 'time', 'timesince', 'timeuntil', 'title', 'truncatechars_html',
+ 'truncatewords', 'truncatewords_html', 'unordered_list', 'upper', 'urlencode', 'urlize',
+ 'urlizetrunc', 'wordcount', 'wordwrap', 'yesno', --
+ 'language_name', 'language_name_local', 'language_bidi', 'language_name_translated'
+})
+
+lexer.property['scintillua.comment'] = '{#|#}'
return lex