Skip to content

Commit

Permalink
Add pygments_lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
tani committed Dec 6, 2021
1 parent 1beadc6 commit 9580dfe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion acl2_kernel/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions acl2_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import re
import os

__version__ = '0.2.9'
__version__ = '0.3.1'


class ACL2Kernel(Kernel):
implementation = 'acl2_kernel'
Expand All @@ -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'
Expand All @@ -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 {
Expand All @@ -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())
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <m@docs.casa>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 9580dfe

Please sign in to comment.