Skip to content

Commit

Permalink
Update Fennel lexer to include forms from latest version. (#1862)
Browse files Browse the repository at this point in the history
Treat true/false/nil as constants.

Also separate out declarations from other special forms and macros.
  • Loading branch information
technomancy committed Jul 18, 2021
1 parent 1ea5fc3 commit 727401e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
31 changes: 17 additions & 14 deletions pygments/lexers/lisp.py
Expand Up @@ -2631,23 +2631,22 @@ class FennelLexer(RegexLexer):
aliases = ['fennel', 'fnl']
filenames = ['*.fnl']

# these two lists are taken from fennel-mode.el:
# https://gitlab.com/technomancy/fennel-mode
# this list is current as of Fennel version 0.6.0.
# this list is current as of Fennel version 0.10.0.
special_forms = (
'require-macros', 'eval-compiler', 'doc', 'lua', 'hashfn',
'macro', 'macros', 'import-macros', 'pick-args', 'pick-values',
'macroexpand', 'macrodebug', 'do', 'values', 'if', 'when',
'each', 'for', 'fn', 'lambda', 'λ', 'partial', 'while',
'set', 'global', 'var', 'local', 'let', 'tset', 'set-forcibly!',
'doto', 'match', 'or', 'and', 'true', 'false', 'nil', 'not',
'not=', '.', '+', '..', '^', '-', '*', '%', '/', '>',
'<', '>=', '<=', '=', '...', ':', '->', '->>', '-?>',
'-?>>', 'rshift', 'lshift', 'bor', 'band', 'bnot', 'bxor',
'with-open', 'length'
'#', '%', '*', '+', '-', '->', '->>', '-?>', '-?>>', '.', '..',
'/', '//', ':', '<', '<=', '=', '>', '>=', '?.', '^', 'accumulate',
'and', 'band', 'bnot', 'bor', 'bxor', 'collect', 'comment', 'do', 'doc',
'doto', 'each', 'eval-compiler', 'for', 'hashfn', 'icollect', 'if',
'import-macros', 'include', 'length', 'let', 'lshift', 'lua',
'macrodebug', 'match', 'not', 'not=', 'or', 'partial', 'pick-args',
'pick-values', 'quote', 'require-macros', 'rshift', 'set',
'set-forcibly!', 'tset', 'values', 'when', 'while', 'with-open', '~='
)

declarations = (
'fn', 'global', 'lambda', 'local', 'macro', 'macros', 'var', 'λ'
)

# Might be nicer to use the list from _lua_builtins.py but it's unclear how?
builtins = (
'_G', '_VERSION', 'arg', 'assert', 'bit32', 'collectgarbage',
'coroutine', 'debug', 'dofile', 'error', 'getfenv',
Expand All @@ -2673,13 +2672,17 @@ class FennelLexer(RegexLexer):

(r'"(\\\\|\\[^\\]|[^"\\])*"', String),

(r'(true|false|nil)', Name.Constant),

# these are technically strings, but it's worth visually
# distinguishing them because their intent is different
# from regular strings.
(r':' + valid_name, String.Symbol),

# special forms are keywords
(words(special_forms, suffix=' '), Keyword),
# these are ... even more special!
(words(declarations, suffix=' '), Keyword.Declaration),
# lua standard library are builtins
(words(builtins, suffix=' '), Name.Builtin),
# special-case the vararg symbol
Expand Down
64 changes: 33 additions & 31 deletions tests/examplefiles/fennel/fennelview.fnl.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 727401e

Please sign in to comment.