diff --git a/.gitignore b/.gitignore
index 7ef544b..2be4d2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@ venv
.pytest_cache
.idea
.vscode
+.ipynb_checkpoints
__pycache__
build
_build
diff --git a/Makefile b/Makefile
index f6a6834..86d4683 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,8 @@ clean:
rm -rf docs/source/_build
rm -rf prof
rm -rf tests/prof
+ rm -rf Untitled*.ipynb
find . -name '.pytest_cache' -exec rm -rf {} +
find . -name '__pycache__' -exec rm -rf {} +
find . -name 'debug.txt' -exec rm -rf {} +
+ find . -name 'debug.txt' -exec rm -rf {} +
diff --git a/main.py b/main.py
index 56dc41d..db0c26f 100644
--- a/main.py
+++ b/main.py
@@ -18,6 +18,7 @@ def main(argv):
loggers = set()
try:
+ print(f"main arguments {argv=}")
opts, args = getopt.getopt(argv, "hdl:i", ["help", "debug", "logger=", "interactive"])
for o, a in opts:
diff --git a/requirements.txt b/requirements.txt
index 3cf351d..7355f10 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -18,3 +18,6 @@ pytest-profiling==1.7.0
pytz==2019.3
six==1.13.0
wcwidth==0.1.7
+
+ipykernel~=5.3.4
+setuptools~=41.6.0
\ No newline at end of file
diff --git a/src/core/sheerka/Sheerka.py b/src/core/sheerka/Sheerka.py
index fb87ef6..896aa4e 100644
--- a/src/core/sheerka/Sheerka.py
+++ b/src/core/sheerka/Sheerka.py
@@ -115,6 +115,7 @@ class Sheerka(Concept):
self.last_executions = []
self.last_return_values = []
+ self.execution_count = 0
@property
def resolved_concepts_by_first_keyword(self):
@@ -436,6 +437,7 @@ class Sheerka(Concept):
# with open(CONCEPTS_FILE, "a") as f:
# f.write(text + "\n")
+ self.execution_count += 1
self._last_execution = execution_context
if len(self.last_executions) == self.MAX_EXECUTION_HISTORY:
del self.last_executions[0]
diff --git a/src/jupyter/SheerkaKernel.py b/src/jupyter/SheerkaKernel.py
new file mode 100644
index 0000000..5218259
--- /dev/null
+++ b/src/jupyter/SheerkaKernel.py
@@ -0,0 +1,53 @@
+from core.sheerka.Sheerka import Sheerka
+from ipykernel.ipkernel import IPythonKernel
+from ipykernel.kernelapp import IPKernelApp
+from sheerkapickle import encode
+
+
+class SheerkaKernel(IPythonKernel):
+ implementation = 'Sheerka'
+ implementation_version = '0.1'
+ language = 'sheerka'
+ language_version = '0.1'
+ language_info = {
+ 'name': 'Any text',
+ 'mimetype': 'text/plain',
+ 'file_extension': '.txt',
+ }
+ banner = "Sheerka kernel"
+
+ sheerka = Sheerka()
+ sheerka.initialize()
+
+ def __init__(self, **kwargs):
+ print(f"SheerkaKernel args: {kwargs}")
+ super().__init__(**kwargs)
+
+ def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False):
+ result = self.sheerka.evaluate_user_input(code)
+
+ if not silent:
+ display_data_content = {
+ 'data': {
+ 'text/plain': str(result),
+ 'application/json': encode(self.sheerka, result)
+ },
+ 'metadata': {
+ 'application/json': {'expanded': True}
+ },
+ 'execution_count': self.sheerka.execution_count,
+
+ }
+ stream_content = {'name': 'stdout', 'text': display_data_content}
+ # self.send_response(self.iopub_socket, "stream", stream_content)
+ self.send_response(self.iopub_socket, "execute_result", display_data_content)
+
+ return {'status': 'ok',
+ # The base class increments the execution count
+ 'execution_count': self.sheerka.execution_count,
+ 'payload': [],
+ 'user_expressions': {}}
+
+
+if __name__ == '__main__':
+ IPKernelApp.launch_instance(kernel_class=SheerkaKernel)
diff --git a/src/jupyter/__init__.py b/src/jupyter/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/jupyter/install_kernel.md b/src/jupyter/install_kernel.md
new file mode 100644
index 0000000..36a691d
--- /dev/null
+++ b/src/jupyter/install_kernel.md
@@ -0,0 +1,18 @@
+To make Jupyter notebook recognize Sheerka,
+the file kernel.json must be copied where the kernels are declared
+
+ * First, open the kernel.json file and make sure that the path to SheerkaKernel is correct.
+ * The copy it to the correct location
+ * You can use the command 'jupyter kernelspec install '
+ * or simply copy it using cp ;-)
+
+Valid locations for kernel.json are
+
+| | Unix | Windows |
+|----|------| ---------------|
+|System | /usr/share/jupyter/kernels
/usr/local/share/jupyter/kernels | %PROGRAMDATA%\jupyter\kernels |
+|Env |{sys.prefix}/share/jupyter/kernels | |
+| User | ~/.local/share/jupyter/kernels (Linux)
~/Library/Jupyter/kernels (Mac) | %APPDATA%\jupyter\kernels |
+
+
+from https://jupyter-client.readthedocs.io/en/latest/kernels.html#kernel-specs
diff --git a/src/jupyter/kernel.json b/src/jupyter/kernel.json
new file mode 100644
index 0000000..ab75d53
--- /dev/null
+++ b/src/jupyter/kernel.json
@@ -0,0 +1,3 @@
+{"argv":["python", "/home/kodjo/Dev/Sheerka/src/jupyter/SheerkaKernel.py", "-f", "{connection_file}"],
+ "display_name":"Sheerka"
+}
\ No newline at end of file
diff --git a/src/parsers/BnfParser.py b/src/parsers/BnfParser.py
index f440f32..eb7e499 100644
--- a/src/parsers/BnfParser.py
+++ b/src/parsers/BnfParser.py
@@ -16,7 +16,7 @@ class UnexpectedEndOfFileError(ErrorNode):
class BnfParser(BaseParser):
"""
- Parser used to transform litteral into ParsingExpression
+ Parser used to transform literal into ParsingExpression
example :
a | b, c -> Sequence(OrderedChoice(a, b) ,c)