Skip to content

Commit

Permalink
Improve Ada syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Nov 2, 2024
1 parent 011d720 commit 2807ae6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion llamafile/highlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" || //
Expand Down
2 changes: 2 additions & 0 deletions llamafile/highlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};

Expand Down
5 changes: 3 additions & 2 deletions llamafile/highlight_ada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {

Expand All @@ -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;
Expand Down

0 comments on commit 2807ae6

Please sign in to comment.