Skip to content

Distribute and run LLMs with a single file.

Improve Ada syntax highlighting

Justine Tunney2807ae6f5f84
diff --git a/llamafile/highlight.cpp b/llamafile/highlight.cpp
index 9c72900d..a289fceb 100644
--- a/llamafile/highlight.cpp
+++ b/llamafile/highlight.cpp
@@ -140,7 +140,8 @@ Highlight *Highlight::create(const std::string_view &lang) {
lang == "clojure")
return new HighlightLisp;
- if (lang == "ada")
+ if (lang == "ada" || //
+ lang == "adb")
return new HighlightAda;
if (lang == "haskell" || //
diff --git a/llamafile/highlight.h b/llamafile/highlight.h
index 59e1f018..9586d9f3 100644
--- a/llamafile/highlight.h
+++ b/llamafile/highlight.h
@@ -422,7 +422,9 @@ class HighlightAda : public Highlight {
void flush(std::string *result) override;
private:
+ int c_ = 0;
int t_ = 0;
+ int last_ = 0;
std::string symbol_;
};
diff --git a/llamafile/highlight_ada.cpp b/llamafile/highlight_ada.cpp
index 6f157b59..a6adab3d 100644
--- a/llamafile/highlight_ada.cpp
+++ b/llamafile/highlight_ada.cpp
@@ -37,7 +37,8 @@ HighlightAda::~HighlightAda() {
void HighlightAda::feed(std::string *r, std::string_view input) {
int c;
for (size_t i = 0; i < input.size(); ++i) {
- c = input[i] & 255;
+ last_ = c_;
+ c_ = c = input[i] & 255;
switch (t_) {
@@ -48,7 +49,7 @@ void HighlightAda::feed(std::string *r, std::string_view input) {
goto Symbol;
} else if (c == '-') {
t_ = HYPHEN;
- } else if (c == '\'') {
+ } else if (c == '\'' && last_ != ')') {
t_ = QUOTE;
*r += HI_STRING;
*r += c;