Skip to content

Distribute and run LLMs with a single file.

Add FORTRAN syntax highlighting

Justine Tunneyba1664484607
diff --git a/llamafile/highlight.cpp b/llamafile/highlight.cpp
index 50401f07..60c292e7 100644
--- a/llamafile/highlight.cpp
+++ b/llamafile/highlight.cpp
@@ -32,6 +32,8 @@ Highlight *Highlight::create(const std::string_view &lang) {
return new HighlightPython();
} else if (lang == "rs" || lang == "rust") {
return new HighlightRust();
+ } else if (lang == "f" || lang == "fortran") {
+ return new HighlightFortran();
} else {
return new HighlightPlain;
}
diff --git a/llamafile/highlight.h b/llamafile/highlight.h
index 5bb06417..f363e960 100644
--- a/llamafile/highlight.h
+++ b/llamafile/highlight.h
@@ -26,6 +26,9 @@
#define HI_COMMENT "\033[31m" // red
#define HI_MACRO "\033[35m" // magenta
#define HI_ATTRIB "\033[35m" // magenta
+#define HI_CONTIN "\033[33m" // yellow
+#define HI_TYPE "\033[36m" // cyan
+#define HI_LABEL "\033[35m" // magenta
typedef const char *is_keyword_f(const char *, size_t);
@@ -36,6 +39,8 @@ is_keyword_f is_keyword_js;
is_keyword_f is_keyword_java;
is_keyword_f is_keyword_python;
is_keyword_f is_keyword_rust;
+is_keyword_f is_keyword_fortran;
+is_keyword_f is_keyword_fortran_type;
}
class Highlight {
@@ -104,3 +109,16 @@ class HighlightRust : public Highlight {
int nest_ = 0;
std::string word_;
};
+
+class HighlightFortran : public Highlight {
+ public:
+ HighlightFortran();
+ ~HighlightFortran() override;
+ void feed(std::string *result, std::string_view input) override;
+ void flush(std::string *result) override;
+
+ private:
+ int t_ = 0;
+ int col_ = 0;
+ std::string word_;
+};
diff --git a/llamafile/highlight_fortran.cpp b/llamafile/highlight_fortran.cpp
new file mode 100644
index 00000000..f235b16d
--- /dev/null
+++ b/llamafile/highlight_fortran.cpp
@@ -0,0 +1,181 @@
+// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-
+// vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi
+//
+// Copyright 2024 Mozilla Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "highlight.h"
+
+#include <ctype.h>
+
+#define NORMAL 0
+#define WORD 1
+#define QUOTE 2
+#define DQUOTE 3
+#define COMMENT 4
+#define BACKSLASH 64
+
+HighlightFortran::HighlightFortran() {
+}
+
+HighlightFortran::~HighlightFortran() {
+}
+
+void HighlightFortran::feed(std::string *r, std::string_view input) {
+ int c;
+ for (size_t i = 0; i < input.size(); ++i) {
+ c = input[i] & 255;
+
+ ++col_;
+ if (c == '\n')
+ col_ = -1;
+
+ if (t_ == NORMAL) {
+ if (col_ == 0 && c == '*') {
+ t_ = COMMENT;
+ *r += HI_COMMENT;
+ } else if (col_ == 5 && c != ' ') {
+ *r += HI_CONTIN;
+ *r += c;
+ *r += HI_RESET;
+ continue;
+ } else if (col_ <= 4 && isdigit(c)) {
+ *r += HI_LABEL;
+ *r += c;
+ *r += HI_RESET;
+ continue;
+ }
+ }
+
+ if (t_ & BACKSLASH) {
+ t_ &= ~BACKSLASH;
+ *r += c;
+ continue;
+ } else if (c == '\\') {
+ *r += c;
+ t_ |= BACKSLASH;
+ continue;
+ }
+
+ switch (t_) {
+
+ Normal:
+ case NORMAL:
+ if (!isascii(c) || isalpha(c) || c == '_' || c == '.') {
+ word_ += c;
+ t_ = WORD;
+ } else if (c == '!') {
+ t_ = COMMENT;
+ *r += HI_COMMENT;
+ *r += c;
+ } else if (c == '\'') {
+ t_ = QUOTE;
+ *r += HI_STRING;
+ *r += c;
+ } else if (c == '"') {
+ t_ = DQUOTE;
+ *r += HI_STRING;
+ *r += c;
+ } else {
+ *r += c;
+ }
+ break;
+
+ Word:
+ case WORD:
+ if (!isascii(c) || isalpha(c) || isdigit(c) || c == '_') {
+ word_ += c;
+ } else if (c == '.' && word_[0] == '.') {
+ word_ += c;
+ if (is_keyword_fortran(word_.data(), word_.size())) {
+ *r += HI_KEYWORD;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ t_ = NORMAL;
+ } else {
+ if (is_keyword_fortran(word_.data(), word_.size())) {
+ *r += HI_KEYWORD;
+ *r += word_;
+ *r += HI_RESET;
+ } else if (is_keyword_fortran_type(word_.data(), word_.size())) {
+ *r += HI_TYPE;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ t_ = NORMAL;
+ goto Normal;
+ }
+ break;
+
+ case COMMENT:
+ if (c == '\n') {
+ *r += HI_RESET;
+ *r += c;
+ t_ = NORMAL;
+ } else {
+ *r += c;
+ }
+ break;
+
+ case QUOTE:
+ *r += c;
+ if (c == '\'') {
+ *r += HI_RESET;
+ t_ = NORMAL;
+ }
+ break;
+
+ case DQUOTE:
+ *r += c;
+ if (c == '"') {
+ *r += HI_RESET;
+ t_ = NORMAL;
+ }
+ break;
+
+ default:
+ __builtin_unreachable();
+ }
+ }
+}
+
+void HighlightFortran::flush(std::string *r) {
+ switch (t_) {
+ case WORD:
+ if (is_keyword_fortran(word_.data(), word_.size())) {
+ *r += HI_KEYWORD;
+ *r += word_;
+ *r += HI_RESET;
+ } else {
+ *r += word_;
+ }
+ word_.clear();
+ break;
+ case QUOTE:
+ case DQUOTE:
+ case COMMENT:
+ *r += HI_RESET;
+ break;
+ default:
+ break;
+ }
+ t_ = NORMAL;
+}
diff --git a/llamafile/is_keyword_fortran.c b/llamafile/is_keyword_fortran.c
new file mode 100644
index 00000000..1bdc6708
--- /dev/null
+++ b/llamafile/is_keyword_fortran.c
@@ -0,0 +1,337 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf is_keyword_fortran.gperf */
+/* Computed positions: -k'2-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 "is_keyword_fortran.gperf"
+
+#include <string.h>
+#include <libc/str/tab.h>
+#define GPERF_DOWNCASE
+
+#define TOTAL_KEYWORDS 116
+#define MIN_WORD_LENGTH 2
+#define MAX_WORD_LENGTH 15
+#define MIN_HASH_VALUE 7
+#define MAX_HASH_VALUE 291
+/* maximum key range = 285, duplicates = 0 */
+
+#ifndef GPERF_DOWNCASE
+#define GPERF_DOWNCASE 1
+static unsigned char gperf_downcase[256] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
+ 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
+ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
+ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 255
+ };
+#endif
+
+#ifndef GPERF_CASE_STRNCMP
+#define GPERF_CASE_STRNCMP 1
+static int
+gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
+{
+ for (; n > 0;)
+ {
+ unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
+ unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
+ if (c1 != 0 && c1 == c2)
+ {
+ n--;
+ continue;
+ }
+ return (int)c1 - (int)c2;
+ }
+ return 0;
+}
+#endif
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static unsigned int
+hash (register const char *str, register size_t len)
+{
+ static const unsigned short asso_values[] =
+ {
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 70, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 35, 0, 115, 122, 0,
+ 25, 95, 50, 95, 5, 62, 25, 25, 40, 5,
+ 75, 55, 75, 15, 10, 55, 10, 20, 0, 105,
+ 0, 292, 292, 292, 292, 292, 292, 35, 0, 115,
+ 122, 0, 25, 95, 50, 95, 5, 62, 25, 25,
+ 40, 5, 75, 55, 75, 15, 10, 55, 10, 20,
+ 0, 105, 0, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292, 292, 292, 292,
+ 292, 292, 292, 292, 292, 292, 292
+ };
+ register unsigned int hval = len;
+
+ switch (hval)
+ {
+ default:
+ hval += asso_values[(unsigned char)str[2]+1];
+ /*FALLTHROUGH*/
+ case 2:
+ hval += asso_values[(unsigned char)str[1]];
+ break;
+ }
+ return hval + asso_values[(unsigned char)str[len - 1]];
+}
+
+const char *
+is_keyword_fortran (register const char *str, register size_t len)
+{
+ static const char * const wordlist[] =
+ {
+ "", "", "", "", "", "", "",
+ "rewrite",
+ "", "",
+ "deallocate",
+ "module",
+ "do",
+ "", "", "", "", "",
+ "continue",
+ "exit",
+ "", "", "",
+ "non_recursive",
+ "",
+ "non_overridable",
+ "result",
+ "",
+ "abstract",
+ "",
+ "concurrent",
+ "", "",
+ "contains",
+ "associate",
+ "contiguous",
+ "format",
+ "",
+ "volatile",
+ "else",
+ "",
+ "select",
+ "asynchronous",
+ "use",
+ "elsewhere",
+ "class",
+ "images",
+ "endfile",
+ "",
+ "case",
+ "pause",
+ "forall",
+ "if",
+ "",
+ "wait",
+ "",
+ "codimension",
+ "",
+ "allocate",
+ "save",
+ "while",
+ "allocatable",
+ "", "",
+ "pass",
+ "value",
+ "target",
+ "", "",
+ "goto",
+ "endif",
+ "assign",
+ "", "",
+ "pure",
+ "",
+ "equivalence",
+ "extends",
+ "all",
+ "enum",
+ "where",
+ "nopass",
+ "",
+ "sequence",
+ "elemental",
+ "write",
+ "impure",
+ "private",
+ "external",
+ "call",
+ "flush",
+ "common",
+ "pointer",
+ "namelist",
+ ".or.",
+ "print",
+ "import",
+ "",
+ "implicit",
+ "", "",
+ "return",
+ "", "",
+ "interface",
+ "close",
+ "rank",
+ "",
+ "function",
+ "", "",
+ "intent",
+ "",
+ "critical",
+ "",
+ ".and.",
+ "", "", "",
+ "then",
+ "", "",
+ "inquire",
+ "",
+ ".le.",
+ "",
+ "read",
+ "generic",
+ "rewind",
+ "data",
+ "final",
+ "recursive",
+ "",
+ "unlock",
+ "parameter",
+ "enumerator",
+ "", "", "",
+ ".ne.",
+ "",
+ ".neqv.",
+ "", "",
+ "open",
+ "", "", "", "",
+ ".eq.",
+ ".eqv.",
+ "memory",
+ "", "",
+ ".lt.",
+ "", "", "", "",
+ "procedure",
+ "", "", "",
+ "optional",
+ "stop",
+ "end",
+ "backspace",
+ "block",
+ "",
+ "include",
+ "error",
+ "", "", "",
+ "only",
+ "", "", "", "",
+ "submodule",
+ "subroutine",
+ "",
+ "program",
+ "operator",
+ "dimension",
+ "", "", "", "", "",
+ ".not.",
+ "",
+ "nullify",
+ "lock",
+ ".ge.",
+ "", "", "", "", "", "", "", "", "",
+ "",
+ "entry",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "", "",
+ "intrinsic",
+ "", "", "", "",
+ ".gt.",
+ "deferred",
+ "bind",
+ "", "",
+ "sync",
+ "", "",
+ "cycle",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "",
+ "", "", "",
+ "protected",
+ "", "", "", "", "", "", "", "", "",
+ "public"
+ };
+
+ 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 ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
+ return s;
+ }
+ }
+ return 0;
+}
diff --git a/llamafile/is_keyword_fortran.gperf b/llamafile/is_keyword_fortran.gperf
new file mode 100644
index 00000000..8e04987d
--- /dev/null
+++ b/llamafile/is_keyword_fortran.gperf
@@ -0,0 +1,127 @@
+%{
+#include <string.h>
+#include <libc/str/tab.h>
+#define GPERF_DOWNCASE
+%}
+%ignore-case
+%compare-strncmp
+%language=ANSI-C
+%readonly-tables
+%define lookup-function-name is_keyword_fortran
+%%
+.and.
+.eq.
+.eqv.
+.ge.
+.gt.
+.le.
+.lt.
+.ne.
+.neqv.
+.not.
+.or.
+abstract
+all
+allocatable
+allocate
+assign
+associate
+asynchronous
+backspace
+bind
+block
+call
+case
+class
+close
+codimension
+common
+concurrent
+contains
+contiguous
+continue
+critical
+cycle
+data
+deallocate
+deferred
+dimension
+do
+elemental
+else
+elsewhere
+end
+endfile
+endif
+entry
+enum
+enumerator
+equivalence
+error
+exit
+extends
+external
+final
+flush
+forall
+format
+function
+generic
+goto
+if
+images
+implicit
+import
+impure
+include
+inquire
+intent
+interface
+intrinsic
+lock
+memory
+module
+namelist
+non_overridable
+non_recursive
+nopass
+nullify
+only
+open
+operator
+optional
+parameter
+pass
+pause
+pointer
+print
+private
+procedure
+program
+protected
+public
+pure
+rank
+read
+recursive
+result
+return
+rewind
+rewrite
+save
+select
+sequence
+stop
+submodule
+subroutine
+sync
+target
+then
+unlock
+use
+value
+volatile
+wait
+where
+while
+write
diff --git a/llamafile/is_keyword_fortran_type.c b/llamafile/is_keyword_fortran_type.c
new file mode 100644
index 00000000..d1fdd2be
--- /dev/null
+++ b/llamafile/is_keyword_fortran_type.c
@@ -0,0 +1,171 @@
+/* ANSI-C code produced by gperf version 3.1 */
+/* Command-line: gperf llamafile/is_keyword_fortran_type.gperf */
+/* Computed positions: -k'1' */
+
+#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_fortran_type.gperf"
+
+#include <string.h>
+#include <libc/str/tab.h>
+#define GPERF_DOWNCASE
+
+#define TOTAL_KEYWORDS 14
+#define MIN_WORD_LENGTH 4
+#define MAX_WORD_LENGTH 11
+#define MIN_HASH_VALUE 4
+#define MAX_HASH_VALUE 22
+/* maximum key range = 19, duplicates = 0 */
+
+#ifndef GPERF_DOWNCASE
+#define GPERF_DOWNCASE 1
+static unsigned char gperf_downcase[256] =
+ {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
+ 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
+ 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
+ 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
+ 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
+ 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
+ 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 255
+ };
+#endif
+
+#ifndef GPERF_CASE_STRNCMP
+#define GPERF_CASE_STRNCMP 1
+static int
+gperf_case_strncmp (register const char *s1, register const char *s2, register size_t n)
+{
+ for (; n > 0;)
+ {
+ unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
+ unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
+ if (c1 != 0 && c1 == c2)
+ {
+ n--;
+ continue;
+ }
+ return (int)c1 - (int)c2;
+ }
+ return 0;
+}
+#endif
+
+#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[] =
+ {
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 5, 14, 10, 5, 23,
+ 23, 23, 23, 15, 23, 23, 5, 23, 23, 23,
+ 0, 23, 9, 0, 0, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 5, 14, 10,
+ 5, 23, 23, 23, 23, 15, 23, 23, 5, 23,
+ 23, 23, 0, 23, 9, 0, 0, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
+ 23, 23, 23, 23, 23, 23
+ };
+ return len + asso_values[(unsigned char)str[0]];
+}
+
+const char *
+is_keyword_fortran_type (register const char *str, register size_t len)
+{
+ static const char * const wordlist[] =
+ {
+ "", "", "", "",
+ "type",
+ "",
+ "target",
+ "pointer",
+ "sequence",
+ "precision",
+ "",
+ "double",
+ "logical",
+ "real",
+ "dimension",
+ "",
+ "allocatable",
+ "complex",
+ "byte",
+ "character",
+ "", "",
+ "integer"
+ };
+
+ 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 ((((unsigned char)*str ^ (unsigned char)*s) & ~32) == 0 && !gperf_case_strncmp (str, s, len) && s[len] == '\0')
+ return s;
+ }
+ }
+ return 0;
+}
diff --git a/llamafile/is_keyword_fortran_type.gperf b/llamafile/is_keyword_fortran_type.gperf
new file mode 100644
index 00000000..3498eaa0
--- /dev/null
+++ b/llamafile/is_keyword_fortran_type.gperf
@@ -0,0 +1,25 @@
+%{
+#include <string.h>
+#include <libc/str/tab.h>
+#define GPERF_DOWNCASE
+%}
+%ignore-case
+%compare-strncmp
+%language=ANSI-C
+%readonly-tables
+%define lookup-function-name is_keyword_fortran_type
+%%
+allocatable
+byte
+character
+complex
+dimension
+double
+integer
+logical
+pointer
+precision
+real
+sequence
+target
+type