Server IP : 85.214.239.14 / Your IP : 3.138.137.244 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/proc/2/cwd/proc/self/root/lib/python3/dist-packages/pygments/lexers/ |
Upload File : |
""" pygments.lexers.nix ~~~~~~~~~~~~~~~~~~~ Lexers for the NixOS Nix language. :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re from pygments.lexer import RegexLexer, include from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Literal __all__ = ['NixLexer'] class NixLexer(RegexLexer): """ For the Nix language. .. versionadded:: 2.0 """ name = 'Nix' url = 'http://nixos.org/nix/' aliases = ['nixos', 'nix'] filenames = ['*.nix'] mimetypes = ['text/x-nix'] keywords = ['rec', 'with', 'let', 'in', 'inherit', 'assert', 'if', 'else', 'then', '...'] builtins = ['import', 'abort', 'baseNameOf', 'dirOf', 'isNull', 'builtins', 'map', 'removeAttrs', 'throw', 'toString', 'derivation'] operators = ['++', '+', '?', '.', '!', '//', '==', '!=', '&&', '||', '->', '='] punctuations = ["(", ")", "[", "]", ";", "{", "}", ":", ",", "@"] tokens = { 'root': [ # comments starting with # (r'#.*$', Comment.Single), # multiline comments (r'/\*', Comment.Multiline, 'comment'), # whitespace (r'\s+', Text), # keywords ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in keywords), Keyword), # highlight the builtins ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in builtins), Name.Builtin), (r'\b(true|false|null)\b', Name.Constant), # operators ('(%s)' % '|'.join(re.escape(entry) for entry in operators), Operator), # word operators (r'\b(or|and)\b', Operator.Word), # punctuations ('(%s)' % '|'.join(re.escape(entry) for entry in punctuations), Punctuation), # integers (r'[0-9]+', Number.Integer), # strings (r'"', String.Double, 'doublequote'), (r"''", String.Single, 'singlequote'), # paths (r'[\w.+-]*(\/[\w.+-]+)+', Literal), (r'\<[\w.+-]+(\/[\w.+-]+)*\>', Literal), # urls (r'[a-zA-Z][a-zA-Z0-9\+\-\.]*\:[\w%/?:@&=+$,\\.!~*\'-]+', Literal), # names of variables (r'[\w-]+\s*=', String.Symbol), (r'[a-zA-Z_][\w\'-]*', Text), ], 'comment': [ (r'[^/*]+', Comment.Multiline), (r'/\*', Comment.Multiline, '#push'), (r'\*/', Comment.Multiline, '#pop'), (r'[*/]', Comment.Multiline), ], 'singlequote': [ (r"'''", String.Escape), (r"''\$\{", String.Escape), (r"''\n", String.Escape), (r"''\r", String.Escape), (r"''\t", String.Escape), (r"''", String.Single, '#pop'), (r'\$\{', String.Interpol, 'antiquote'), (r"['$]", String.Single), (r"[^'$]+", String.Single), ], 'doublequote': [ (r'\\', String.Escape), (r'\\"', String.Escape), (r'\\$\{', String.Escape), (r'"', String.Double, '#pop'), (r'\$\{', String.Interpol, 'antiquote'), (r'[^"]', String.Double), ], 'antiquote': [ (r"\}", String.Interpol, '#pop'), # TODO: we should probably escape also here ''${ \${ (r"\$\{", String.Interpol, '#push'), include('root'), ], } def analyse_text(text): rv = 0.0 # TODO: let/in if re.search(r'import.+?<[^>]+>', text): rv += 0.4 if re.search(r'mkDerivation\s+(\(|\{|rec)', text): rv += 0.4 if re.search(r'=\s+mkIf\s+', text): rv += 0.4 if re.search(r'\{[a-zA-Z,\s]+\}:', text): rv += 0.1 return rv