From 9580dfeb84d2278be7ea1456ac48a0e46e2f6c71 Mon Sep 17 00:00:00 2001 From: TANIGUCHI Masaya Date: Mon, 6 Dec 2021 12:38:40 +0900 Subject: [PATCH] Add pygments_lexer --- acl2_kernel/install.py | 3 ++- acl2_kernel/kernel.py | 18 +++++++++++------- pyproject.toml | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/acl2_kernel/install.py b/acl2_kernel/install.py index e544a4b..7b4185e 100644 --- a/acl2_kernel/install.py +++ b/acl2_kernel/install.py @@ -6,13 +6,14 @@ from jupyter_client.kernelspec import KernelSpecManager from IPython.utils.tempdir import TemporaryDirectory + def install_my_kernel_spec(user=True, prefix=None, acl2='acl2'): kernel_json = { 'argv': [sys.executable, '-m', 'acl2_kernel', '-f', '{connection_file}'], 'display_name': 'ACL2', 'language': 'acl2', 'codemirror_mode': 'lisp', - 'env': { 'ACL2': acl2 }, + 'env': {'ACL2': acl2}, } with TemporaryDirectory() as td: os.chmod(td, 0o755) # Starts off as 700, not user readable diff --git a/acl2_kernel/kernel.py b/acl2_kernel/kernel.py index a07f2a8..464088e 100644 --- a/acl2_kernel/kernel.py +++ b/acl2_kernel/kernel.py @@ -8,7 +8,8 @@ import re import os -__version__ = '0.2.9' +__version__ = '0.3.1' + class ACL2Kernel(Kernel): implementation = 'acl2_kernel' @@ -19,13 +20,14 @@ def language_version(self): with Popen(os.environ['ACL2'], stdout=PIPE, stdin=PIPE) as p: p.stdin.close() return re.findall(r'ACL2 Version.*$', p.stdout.read().decode('utf-8'), re.MULTILINE)[0] - + @property def banner(self): return u'ACL2 Kernel (%s)' % self.language_version - + language_info = { 'name': 'acl2', + 'pygments_lexer': 'common-lisp', 'codemirror_mode': 'commonlisp', 'mimetype': 'text/x-common-lisp', 'file_extension': '.lisp' @@ -48,13 +50,14 @@ def _start_acl2(self): (set-ld-prompt 'jupyter-prompt state) (defttag nil) (reset-prehistory)''' - self.acl2wrapper = replwrap.REPLWrapper(os.environ['ACL2'], 'ACL2 !>', prompt_change_cmd, 'JPY-ACL2>') + self.acl2wrapper = replwrap.REPLWrapper( + os.environ['ACL2'], 'ACL2 !>', prompt_change_cmd, 'JPY-ACL2>') # Discard the output of prompt_change_cmd. for i in range(3): self.acl2wrapper.run_command(';', timeout=None) finally: signal.signal(signal.SIGINT, sig) - + def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): if not code.strip(): return { @@ -81,7 +84,8 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None, al # (t (cons (car x) # (app (cdr x) y))))) # using the \((?>[^()]|(?R))*\) regex. - num_cmds = len(regex.findall(r'^[ \t]*:.*$|\((?>[^()]|(?R))*\)', cmd, regex.MULTILINE)) + num_cmds = len(regex.findall( + r'^[ \t]*:.*$|\((?>[^()]|(?R))*\)', cmd, regex.MULTILINE)) # Convert all \r and \n into spaces. cmd = re.sub(r'[\r\n]', ' ', cmd.strip()) @@ -99,7 +103,7 @@ def do_execute(self, code, silent, store_history=True, user_expressions=None, al self.acl2wrapper.child.sendintr() interrupted = True self.acl2wrapper._expect_prompt() - output = self.acl2wrapper.child.before + output = self.acl2wrapper.child.before self.process_output(output) except EOF: output = self.acl2wrapper.child.before + 'Restarting ACL2' diff --git a/pyproject.toml b/pyproject.toml index 040da4c..287471a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "acl2-kernel" -version = "0.2.9" +version = "0.3.1" description = "Jupyter Kernel for ACL2" authors = ["TANIGUCHI Masaya "] license = "Apache-2.0"