From e54caf087cecda02b625b5d5d51c667746002a3e Mon Sep 17 00:00:00 2001 From: orbitalquark <70453897+orbitalquark@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:42:10 -0400 Subject: Rename 'ansi_c', 'dmd', and 'rstats' lexers to 'c', 'd', and 'r' Originally this was to prevent clashes with Textadept's language-specific key handling, but this is no longer applicable. --- lua/lexers/ansi_c.lua | 213 -------------------------------------------------- lua/lexers/c.lua | 213 ++++++++++++++++++++++++++++++++++++++++++++++++++ lua/lexers/d.lua | 141 +++++++++++++++++++++++++++++++++ lua/lexers/dmd.lua | 141 --------------------------------- lua/lexers/glsl.lua | 2 +- lua/lexers/lexer.lua | 12 +-- lua/lexers/output.lua | 2 +- lua/lexers/r.lua | 52 ++++++++++++ lua/lexers/rstats.lua | 52 ------------ 9 files changed, 412 insertions(+), 416 deletions(-) delete mode 100644 lua/lexers/ansi_c.lua create mode 100644 lua/lexers/c.lua create mode 100644 lua/lexers/d.lua delete mode 100644 lua/lexers/dmd.lua create mode 100644 lua/lexers/r.lua delete mode 100644 lua/lexers/rstats.lua (limited to 'lua/lexers') diff --git a/lua/lexers/ansi_c.lua b/lua/lexers/ansi_c.lua deleted file mode 100644 index eacae09..0000000 --- a/lua/lexers/ansi_c.lua +++ /dev/null @@ -1,213 +0,0 @@ --- Copyright 2006-2024 Mitchell. See LICENSE. --- C LPeg lexer. - -local lexer = lexer -local P, S, B = lpeg.P, lpeg.S, lpeg.B - -local lex = lexer.new(...) - --- Keywords. -lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) - --- Types. -lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE))) - --- Functions. -local builtin_func = -(B('.') + B('->')) * - lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)) -local func = lex:tag(lexer.FUNCTION, lexer.word) -local method = (B('.') + B('->')) * lex:tag(lexer.FUNCTION_METHOD, lexer.word) -lex:add_rule('function', (builtin_func + method + func) * #(lexer.space^0 * '(')) - --- Constants. -lex:add_rule('constants', lex:tag(lexer.CONSTANT_BUILTIN, - -(B('.') + B('->')) * lex:word_match(lexer.CONSTANT_BUILTIN))) - --- Labels. -lex:add_rule('label', lex:tag(lexer.LABEL, lexer.starts_line(lexer.word * ':'))) - --- Strings. -local sq_str = lexer.range("'", true) -local dq_str = lexer.range('"', true) -lex:add_rule('string', lex:tag(lexer.STRING, P('L')^-1 * (sq_str + dq_str))) - --- Identifiers. -lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) - --- Comments. -local line_comment = lexer.to_eol('//', true) -local ws = S(' \t')^0 -local block_comment = lexer.range('/*', '*/') + - lexer.range('#if' * ws * '0' * lexer.space, '#endif') -lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment)) - --- Numbers. -local integer = lexer.integer * lexer.word_match('u l ll ul ull lu llu', true)^-1 -local float = lexer.float * P('f')^-1 -lex:add_rule('number', lex:tag(lexer.NUMBER, float + integer)) - --- Preprocessor. -local include = lex:tag(lexer.PREPROCESSOR, '#' * ws * 'include') * - (lex:get_rule('whitespace') * lex:tag(lexer.STRING, lexer.range('<', '>', true)))^-1 -local preproc = lex:tag(lexer.PREPROCESSOR, '#' * ws * lex:word_match(lexer.PREPROCESSOR)) -lex:add_rule('preprocessor', include + preproc) - --- Attributes. -local standard_attr = lex:word_match(lexer.ATTRIBUTE) -local non_standard_attr = lexer.word * '::' * lexer.word -local attr_args = lexer.range('(', ')') -local attr = (non_standard_attr + standard_attr) * attr_args^-1 -lex:add_rule('attribute', lex:tag(lexer.ATTRIBUTE, '[[' * attr * (ws * ',' * ws * attr)^0 * ']]')) - --- Operators. -lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))) - --- Fold points. -lex:add_fold_point(lexer.PREPROCESSOR, '#if', '#endif') -lex:add_fold_point(lexer.PREPROCESSOR, '#ifdef', '#endif') -lex:add_fold_point(lexer.PREPROCESSOR, '#ifndef', '#endif') -lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '/*', '*/') - --- Word lists. -lex:set_word_list(lexer.KEYWORD, { - 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', - 'goto', 'if', 'inline', 'register', 'restrict', 'return', 'sizeof', 'static', 'switch', 'typedef', - 'volatile', 'while', -- - 'false', 'true', -- C99 - 'alignas', 'alignof', '_Atomic', '_Generic', 'noreturn', '_Static_assert', 'thread_local', -- C11 - -- Compiler. - 'asm', '__asm', '__asm__', '__restrict__', '__inline', '__inline__', '__attribute__', '__declspec' -}) - -lex:set_word_list(lexer.TYPE, { - 'bool', 'char', 'double', 'float', 'int', 'long', 'short', 'signed', 'struct', 'union', - 'unsigned', 'void', -- - 'complex', 'imaginary', '_Complex', '_Imaginary', -- complex.h C99 - 'lconv', -- locale.h - 'div_t', -- math.h - 'va_list', -- stdarg.h - 'bool', '_Bool', -- stdbool.h C99 - -- stddef.h. - 'size_t', 'ptrdiff_t', -- - 'max_align_t', -- C11 - -- stdint.h. - 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', - 'int_fast64_t', 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t', 'intmax_t', - 'intptr_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint_fast8_t', 'uint_fast16_t', - 'uint_fast32_t', 'uint_fast64_t', 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', - 'uint_least64_t', 'uintmax_t', 'uintptr_t', -- - 'FILE', 'fpos_t', -- stdio.h - 'div_t', 'ldiv_t', -- stdlib.h - -- time.h. - 'tm', 'time_t', 'clock_t', -- - 'timespec' -- C11 -}) - -lex:set_word_list(lexer.FUNCTION_BUILTIN, { - 'assert', -- assert.h - -- complex.h. - 'CMPLX', 'creal', 'cimag', 'cabs', 'carg', 'conj', 'cproj', - -- C99 - 'cexp', 'cpow', 'csin', 'ccos', 'ctan', 'casin', 'cacos', 'catan', 'csinh', 'ccosh', 'ctanh', - 'casinh', 'cacosh', 'catanh', - -- ctype.h. - 'isalnum', 'isalpha', 'islower', 'isupper', 'isdigit', 'isxdigit', 'iscntrl', 'isgraph', - 'isspace', 'isprint', 'ispunct', 'tolower', 'toupper', -- - 'isblank', -- C99 - -- inttypes.h. - 'INT8_C', 'INT16_C', 'INT32_C', 'INT64_C', 'INTMAX_C', 'UINT8_C', 'UINT16_C', 'UINT32_C', - 'UINT64_C', 'UINTMAX_C', -- - 'setlocale', 'localeconv', -- locale.h - -- math.h. - 'abs', 'div', 'fabs', 'fmod', 'exp', 'log', 'log10', 'pow', 'sqrt', 'sin', 'cos', 'tan', 'asin', - 'acos', 'atan', 'atan2', 'sinh', 'cosh', 'tanh', 'ceil', 'floor', 'frexp', 'ldexp', 'modf', - -- C99. - 'remainder', 'remquo', 'fma', 'fmax', 'fmin', 'fdim', 'nan', 'exp2', 'expm1', 'log2', 'log1p', - 'cbrt', 'hypot', 'asinh', 'acosh', 'atanh', 'erf', 'erfc', 'tgamma', 'lgamma', 'trunc', 'round', - 'nearbyint', 'rint', 'scalbn', 'ilogb', 'logb', 'nextafter', 'nexttoward', 'copysign', 'isfinite', - 'isinf', 'isnan', 'isnormal', 'signbit', 'isgreater', 'isgreaterequal', 'isless', 'islessequal', - 'islessgreater', 'isunordered', -- - 'strtoimax', 'strtoumax', -- inttypes.h C99 - 'signal', 'raise', -- signal.h - 'setjmp', 'longjmp', -- setjmp.h - 'va_start', 'va_arg', 'va_end', -- stdarg.h - -- stdio.h. - 'fopen', 'freopen', 'fclose', 'fflush', 'setbuf', 'setvbuf', 'fwide', 'fread', 'fwrite', 'fgetc', - 'getc', 'fgets', 'fputc', 'putc', 'getchar', 'gets', 'putchar', 'puts', 'ungetc', 'scanf', - 'fscanf', 'sscanf', 'printf', 'fprintf', 'sprintf', 'vprintf', 'vfprintf', 'vsprintf', 'ftell', - 'fgetpos', 'fseek', 'fsetpos', 'rewind', 'clearerr', 'feof', 'ferror', 'perror', 'remove', - 'rename', 'tmpfile', 'tmpnam', - -- stdlib.h. - 'abort', 'exit', 'atexit', 'system', 'getenv', 'malloc', 'calloc', 'realloc', 'free', 'atof', - 'atoi', 'atol', 'strtol', 'strtoul', 'strtod', 'mblen', 'mbsinit', 'mbrlen', 'qsort', 'bsearch', - 'rand', 'srand', -- - 'quick_exit', '_Exit', 'at_quick_exit', 'aligned_alloc', -- C11 - -- string.h. - 'strcpy', 'strncpy', 'strcat', 'strncat', 'strxfrm', 'strlen', 'strcmp', 'strncmp', 'strcoll', - 'strchr', 'strrchr', 'strspn', 'strcspn', 'strpbrk', 'strstr', 'strtok', 'memchr', 'memcmp', - 'memset', 'memcpy', 'memmove', 'strerror', - -- time.h. - 'difftime', 'time', 'clock', 'asctime', 'ctime', 'gmtime', 'localtime', 'mktime', -- - 'timespec_get' -- C11 -}) - -lex:set_word_list(lexer.CONSTANT_BUILTIN, { - 'NULL', -- - '__DATE__', '__FILE__', '__LINE__', '__TIME__', '__func__', -- preprocessor - -- errno.h. - 'errno', -- - 'E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADF', - 'EBADMSG', 'EBUSY', 'ECANCELED', 'ECHILD', 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', - 'EDEADLK', 'EDESTADDRREQ', 'EDOM', 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTUNREACH', 'EIDRM', - 'EILSEQ', 'EINPROGRESS', 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', 'ELOOP', 'EMFILE', - 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', - 'ENFILE', 'ENOBUFS', 'ENODATA', 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', 'ENOMEM', - 'ENOMSG', 'ENOPROTOOPT', 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTCONN', 'ENOTDIR', - 'ENOTEMPTY', 'ENOTRECOVERABLE', 'ENOTSOCK', 'ENOTSUP', 'ENOTTY', 'ENXIO', 'EOPNOTSUPP', - 'EOVERFLOW', 'EOWNERDEAD', 'EPERM', 'EPIPE', 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', 'ERANGE', - 'EROFS', 'ESPIPE', 'ESRCH', 'ESTALE', 'ETIME', 'ETIMEDOUT', 'ETXTBSY', 'EWOULDBLOCK', 'EXDEV', - -- float.h. - 'FLT_MIN', 'DBL_MIN', 'LDBL_MIN', 'FLT_MAX', 'DBL_MAX', 'LDBL_MAX', - -- limits.h. - 'CHAR_BIT', 'MB_LEN_MAX', 'CHAR_MIN', 'CHAR_MAX', 'SCHAR_MIN', 'SHRT_MIN', 'INT_MIN', 'LONG_MIN', - 'SCHAR_MAX', 'SHRT_MAX', 'INT_MAX', 'LONG_MAX', 'UCHAR_MAX', 'USHRT_MAX', 'UINT_MAX', 'ULONG_MAX', - -- C99. - 'LLONG_MIN', 'ULLONG_MAX', 'PTRDIFF_MIN', 'PTRDIFF_MAX', 'SIZE_MAX', 'SIG_ATOMIC_MIN', - 'SIG_ATOMIC_MAX', 'WINT_MIN', 'WINT_MAX', 'WCHAR_MIN', 'WCHAR_MAX', -- - 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', -- locale.h - -- math.h. - 'HUGE_VAL', -- - 'INFINITY', 'NAN', -- C99 - -- stdint.h. - 'INT8_MIN', 'INT16_MIN', 'INT32_MIN', 'INT64_MIN', 'INT_FAST8_MIN', 'INT_FAST16_MIN', - 'INT_FAST32_MIN', 'INT_FAST64_MIN', 'INT_LEAST8_MIN', 'INT_LEAST16_MIN', 'INT_LEAST32_MIN', - 'INT_LEAST64_MIN', 'INTPTR_MIN', 'INTMAX_MIN', 'INT8_MAX', 'INT16_MAX', 'INT32_MAX', 'INT64_MAX', - 'INT_FAST8_MAX', 'INT_FAST16_MAX', 'INT_FAST32_MAX', 'INT_FAST64_MAX', 'INT_LEAST8_MAX', - 'INT_LEAST16_MAX', 'INT_LEAST32_MAX', 'INT_LEAST64_MAX', 'INTPTR_MAX', 'INTMAX_MAX', 'UINT8_MAX', - 'UINT16_MAX', 'UINT32_MAX', 'UINT64_MAX', 'UINT_FAST8_MAX', 'UINT_FAST16_MAX', 'UINT_FAST32_MAX', - 'UINT_FAST64_MAX', 'UINT_LEAST8_MAX', 'UINT_LEAST16_MAX', 'UINT_LEAST32_MAX', 'UINT_LEAST64_MAX', - 'UINTPTR_MAX', 'UINTMAX_MAX', - -- stdio.h - 'stdin', 'stdout', 'stderr', 'EOF', 'FOPEN_MAX', 'FILENAME_MAX', 'BUFSIZ', '_IOFBF', '_IOLBF', - '_IONBF', 'SEEK_SET', 'SEEK_CUR', 'SEEK_END', 'TMP_MAX', -- - 'EXIT_SUCCESS', 'EXIT_FAILURE', 'RAND_MAX', -- stdlib.h - -- signal.h. - 'SIG_DFL', 'SIG_IGN', 'SIG_ERR', 'SIGABRT', 'SIGFPE', 'SIGILL', 'SIGINT', 'SIGSEGV', 'SIGTERM', -- - 'CLOCKS_PER_SEC' -- time.h. -}) - -lex:set_word_list(lexer.PREPROCESSOR, { - 'define', 'defined', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'line', 'pragma', - 'undef' -}) - -lex:set_word_list(lexer.ATTRIBUTE, { - -- C23 - 'deprecated', 'fallthrough', 'nodiscard', 'maybe_unused', 'noreturn', '_Noreturn', 'unsequenced', - 'reproducible' -}) - -lexer.property['scintillua.comment'] = '//' - -return lex diff --git a/lua/lexers/c.lua b/lua/lexers/c.lua new file mode 100644 index 0000000..eacae09 --- /dev/null +++ b/lua/lexers/c.lua @@ -0,0 +1,213 @@ +-- Copyright 2006-2024 Mitchell. See LICENSE. +-- C LPeg lexer. + +local lexer = lexer +local P, S, B = lpeg.P, lpeg.S, lpeg.B + +local lex = lexer.new(...) + +-- Keywords. +lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) + +-- Types. +lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE))) + +-- Functions. +local builtin_func = -(B('.') + B('->')) * + lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)) +local func = lex:tag(lexer.FUNCTION, lexer.word) +local method = (B('.') + B('->')) * lex:tag(lexer.FUNCTION_METHOD, lexer.word) +lex:add_rule('function', (builtin_func + method + func) * #(lexer.space^0 * '(')) + +-- Constants. +lex:add_rule('constants', lex:tag(lexer.CONSTANT_BUILTIN, + -(B('.') + B('->')) * lex:word_match(lexer.CONSTANT_BUILTIN))) + +-- Labels. +lex:add_rule('label', lex:tag(lexer.LABEL, lexer.starts_line(lexer.word * ':'))) + +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +lex:add_rule('string', lex:tag(lexer.STRING, P('L')^-1 * (sq_str + dq_str))) + +-- Identifiers. +lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +local line_comment = lexer.to_eol('//', true) +local ws = S(' \t')^0 +local block_comment = lexer.range('/*', '*/') + + lexer.range('#if' * ws * '0' * lexer.space, '#endif') +lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment)) + +-- Numbers. +local integer = lexer.integer * lexer.word_match('u l ll ul ull lu llu', true)^-1 +local float = lexer.float * P('f')^-1 +lex:add_rule('number', lex:tag(lexer.NUMBER, float + integer)) + +-- Preprocessor. +local include = lex:tag(lexer.PREPROCESSOR, '#' * ws * 'include') * + (lex:get_rule('whitespace') * lex:tag(lexer.STRING, lexer.range('<', '>', true)))^-1 +local preproc = lex:tag(lexer.PREPROCESSOR, '#' * ws * lex:word_match(lexer.PREPROCESSOR)) +lex:add_rule('preprocessor', include + preproc) + +-- Attributes. +local standard_attr = lex:word_match(lexer.ATTRIBUTE) +local non_standard_attr = lexer.word * '::' * lexer.word +local attr_args = lexer.range('(', ')') +local attr = (non_standard_attr + standard_attr) * attr_args^-1 +lex:add_rule('attribute', lex:tag(lexer.ATTRIBUTE, '[[' * attr * (ws * ',' * ws * attr)^0 * ']]')) + +-- Operators. +lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>~!=^&|?~:;,.()[]{}'))) + +-- Fold points. +lex:add_fold_point(lexer.PREPROCESSOR, '#if', '#endif') +lex:add_fold_point(lexer.PREPROCESSOR, '#ifdef', '#endif') +lex:add_fold_point(lexer.PREPROCESSOR, '#ifndef', '#endif') +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, '/*', '*/') + +-- Word lists. +lex:set_word_list(lexer.KEYWORD, { + 'auto', 'break', 'case', 'const', 'continue', 'default', 'do', 'else', 'enum', 'extern', 'for', + 'goto', 'if', 'inline', 'register', 'restrict', 'return', 'sizeof', 'static', 'switch', 'typedef', + 'volatile', 'while', -- + 'false', 'true', -- C99 + 'alignas', 'alignof', '_Atomic', '_Generic', 'noreturn', '_Static_assert', 'thread_local', -- C11 + -- Compiler. + 'asm', '__asm', '__asm__', '__restrict__', '__inline', '__inline__', '__attribute__', '__declspec' +}) + +lex:set_word_list(lexer.TYPE, { + 'bool', 'char', 'double', 'float', 'int', 'long', 'short', 'signed', 'struct', 'union', + 'unsigned', 'void', -- + 'complex', 'imaginary', '_Complex', '_Imaginary', -- complex.h C99 + 'lconv', -- locale.h + 'div_t', -- math.h + 'va_list', -- stdarg.h + 'bool', '_Bool', -- stdbool.h C99 + -- stddef.h. + 'size_t', 'ptrdiff_t', -- + 'max_align_t', -- C11 + -- stdint.h. + 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', + 'int_fast64_t', 'int_least8_t', 'int_least16_t', 'int_least32_t', 'int_least64_t', 'intmax_t', + 'intptr_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint_fast8_t', 'uint_fast16_t', + 'uint_fast32_t', 'uint_fast64_t', 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', + 'uint_least64_t', 'uintmax_t', 'uintptr_t', -- + 'FILE', 'fpos_t', -- stdio.h + 'div_t', 'ldiv_t', -- stdlib.h + -- time.h. + 'tm', 'time_t', 'clock_t', -- + 'timespec' -- C11 +}) + +lex:set_word_list(lexer.FUNCTION_BUILTIN, { + 'assert', -- assert.h + -- complex.h. + 'CMPLX', 'creal', 'cimag', 'cabs', 'carg', 'conj', 'cproj', + -- C99 + 'cexp', 'cpow', 'csin', 'ccos', 'ctan', 'casin', 'cacos', 'catan', 'csinh', 'ccosh', 'ctanh', + 'casinh', 'cacosh', 'catanh', + -- ctype.h. + 'isalnum', 'isalpha', 'islower', 'isupper', 'isdigit', 'isxdigit', 'iscntrl', 'isgraph', + 'isspace', 'isprint', 'ispunct', 'tolower', 'toupper', -- + 'isblank', -- C99 + -- inttypes.h. + 'INT8_C', 'INT16_C', 'INT32_C', 'INT64_C', 'INTMAX_C', 'UINT8_C', 'UINT16_C', 'UINT32_C', + 'UINT64_C', 'UINTMAX_C', -- + 'setlocale', 'localeconv', -- locale.h + -- math.h. + 'abs', 'div', 'fabs', 'fmod', 'exp', 'log', 'log10', 'pow', 'sqrt', 'sin', 'cos', 'tan', 'asin', + 'acos', 'atan', 'atan2', 'sinh', 'cosh', 'tanh', 'ceil', 'floor', 'frexp', 'ldexp', 'modf', + -- C99. + 'remainder', 'remquo', 'fma', 'fmax', 'fmin', 'fdim', 'nan', 'exp2', 'expm1', 'log2', 'log1p', + 'cbrt', 'hypot', 'asinh', 'acosh', 'atanh', 'erf', 'erfc', 'tgamma', 'lgamma', 'trunc', 'round', + 'nearbyint', 'rint', 'scalbn', 'ilogb', 'logb', 'nextafter', 'nexttoward', 'copysign', 'isfinite', + 'isinf', 'isnan', 'isnormal', 'signbit', 'isgreater', 'isgreaterequal', 'isless', 'islessequal', + 'islessgreater', 'isunordered', -- + 'strtoimax', 'strtoumax', -- inttypes.h C99 + 'signal', 'raise', -- signal.h + 'setjmp', 'longjmp', -- setjmp.h + 'va_start', 'va_arg', 'va_end', -- stdarg.h + -- stdio.h. + 'fopen', 'freopen', 'fclose', 'fflush', 'setbuf', 'setvbuf', 'fwide', 'fread', 'fwrite', 'fgetc', + 'getc', 'fgets', 'fputc', 'putc', 'getchar', 'gets', 'putchar', 'puts', 'ungetc', 'scanf', + 'fscanf', 'sscanf', 'printf', 'fprintf', 'sprintf', 'vprintf', 'vfprintf', 'vsprintf', 'ftell', + 'fgetpos', 'fseek', 'fsetpos', 'rewind', 'clearerr', 'feof', 'ferror', 'perror', 'remove', + 'rename', 'tmpfile', 'tmpnam', + -- stdlib.h. + 'abort', 'exit', 'atexit', 'system', 'getenv', 'malloc', 'calloc', 'realloc', 'free', 'atof', + 'atoi', 'atol', 'strtol', 'strtoul', 'strtod', 'mblen', 'mbsinit', 'mbrlen', 'qsort', 'bsearch', + 'rand', 'srand', -- + 'quick_exit', '_Exit', 'at_quick_exit', 'aligned_alloc', -- C11 + -- string.h. + 'strcpy', 'strncpy', 'strcat', 'strncat', 'strxfrm', 'strlen', 'strcmp', 'strncmp', 'strcoll', + 'strchr', 'strrchr', 'strspn', 'strcspn', 'strpbrk', 'strstr', 'strtok', 'memchr', 'memcmp', + 'memset', 'memcpy', 'memmove', 'strerror', + -- time.h. + 'difftime', 'time', 'clock', 'asctime', 'ctime', 'gmtime', 'localtime', 'mktime', -- + 'timespec_get' -- C11 +}) + +lex:set_word_list(lexer.CONSTANT_BUILTIN, { + 'NULL', -- + '__DATE__', '__FILE__', '__LINE__', '__TIME__', '__func__', -- preprocessor + -- errno.h. + 'errno', -- + 'E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADF', + 'EBADMSG', 'EBUSY', 'ECANCELED', 'ECHILD', 'ECONNABORTED', 'ECONNREFUSED', 'ECONNRESET', + 'EDEADLK', 'EDESTADDRREQ', 'EDOM', 'EDQUOT', 'EEXIST', 'EFAULT', 'EFBIG', 'EHOSTUNREACH', 'EIDRM', + 'EILSEQ', 'EINPROGRESS', 'EINTR', 'EINVAL', 'EIO', 'EISCONN', 'EISDIR', 'ELOOP', 'EMFILE', + 'EMLINK', 'EMSGSIZE', 'EMULTIHOP', 'ENAMETOOLONG', 'ENETDOWN', 'ENETRESET', 'ENETUNREACH', + 'ENFILE', 'ENOBUFS', 'ENODATA', 'ENODEV', 'ENOENT', 'ENOEXEC', 'ENOLCK', 'ENOLINK', 'ENOMEM', + 'ENOMSG', 'ENOPROTOOPT', 'ENOSPC', 'ENOSR', 'ENOSTR', 'ENOSYS', 'ENOTCONN', 'ENOTDIR', + 'ENOTEMPTY', 'ENOTRECOVERABLE', 'ENOTSOCK', 'ENOTSUP', 'ENOTTY', 'ENXIO', 'EOPNOTSUPP', + 'EOVERFLOW', 'EOWNERDEAD', 'EPERM', 'EPIPE', 'EPROTO', 'EPROTONOSUPPORT', 'EPROTOTYPE', 'ERANGE', + 'EROFS', 'ESPIPE', 'ESRCH', 'ESTALE', 'ETIME', 'ETIMEDOUT', 'ETXTBSY', 'EWOULDBLOCK', 'EXDEV', + -- float.h. + 'FLT_MIN', 'DBL_MIN', 'LDBL_MIN', 'FLT_MAX', 'DBL_MAX', 'LDBL_MAX', + -- limits.h. + 'CHAR_BIT', 'MB_LEN_MAX', 'CHAR_MIN', 'CHAR_MAX', 'SCHAR_MIN', 'SHRT_MIN', 'INT_MIN', 'LONG_MIN', + 'SCHAR_MAX', 'SHRT_MAX', 'INT_MAX', 'LONG_MAX', 'UCHAR_MAX', 'USHRT_MAX', 'UINT_MAX', 'ULONG_MAX', + -- C99. + 'LLONG_MIN', 'ULLONG_MAX', 'PTRDIFF_MIN', 'PTRDIFF_MAX', 'SIZE_MAX', 'SIG_ATOMIC_MIN', + 'SIG_ATOMIC_MAX', 'WINT_MIN', 'WINT_MAX', 'WCHAR_MIN', 'WCHAR_MAX', -- + 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', -- locale.h + -- math.h. + 'HUGE_VAL', -- + 'INFINITY', 'NAN', -- C99 + -- stdint.h. + 'INT8_MIN', 'INT16_MIN', 'INT32_MIN', 'INT64_MIN', 'INT_FAST8_MIN', 'INT_FAST16_MIN', + 'INT_FAST32_MIN', 'INT_FAST64_MIN', 'INT_LEAST8_MIN', 'INT_LEAST16_MIN', 'INT_LEAST32_MIN', + 'INT_LEAST64_MIN', 'INTPTR_MIN', 'INTMAX_MIN', 'INT8_MAX', 'INT16_MAX', 'INT32_MAX', 'INT64_MAX', + 'INT_FAST8_MAX', 'INT_FAST16_MAX', 'INT_FAST32_MAX', 'INT_FAST64_MAX', 'INT_LEAST8_MAX', + 'INT_LEAST16_MAX', 'INT_LEAST32_MAX', 'INT_LEAST64_MAX', 'INTPTR_MAX', 'INTMAX_MAX', 'UINT8_MAX', + 'UINT16_MAX', 'UINT32_MAX', 'UINT64_MAX', 'UINT_FAST8_MAX', 'UINT_FAST16_MAX', 'UINT_FAST32_MAX', + 'UINT_FAST64_MAX', 'UINT_LEAST8_MAX', 'UINT_LEAST16_MAX', 'UINT_LEAST32_MAX', 'UINT_LEAST64_MAX', + 'UINTPTR_MAX', 'UINTMAX_MAX', + -- stdio.h + 'stdin', 'stdout', 'stderr', 'EOF', 'FOPEN_MAX', 'FILENAME_MAX', 'BUFSIZ', '_IOFBF', '_IOLBF', + '_IONBF', 'SEEK_SET', 'SEEK_CUR', 'SEEK_END', 'TMP_MAX', -- + 'EXIT_SUCCESS', 'EXIT_FAILURE', 'RAND_MAX', -- stdlib.h + -- signal.h. + 'SIG_DFL', 'SIG_IGN', 'SIG_ERR', 'SIGABRT', 'SIGFPE', 'SIGILL', 'SIGINT', 'SIGSEGV', 'SIGTERM', -- + 'CLOCKS_PER_SEC' -- time.h. +}) + +lex:set_word_list(lexer.PREPROCESSOR, { + 'define', 'defined', 'elif', 'else', 'endif', 'error', 'if', 'ifdef', 'ifndef', 'line', 'pragma', + 'undef' +}) + +lex:set_word_list(lexer.ATTRIBUTE, { + -- C23 + 'deprecated', 'fallthrough', 'nodiscard', 'maybe_unused', 'noreturn', '_Noreturn', 'unsequenced', + 'reproducible' +}) + +lexer.property['scintillua.comment'] = '//' + +return lex diff --git a/lua/lexers/d.lua b/lua/lexers/d.lua new file mode 100644 index 0000000..32609cc --- /dev/null +++ b/lua/lexers/d.lua @@ -0,0 +1,141 @@ +-- Copyright 2006-2024 Mitchell. See LICENSE. +-- D LPeg lexer. +-- Heavily modified by Brian Schott (@Hackerpilot on Github). + +local lexer = lexer +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new(...) + +-- Class names. +local ws = lex:get_rule('whitespace') +lex:add_rule('class', + lex:tag(lexer.TYPE, P('class') + 'struct') * ws^-1 * lex:tag(lexer.CLASS, lexer.word)) + +-- Versions. +local open_paren = lex:tag(lexer.OPERATOR, '(') +lex:add_rule('version', lex:tag(lexer.KEYWORD, 'version') * ws^-1 * open_paren * ws^-1 * + lex:tag(lexer.CONSTANT_BUILTIN .. '.version', lex:word_match('version'))) + +-- Scopes. +lex:add_rule('scope', lex:tag(lexer.KEYWORD, 'scope') * ws^-1 * open_paren * ws^-1 * + lex:tag(lexer.CONSTANT_BUILTIN .. '.scope', lexer.word_match('exit success failure'))) + +-- Traits. +lex:add_rule('trait', lex:tag(lexer.KEYWORD, '__traits') * ws^-1 * open_paren * ws^-1 * + lex:tag(lexer.VARIABLE_BUILTIN .. '.traits', lex:word_match('trait'))) + +-- Function names. +local func = lex:tag(lexer.FUNCTION, lexer.word) +local method = lpeg.B('.') * lex:tag(lexer.FUNCTION_METHOD, lexer.word) +lex:add_rule('function', (method + func) * #(ws^-1 * ('!' * lexer.word^-1 * ws^-1)^-1 * '(')) + +-- Keywords. +lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) + +-- Types. +lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE))) + +-- Constants. +lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN))) + +-- Properties. +local dot = lex:tag(lexer.OPERATOR, '.') +lex:add_rule('property', lpeg.B(lexer.alnum + ')') * dot * + lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match('property'))) + +-- Strings. +local sq_str = lexer.range("'", true) * S('cwd')^-1 +local dq_str = lexer.range('"') * S('cwd')^-1 +local lit_str = 'r' * lexer.range('"', false, false) * S('cwd')^-1 +local bt_str = lexer.range('`', false, false) * S('cwd')^-1 +local hex_str = 'x' * lexer.range('"') * S('cwd')^-1 +local other_hex_str = '\\x' * (lexer.xdigit * lexer.xdigit)^1 +local str = sq_str + dq_str + lit_str + bt_str + hex_str + other_hex_str +for left, right in pairs{['['] = ']', ['('] = ')', ['{'] = '}', ['<'] = '>'} do + str = str + lexer.range('q"' .. left, right .. '"', false, false, true) * S('cwd')^-1 +end +lex:add_rule('string', lex:tag(lexer.STRING, str)) + +-- Identifiers. +lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) + +-- Comments. +local line_comment = lexer.to_eol('//', true) +local block_comment = lexer.range('/*', '*/') +local nested_comment = lexer.range('/+', '+/', false, false, true) +lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment + nested_comment)) + +-- Numbers. +lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number_('_') * S('uULdDfFi')^-1)) + +-- Preprocessor. +lex:add_rule('annotation', lex:tag(lexer.ANNOTATION, '@' * lexer.word^1)) +lex:add_rule('preprocessor', lex:tag(lexer.PREPROCESSOR, lexer.to_eol('#'))) + +-- Operators. +lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('?=!<>+-*$/%&|^~.,;:()[]{}'))) + +-- Fold points. +lex:add_fold_point(lexer.OPERATOR, '{', '}') +lex:add_fold_point(lexer.COMMENT, '/*', '*/') +lex:add_fold_point(lexer.COMMENT, '/+', '+/') + +-- Word lists. +lex:set_word_list('version', { + 'AArch64', 'AIX', 'all', 'Alpha', 'Alpha_HardFloat', 'Alpha_SoftFloat', 'Android', 'ARM', + 'ARM_HardFloat', 'ARM_SoftFloat', 'ARM_SoftFP', 'ARM_Thumb', 'assert', 'BigEndian', 'BSD', + 'Cygwin', 'D_Coverage', 'D_Ddoc', 'D_HardFloat', 'DigitalMars', 'D_InlineAsm_X86', + 'D_InlineAsm_X86_64', 'D_LP64', 'D_NoBoundsChecks', 'D_PIC', 'DragonFlyBSD', 'D_SIMD', + 'D_SoftFloat', 'D_Version2', 'D_X32', 'FreeBSD', 'GNU', 'Haiku', 'HPPA', 'HPPA64', 'Hurd', 'IA64', + 'LDC', 'linux', 'LittleEndian', 'MIPS32', 'MIPS64', 'MIPS_EABI', 'MIPS_HardFloat', 'MIPS_N32', + 'MIPS_N64', 'MIPS_O32', 'MIPS_O64', 'MIPS_SoftFloat', 'NetBSD', 'none', 'OpenBSD', 'OSX', 'Posix', + 'PPC', 'PPC64', 'PPC_HardFloat', 'PPC_SoftFloat', 'S390', 'S390X', 'SDC', 'SH', 'SH64', 'SkyOS', + 'Solaris', 'SPARC', 'SPARC64', 'SPARC_HardFloat', 'SPARC_SoftFloat', 'SPARC_V8Plus', 'SysV3', + 'SysV4', 'unittest', 'Win32', 'Win64', 'Windows', 'X86', 'X86_64' +}) + +lex:set_word_list('trait', { + 'allMembers', 'classInstanceSize', 'compiles', 'derivedMembers', 'getAttributes', 'getMember', + 'getOverloads', 'getProtection', 'getUnitTests', 'getVirtualFunctions', 'getVirtualIndex', + 'getVirtualMethods', 'hasMember', 'identifier', 'isAbstractClass', 'isAbstractFunction', + 'isArithmetic', 'isAssociativeArray', 'isFinalClass', 'isFinalFunction', 'isFloating', + 'isIntegral', 'isLazy', 'isNested', 'isOut', 'isOverrideFunction', 'isPOD', 'isRef', 'isSame', + 'isScalar', 'isStaticArray', 'isStaticFunction', 'isUnsigned', 'isVirtualFunction', + 'isVirtualMethod', 'parent' +}) + +lex:set_word_list(lexer.KEYWORD, { + 'abstract', 'align', 'asm', 'assert', 'auto', 'body', 'break', 'case', 'cast', 'catch', 'const', + 'continue', 'debug', 'default', 'delete', 'deprecated', 'do', 'else', 'extern', 'export', 'false', + 'final', 'finally', 'for', 'foreach', 'foreach_reverse', 'goto', 'if', 'import', 'immutable', + 'in', 'inout', 'invariant', 'is', 'lazy', 'macro', 'mixin', 'new', 'nothrow', 'null', 'out', + 'override', 'pragma', 'private', 'protected', 'public', 'pure', 'ref', 'return', 'scope', + 'shared', 'static', 'super', 'switch', 'synchronized', 'this', 'throwtrue', 'try', 'typeid', + 'typeof', 'unittest', 'version', 'virtual', 'volatile', 'while', 'with', '__gshared', '__thread', + '__traits', '__vector', '__parameters' +}) + +lex:set_word_list(lexer.TYPE, { + 'alias', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'creal', 'dchar', + 'delegate', 'double', 'enum', 'float', 'function', 'idouble', 'ifloat', 'int', 'interface', + 'ireal', 'long', 'module', 'package', 'ptrdiff_t', 'real', 'short', 'size_t', 'struct', + 'template', 'typedef', 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'ushort', 'void', 'wchar', + 'string', 'wstring', 'dstring', 'hash_t', 'equals_t' +}) + +lex:set_word_list(lexer.CONSTANT_BUILTIN, { + '__FILE__', '__LINE__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', '__VENDOR__', + '__VERSION__', '__FUNCTION__', '__PRETTY_FUNCTION__', '__MODULE__' +}) + +lex:set_word_list('property', { + 'alignof', 'dig', 'dup', 'epsilon', 'idup', 'im', 'init', 'infinity', 'keys', 'length', + 'mangleof', 'mant_dig', 'max', 'max_10_exp', 'max_exp', 'min', 'min_normal', 'min_10_exp', + 'min_exp', 'nan', 'offsetof', 'ptr', 're', 'rehash', 'reverse', 'sizeof', 'sort', 'stringof', + 'tupleof', 'values' +}) + +lexer.property['scintillua.comment'] = '//' + +return lex diff --git a/lua/lexers/dmd.lua b/lua/lexers/dmd.lua deleted file mode 100644 index 32609cc..0000000 --- a/lua/lexers/dmd.lua +++ /dev/null @@ -1,141 +0,0 @@ --- Copyright 2006-2024 Mitchell. See LICENSE. --- D LPeg lexer. --- Heavily modified by Brian Schott (@Hackerpilot on Github). - -local lexer = lexer -local P, S = lpeg.P, lpeg.S - -local lex = lexer.new(...) - --- Class names. -local ws = lex:get_rule('whitespace') -lex:add_rule('class', - lex:tag(lexer.TYPE, P('class') + 'struct') * ws^-1 * lex:tag(lexer.CLASS, lexer.word)) - --- Versions. -local open_paren = lex:tag(lexer.OPERATOR, '(') -lex:add_rule('version', lex:tag(lexer.KEYWORD, 'version') * ws^-1 * open_paren * ws^-1 * - lex:tag(lexer.CONSTANT_BUILTIN .. '.version', lex:word_match('version'))) - --- Scopes. -lex:add_rule('scope', lex:tag(lexer.KEYWORD, 'scope') * ws^-1 * open_paren * ws^-1 * - lex:tag(lexer.CONSTANT_BUILTIN .. '.scope', lexer.word_match('exit success failure'))) - --- Traits. -lex:add_rule('trait', lex:tag(lexer.KEYWORD, '__traits') * ws^-1 * open_paren * ws^-1 * - lex:tag(lexer.VARIABLE_BUILTIN .. '.traits', lex:word_match('trait'))) - --- Function names. -local func = lex:tag(lexer.FUNCTION, lexer.word) -local method = lpeg.B('.') * lex:tag(lexer.FUNCTION_METHOD, lexer.word) -lex:add_rule('function', (method + func) * #(ws^-1 * ('!' * lexer.word^-1 * ws^-1)^-1 * '(')) - --- Keywords. -lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) - --- Types. -lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE))) - --- Constants. -lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN))) - --- Properties. -local dot = lex:tag(lexer.OPERATOR, '.') -lex:add_rule('property', lpeg.B(lexer.alnum + ')') * dot * - lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match('property'))) - --- Strings. -local sq_str = lexer.range("'", true) * S('cwd')^-1 -local dq_str = lexer.range('"') * S('cwd')^-1 -local lit_str = 'r' * lexer.range('"', false, false) * S('cwd')^-1 -local bt_str = lexer.range('`', false, false) * S('cwd')^-1 -local hex_str = 'x' * lexer.range('"') * S('cwd')^-1 -local other_hex_str = '\\x' * (lexer.xdigit * lexer.xdigit)^1 -local str = sq_str + dq_str + lit_str + bt_str + hex_str + other_hex_str -for left, right in pairs{['['] = ']', ['('] = ')', ['{'] = '}', ['<'] = '>'} do - str = str + lexer.range('q"' .. left, right .. '"', false, false, true) * S('cwd')^-1 -end -lex:add_rule('string', lex:tag(lexer.STRING, str)) - --- Identifiers. -lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) - --- Comments. -local line_comment = lexer.to_eol('//', true) -local block_comment = lexer.range('/*', '*/') -local nested_comment = lexer.range('/+', '+/', false, false, true) -lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment + nested_comment)) - --- Numbers. -lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number_('_') * S('uULdDfFi')^-1)) - --- Preprocessor. -lex:add_rule('annotation', lex:tag(lexer.ANNOTATION, '@' * lexer.word^1)) -lex:add_rule('preprocessor', lex:tag(lexer.PREPROCESSOR, lexer.to_eol('#'))) - --- Operators. -lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('?=!<>+-*$/%&|^~.,;:()[]{}'))) - --- Fold points. -lex:add_fold_point(lexer.OPERATOR, '{', '}') -lex:add_fold_point(lexer.COMMENT, '/*', '*/') -lex:add_fold_point(lexer.COMMENT, '/+', '+/') - --- Word lists. -lex:set_word_list('version', { - 'AArch64', 'AIX', 'all', 'Alpha', 'Alpha_HardFloat', 'Alpha_SoftFloat', 'Android', 'ARM', - 'ARM_HardFloat', 'ARM_SoftFloat', 'ARM_SoftFP', 'ARM_Thumb', 'assert', 'BigEndian', 'BSD', - 'Cygwin', 'D_Coverage', 'D_Ddoc', 'D_HardFloat', 'DigitalMars', 'D_InlineAsm_X86', - 'D_InlineAsm_X86_64', 'D_LP64', 'D_NoBoundsChecks', 'D_PIC', 'DragonFlyBSD', 'D_SIMD', - 'D_SoftFloat', 'D_Version2', 'D_X32', 'FreeBSD', 'GNU', 'Haiku', 'HPPA', 'HPPA64', 'Hurd', 'IA64', - 'LDC', 'linux', 'LittleEndian', 'MIPS32', 'MIPS64', 'MIPS_EABI', 'MIPS_HardFloat', 'MIPS_N32', - 'MIPS_N64', 'MIPS_O32', 'MIPS_O64', 'MIPS_SoftFloat', 'NetBSD', 'none', 'OpenBSD', 'OSX', 'Posix', - 'PPC', 'PPC64', 'PPC_HardFloat', 'PPC_SoftFloat', 'S390', 'S390X', 'SDC', 'SH', 'SH64', 'SkyOS', - 'Solaris', 'SPARC', 'SPARC64', 'SPARC_HardFloat', 'SPARC_SoftFloat', 'SPARC_V8Plus', 'SysV3', - 'SysV4', 'unittest', 'Win32', 'Win64', 'Windows', 'X86', 'X86_64' -}) - -lex:set_word_list('trait', { - 'allMembers', 'classInstanceSize', 'compiles', 'derivedMembers', 'getAttributes', 'getMember', - 'getOverloads', 'getProtection', 'getUnitTests', 'getVirtualFunctions', 'getVirtualIndex', - 'getVirtualMethods', 'hasMember', 'identifier', 'isAbstractClass', 'isAbstractFunction', - 'isArithmetic', 'isAssociativeArray', 'isFinalClass', 'isFinalFunction', 'isFloating', - 'isIntegral', 'isLazy', 'isNested', 'isOut', 'isOverrideFunction', 'isPOD', 'isRef', 'isSame', - 'isScalar', 'isStaticArray', 'isStaticFunction', 'isUnsigned', 'isVirtualFunction', - 'isVirtualMethod', 'parent' -}) - -lex:set_word_list(lexer.KEYWORD, { - 'abstract', 'align', 'asm', 'assert', 'auto', 'body', 'break', 'case', 'cast', 'catch', 'const', - 'continue', 'debug', 'default', 'delete', 'deprecated', 'do', 'else', 'extern', 'export', 'false', - 'final', 'finally', 'for', 'foreach', 'foreach_reverse', 'goto', 'if', 'import', 'immutable', - 'in', 'inout', 'invariant', 'is', 'lazy', 'macro', 'mixin', 'new', 'nothrow', 'null', 'out', - 'override', 'pragma', 'private', 'protected', 'public', 'pure', 'ref', 'return', 'scope', - 'shared', 'static', 'super', 'switch', 'synchronized', 'this', 'throwtrue', 'try', 'typeid', - 'typeof', 'unittest', 'version', 'virtual', 'volatile', 'while', 'with', '__gshared', '__thread', - '__traits', '__vector', '__parameters' -}) - -lex:set_word_list(lexer.TYPE, { - 'alias', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'creal', 'dchar', - 'delegate', 'double', 'enum', 'float', 'function', 'idouble', 'ifloat', 'int', 'interface', - 'ireal', 'long', 'module', 'package', 'ptrdiff_t', 'real', 'short', 'size_t', 'struct', - 'template', 'typedef', 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'ushort', 'void', 'wchar', - 'string', 'wstring', 'dstring', 'hash_t', 'equals_t' -}) - -lex:set_word_list(lexer.CONSTANT_BUILTIN, { - '__FILE__', '__LINE__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', '__VENDOR__', - '__VERSION__', '__FUNCTION__', '__PRETTY_FUNCTION__', '__MODULE__' -}) - -lex:set_word_list('property', { - 'alignof', 'dig', 'dup', 'epsilon', 'idup', 'im', 'init', 'infinity', 'keys', 'length', - 'mangleof', 'mant_dig', 'max', 'max_10_exp', 'max_exp', 'min', 'min_normal', 'min_10_exp', - 'min_exp', 'nan', 'offsetof', 'ptr', 're', 'rehash', 'reverse', 'sizeof', 'sort', 'stringof', - 'tupleof', 'values' -}) - -lexer.property['scintillua.comment'] = '//' - -return lex diff --git a/lua/lexers/glsl.lua b/lua/lexers/glsl.lua index 878ca96..3999a1a 100644 --- a/lua/lexers/glsl.lua +++ b/lua/lexers/glsl.lua @@ -4,7 +4,7 @@ local lexer = lexer local P, S = lpeg.P, lpeg.S -local lex = lexer.new(..., {inherit = lexer.load('ansi_c')}) +local lex = lexer.new(..., {inherit = lexer.load('c')}) -- Word lists. lex:set_word_list(lexer.KEYWORD, { diff --git a/lua/lexers/lexer.lua b/lua/lexers/lexer.lua index 2ea6492..0faeae9 100644 --- a/lua/lexers/lexer.lua +++ b/lua/lexers/lexer.lua @@ -50,9 +50,6 @@ -- lexer should be the name of your programming language in lower case followed by a *.lua* -- extension. For example, a new Lua lexer has the name *lua.lua*. -- --- Note: Try to refrain from using one-character language names like "c", "d", or "r". For --- example, Scintillua uses "ansi_c", "dmd", and "rstats", respectively. --- -- #### New Lexer Template -- -- There is a *lexers/template.txt* file that contains a simple template for a new lexer. Feel @@ -1612,8 +1609,8 @@ function M.detect(filename, line) bib = 'bibtex', -- boo = 'boo', -- cs = 'csharp', -- - c = 'ansi_c', C = 'ansi_c', cc = 'cpp', cpp = 'cpp', cxx = 'cpp', ['c++'] = 'cpp', h = 'cpp', - hh = 'cpp', hpp = 'cpp', hxx = 'cpp', ['h++'] = 'cpp', -- + c = 'c', C = 'c', cc = 'cpp', cpp = 'cpp', cxx = 'cpp', ['c++'] = 'cpp', h = 'cpp', hh = 'cpp', + hpp = 'cpp', hxx = 'cpp', ['h++'] = 'cpp', -- ck = 'chuck', -- clj = 'clojure', cljs = 'clojure', cljc = 'clojure', edn = 'clojure', -- ['CMakeLists.txt'] = 'cmake', cmake = 'cmake', ['cmake.in'] = 'cmake', ctest = 'cmake', @@ -1622,7 +1619,7 @@ function M.detect(filename, line) cr = 'crystal', -- css = 'css', -- cu = 'cuda', cuh = 'cuda', -- - d = 'dmd', di = 'dmd', -- + d = 'd', di = 'd', -- dart = 'dart', -- desktop = 'desktop', -- diff = 'diff', patch = 'diff', -- @@ -1700,8 +1697,7 @@ function M.detect(filename, line) proto = 'protobuf', -- pure = 'pure', -- sc = 'python', py = 'python', pyw = 'python', -- - R = 'rstats', Rout = 'rstats', Rhistory = 'rstats', Rt = 'rstats', ['Rout.save'] = 'rstats', - ['Rout.fail'] = 'rstats', -- + R = 'r', Rout = 'r', Rhistory = 'r', Rt = 'r', ['Rout.save'] = 'r', ['Rout.fail'] = 'r', -- re = 'reason', -- r = 'rebol', reb = 'rebol', -- rst = 'rest', -- diff --git a/lua/lexers/output.lua b/lua/lexers/output.lua index 9408ab1..58b25c5 100644 --- a/lua/lexers/output.lua +++ b/lua/lexers/output.lua @@ -66,7 +66,7 @@ lex:add_rule('python', local lparen, rparen = text('('), text(')') local d_filename = filename((lexer.nonnewline - '(')^1) local d_error = message(lexer.to_eol(S('Ee') * 'rror')) * mark_error -lex:add_rule('dmd', starts_line(d_filename) * lparen * line * rparen * colon * d_error) +lex:add_rule('d', starts_line(d_filename) * lparen * line * rparen * colon * d_error) -- "filename" line X: message (gnuplot) local gp_filename = filename((lexer.nonnewline - '"')^1) diff --git a/lua/lexers/r.lua b/lua/lexers/r.lua new file mode 100644 index 0000000..7ac801e --- /dev/null +++ b/lua/lexers/r.lua @@ -0,0 +1,52 @@ +-- Copyright 2006-2024 Mitchell. See LICENSE. +-- R LPeg lexer. + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, S = lpeg.P, lpeg.S + +local lex = lexer.new('r') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ + 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', -- + 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE', 'F', 'T', + -- Frequently used operators. + '|>', '%%', '%*%', '%/%', '%in%', '%o%', '%x%' +})) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match{ + 'array', 'character', 'closure', 'complex', 'data.frame', 'double', 'environment', 'expression', + 'externalptr', 'factor', 'function', 'integer', 'list', 'logical', 'matrix', 'numeric', + 'pairlist', 'promise', 'raw', 'symbol', 'vector' +})) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +local sq_str = lexer.range("'", true) +local dq_str = lexer.range('"', true) +lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, (lexer.number * P('i')^-1) * P('L')^-1)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('<->+*/^=.,:;|$()[]{}'))) + +-- Folding +lex:add_fold_point(lexer.OPERATOR, '(', ')') +lex:add_fold_point(lexer.OPERATOR, '[', ']') +lex:add_fold_point(lexer.OPERATOR, '{', '}') + +lexer.property['scintillua.comment'] = '#' + +return lex diff --git a/lua/lexers/rstats.lua b/lua/lexers/rstats.lua deleted file mode 100644 index 9883297..0000000 --- a/lua/lexers/rstats.lua +++ /dev/null @@ -1,52 +0,0 @@ --- Copyright 2006-2024 Mitchell. See LICENSE. --- R LPeg lexer. - -local lexer = require('lexer') -local token, word_match = lexer.token, lexer.word_match -local P, S = lpeg.P, lpeg.S - -local lex = lexer.new('rstats') - --- Whitespace. -lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) - --- Keywords. -lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ - 'break', 'else', 'for', 'if', 'in', 'next', 'repeat', 'return', 'switch', 'try', 'while', -- - 'Inf', 'NA', 'NaN', 'NULL', 'FALSE', 'TRUE', 'F', 'T', - -- Frequently used operators. - '|>', '%%', '%*%', '%/%', '%in%', '%o%', '%x%' -})) - --- Types. -lex:add_rule('type', token(lexer.TYPE, word_match{ - 'array', 'character', 'closure', 'complex', 'data.frame', 'double', 'environment', 'expression', - 'externalptr', 'factor', 'function', 'integer', 'list', 'logical', 'matrix', 'numeric', - 'pairlist', 'promise', 'raw', 'symbol', 'vector' -})) - --- Identifiers. -lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) - --- Strings. -local sq_str = lexer.range("'", true) -local dq_str = lexer.range('"', true) -lex:add_rule('string', token(lexer.STRING, sq_str + dq_str)) - --- Comments. -lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) - --- Numbers. -lex:add_rule('number', token(lexer.NUMBER, (lexer.number * P('i')^-1) * P('L')^-1)) - --- Operators. -lex:add_rule('operator', token(lexer.OPERATOR, S('<->+*/^=.,:;|$()[]{}'))) - --- Folding -lex:add_fold_point(lexer.OPERATOR, '(', ')') -lex:add_fold_point(lexer.OPERATOR, '[', ']') -lex:add_fold_point(lexer.OPERATOR, '{', '}') - -lexer.property['scintillua.comment'] = '#' - -return lex -- cgit v1.2.3