Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Add D syntax highlighting
Justine Tunney4804f7123444
diff --git a/llamafile/highlight.cpp b/llamafile/highlight.cppindex cfa8c423..13fb4f01 100644--- a/llamafile/highlight.cpp+++ b/llamafile/highlight.cpp@@ -89,6 +89,8 @@ Highlight *Highlight::create(const std::string_view &lang) {return new HighlightShell;} else if (lang == "swift") {return new HighlightC(is_keyword_swift, is_keyword_swift_type);+ } else if (lang == "d") {+ return new HighlightC(is_keyword_d);} else {return new HighlightPlain;}diff --git a/llamafile/highlight.h b/llamafile/highlight.hindex 66ecf4c7..0033d0e4 100644--- a/llamafile/highlight.h+++ b/llamafile/highlight.h@@ -71,6 +71,7 @@ is_keyword_f is_keyword_shell;is_keyword_f is_keyword_shell_builtin;is_keyword_f is_keyword_swift;is_keyword_f is_keyword_swift_type;+is_keyword_f is_keyword_d;}class Highlight {diff --git a/llamafile/highlight_test.cpp b/llamafile/highlight_test.cppindex 9a0adfc8..c2e78458 100644--- a/llamafile/highlight_test.cpp+++ b/llamafile/highlight_test.cpp@@ -33,9 +33,8 @@ const char *const kLanguages[] = {"c#", //"c++", //"cobol", //- "cs", //- "csharp", //"css", //+ "d", //"fortran", //"go", //"haskell", //diff --git a/llamafile/is_keyword_d.c b/llamafile/is_keyword_d.cnew file mode 100644index 00000000..577b8b0b--- /dev/null+++ b/llamafile/is_keyword_d.c@@ -0,0 +1,273 @@+/* ANSI-C code produced by gperf version 3.1 */+/* Command-line: gperf llamafile/is_keyword_d.gperf */+/* Computed positions: -k'1,3,$' */++#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \+ && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \+ && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \+ && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \+ && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \+ && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \+ && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \+ && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \+ && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \+ && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \+ && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \+ && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \+ && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \+ && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \+ && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \+ && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \+ && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \+ && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \+ && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \+ && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \+ && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \+ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \+ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))+/* The character set is not based on ISO-646. */+#error "gperf generated tables don't work with this execution character set. Please report a bug to <[email protected]>."+#endif++#line 1 "llamafile/is_keyword_d.gperf"++#include <string.h>++#define TOTAL_KEYWORDS 110+#define MIN_WORD_LENGTH 2+#define MAX_WORD_LENGTH 19+#define MIN_HASH_VALUE 3+#define MAX_HASH_VALUE 193+/* maximum key range = 191, duplicates = 0 */++#ifdef __GNUC__+__inline+#else+#ifdef __cplusplus+inline+#endif+#endif+static unsigned int+hash (register const char *str, register size_t len)+{+ static const unsigned char asso_values[] =+ {+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 0, 194, 194, 194, 194, 194, 25, 85, 194, 194,+ 0, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 30, 194, 25, 110, 15,+ 35, 5, 20, 35, 5, 0, 194, 30, 60, 75,+ 35, 5, 0, 194, 85, 5, 0, 65, 30, 50,+ 20, 40, 10, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,+ 194, 194, 194, 194, 194, 194+ };+ register unsigned int hval = len;++ switch (hval)+ {+ default:+ hval += asso_values[(unsigned char)str[2]];+ /*FALLTHROUGH*/+ case 2:+ case 1:+ hval += asso_values[(unsigned char)str[0]];+ break;+ }+ return hval + asso_values[(unsigned char)str[len - 1]];+}++const char *+is_keyword_d (register const char *str, register size_t len)+{+ static const char * const wordlist[] =+ {+ "", "", "",+ "int",+ "", "",+ "import",+ "is",+ "out",+ "this",+ "inout",+ "export",+ "private",+ "",+ "interface",+ "short",+ "switch",+ "idouble",+ "",+ "else",+ "scope",+ "",+ "if",+ "override",+ "cast",+ "catch",+ "typeof",+ "package",+ "",+ "case",+ "float",+ "",+ "cdouble",+ "",+ "auto",+ "alias",+ "assert",+ "in",+ "abstract",+ "invariant",+ "",+ "typeid",+ "do",+ "__traits",+ "goto",+ "",+ "extern",+ "__parameters",+ "",+ "protected",+ "class",+ "static",+ "", "",+ "cent",+ "const",+ "pragma",+ "", "",+ "with",+ "while",+ "",+ "default",+ "continue",+ "",+ "align",+ "ifloat",+ "",+ "__FILE__",+ "void",+ "ireal",+ "shared",+ "__FUNCTION__",+ "unittest",+ "true",+ "ucent",+ "ushort",+ "",+ "__FILE_FULL_PATH__",+ "__PRETTY_FUNCTION__",+ "deprecated",+ "cfloat",+ "",+ "try",+ "",+ "creal",+ "",+ "synchronized",+ "template",+ "immutable",+ "false",+ "",+ "nothrow",+ "__LINE__",+ "pure",+ "super",+ "struct",+ "",+ "function",+ "",+ "macro",+ "",+ "finally",+ "",+ "uint",+ "union",+ "delete",+ "",+ "delegate",+ "__gshared",+ "ulong",+ "double",+ "", "",+ "lazy",+ "ubyte",+ "",+ "foreach",+ "",+ "byte",+ "final",+ "module",+ "", "", "",+ "foreach_reverse",+ "return",+ "",+ "ref",+ "char",+ "dchar",+ "public",+ "", "",+ "long",+ "mixin",+ "", "",+ "new",+ "",+ "throw",+ "", "", "", "",+ "wchar",+ "", "", "",+ "enum",+ "break",+ "", "",+ "__vector",+ "",+ "__MODULE__",+ "",+ "version",+ "",+ "null",+ "", "", "", "", "", "", "", "", "",+ "", "", "", "", "",+ "real",+ "", "", "",+ "asm",+ "bool",+ "", "", "", "", "",+ "debug",+ "", "", "",+ "body",+ "", "", "",+ "for"+ };++ if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)+ {+ register unsigned int key = hash (str, len);++ if (key <= MAX_HASH_VALUE)+ {+ register const char *s = wordlist[key];++ if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')+ return s;+ }+ }+ return 0;+}diff --git a/llamafile/is_keyword_d.gperf b/llamafile/is_keyword_d.gperfnew file mode 100644index 00000000..b27deb18--- /dev/null+++ b/llamafile/is_keyword_d.gperf@@ -0,0 +1,118 @@+%{+#include <string.h>+%}+%compare-strncmp+%language=ANSI-C+%readonly-tables+%define lookup-function-name is_keyword_d+%%+__FILE_FULL_PATH__+__FILE__+__FUNCTION__+__LINE__+__MODULE__+__PRETTY_FUNCTION__+__gshared+__parameters+__traits+__vector+abstract+alias+align+asm+assert+auto+body+bool+break+byte+case+cast+catch+cdouble+cent+cfloat+char+class+const+continue+creal+dchar+debug+default+delegate+delete+deprecated+do+double+else+enum+export+extern+false+final+finally+float+for+foreach+foreach_reverse+function+goto+idouble+if+ifloat+immutable+import+in+inout+int+interface+invariant+ireal+is+lazy+long+macro+mixin+module+new+nothrow+null+out+override+package+pragma+private+protected+public+pure+real+ref+return+scope+shared+short+static+struct+super+switch+synchronized+template+this+throw+true+try+typeid+typeof+ubyte+ucent+uint+ulong+union+unittest+ushort+version+void+wchar+while+with