IPython grammar for tree-sitter (extends Python with magic support)
npm install @abir-taheer/tree-sitter-ipythonA tree-sitter grammar for IPython/Jupyter that extends tree-sitter-python to support magic commands and shell escapes.
- Line Magics (%): %matplotlib inline, %timeit x = 1, %pwd
- Cell Magics (%%): %%time, %%bash, %%writefile test.py
- Shell Escapes (!): !pip install pandas, !ls -la
- Full Python syntax support (inherited from tree-sitter-python)
``bash`
npm install @abir-taheer/tree-sitter-ipython
`javascript
const Parser = require('tree-sitter');
const IPython = require('@abir-taheer/tree-sitter-ipython');
const parser = new Parser();
parser.setLanguage(IPython);
const code =
%matplotlib inline
import pandas as pd
!pip install numpy
%%time
x = sum(range(1000));
const tree = parser.parse(code);
console.log(tree.rootNode.toString());
`
(line_magic
(magic_operator) ; the % symbol
name: (magic_name) ; command name like "matplotlib"
arguments: (magic_arguments)) ; optional arguments like "inline"
`$3
`
(cell_magic
(cell_magic_operator) ; the %% symbol
name: (magic_name) ; command name like "time"
arguments: (magic_arguments)) ; optional arguments
`$3
`
(shell_escape
(shell_operator) ; the ! symbol
command: (shell_content)) ; the shell command
`Development
`bash
Install dependencies
npm installGenerate parser
npm run generateBuild native module
npm run buildRun tests
npm test
``MIT