1 from __future__
import print_function
4 from IPython.core.inputtransformer
import InputTransformer
5 from IPython
import get_ipython
6 from IPython.core
import display
10 _cppDcl=re.compile(
"\s*\.cpp\s+-d")
11 _cppAclic=re.compile(
"\s*\.cpp\s+-a")
12 _bash=re.compile(
"\s*\.bash\d*")
25 >>> t = CppTransformer()
26 >>> t.push("int i=3;")
31 >>> t.push('int q(int i){return i+i;};')
35 >>> t.push(' .cpp -a\t\t ')
36 >>> t.push('int qq(int i){return i+i;};')
41 >>> t.push('int f(int i){return i+i;}')
46 >>> t.push('int ff(int i){return i+i;}')
50 >>> t.push('.bash echo Hello ')
53 >>> t.push(' \t .bash \t echo Hello ')
57 >>> t.push('echo Hello')
63 if line ==
"%s;"%fcnName
or line == fcnName:
65 elif _cppDcl.match(line)
and self.
cell ==
"":
67 elif _cppAclic.match(line)
and self.
cell ==
"":
69 elif _bash.match(line)
and self.
cell ==
"":
70 self.
cell += line.replace(
".bash",
"")+
"\n"
81 utils.declareCppCode(self.
cell)
84 utils.invokeAclic(self.
cell)
87 cellNoEndNewLine = self.
cell[:-1]
88 out = utils._checkOutput(cellNoEndNewLine,
"Error running shell command")
89 if out: sys.stdout.write(out)
92 utils.processCppCode(self.
cell)
98 cppcompleter.unload_ipython_extension(ip)
100 display.display_javascript(utils.jsDefaultHighlight.format(mimeType = utils.ipyMIME), raw=
True)
101 print(
"Notebook is in Python mode")
106 ipython.input_splitter.logical_line_transforms.remove(_transformer)
107 ipython.input_transformer_manager.logical_line_transforms.remove(_transformer)
110 ipython.input_splitter.logical_line_transforms.insert(0,_transformer)
111 ipython.input_transformer_manager.logical_line_transforms.insert(0,_transformer)