From 5d255551a6c704eabf5cbf0054cdea2cd4c5b035 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hans-J=C3=B6rg=20Schurr?= <hansjoerg-schurr@uiowa.edu>
Date: Fri, 3 Feb 2023 16:29:36 -0600
Subject: [PATCH] Fix syntax highliging for new minted versions

---
 spec/doc.tex                      |  6 +++---
 spec/{smtlib2.py => highlight.py} | 31 ++++++++++++++++++++++++-------
 2 files changed, 27 insertions(+), 10 deletions(-)
 rename spec/{smtlib2.py => highlight.py} (79%)
 mode change 100644 => 100755

diff --git a/spec/doc.tex b/spec/doc.tex
index 49a2cf8..8c17aa4 100644
--- a/spec/doc.tex
+++ b/spec/doc.tex
@@ -10,9 +10,9 @@
 
 \usepackage{minted}
 \usemintedstyle{trac}
-% TODO: tweak hilighter
-\newminted[AletheVerb]{smtlib2.py -x}{}
-\newmintinline[inlineAlethe]{smtlib2.py -x}{}
+\renewcommand{\MintedPygmentize}{./highlight.py}
+\newminted[AletheVerb]{smt-lib}{}
+\newmintinline[inlineAlethe]{smt-lib}{}
 
 \usepackage{cite}
 \usepackage{url}
diff --git a/spec/smtlib2.py b/spec/highlight.py
old mode 100644
new mode 100755
similarity index 79%
rename from spec/smtlib2.py
rename to spec/highlight.py
index 862a2a3..ed78bb3
--- a/spec/smtlib2.py
+++ b/spec/highlight.py
@@ -1,19 +1,33 @@
+#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
+# This is a thin wraper arround pygmentize that adds support for SMT-LIB/Alethe.
+# More precicely: it parses the command line arguments and uses a custom
+# SMT-LIB lexer if the user selects smt-lib as the language.
+# This wrapper was made necessary by version 2.7 of minted:  it started to
+# quote command line arguments hended to pygmentize and thereby made the old
+# tick to use "smtlib2.py -x" as the language unworkable.
+
 import re
+import argparse
+import sys
 
-from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, \
-    default, include
+import pygments.cmdline as _cmdline
+from pygments.lexer import RegexLexer
 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
-    Number, Punctuation, Generic
-from pygments import unistring as uni
-
-__all__ = ['Smt2Lexer']
+    Number, Punctuation
 
+def main(args):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-l', dest='lexer', type=str)
+    opts, rest = parser.parse_known_args(args[1:])
+    if opts.lexer == 'smt-lib':
+        args = [__file__, '-l', __file__ + ':SMTLibLexer', '-x', *rest]
+    _cmdline.main(args)
 
 line_re = re.compile('.*?\n')
 
-class CustomLexer(RegexLexer):
+class SMTLibLexer(RegexLexer):
     """
     A SMT-Lib 2 parser
     """
@@ -117,3 +131,6 @@ class CustomLexer(RegexLexer):
             (r'[^()]+', Comment),
         ],
     }
+
+if __name__ == '__main__':
+    main(sys.argv)
\ No newline at end of file
-- 
GitLab