1414
1515from pygments import highlight
1616from pygments .lexers import MathematicaLexer
17+
1718mma_lexer = MathematicaLexer ()
1819
1920from mathicsscript .version import __version__
2021
22+
2123def format_output (obj , expr , format = None ):
2224 if format is None :
2325 format = obj .format
@@ -28,7 +30,7 @@ def format_output(obj, expr, format=None):
2830 from mathics .core .expression import Expression , BoxError
2931
3032 expr_type = expr .get_head_name ()
31- if expr_type == "System`MathMLForm" :
33+ if expr_type == "System`MathMLForm" :
3234 format = "xml"
3335 leaves = expr .get_leaves ()
3436 if len (leaves ) == 1 :
@@ -39,21 +41,17 @@ def format_output(obj, expr, format=None):
3941 if len (leaves ) == 1 :
4042 expr = leaves [0 ]
4143 elif expr_type == "System`Graphics" :
42- result = Expression (
43- 'StandardForm' , expr ).format (obj , 'System`MathMLForm' )
44+ result = Expression ("StandardForm" , expr ).format (obj , "System`MathMLForm" )
4445 ml_str = result .leaves [0 ].leaves [0 ]
4546 # FIXME: not quite right. Need to parse out strings
4647 display_svg (str (ml_str ))
4748
48-
49- if format == 'text' :
50- result = expr .format (obj , 'System`OutputForm' )
51- elif format == 'xml' :
52- result = Expression (
53- 'StandardForm' , expr ).format (obj , 'System`MathMLForm' )
54- elif format == 'tex' :
55- result = Expression ('StandardForm' , expr ).format (
56- obj , 'System`TeXForm' )
49+ if format == "text" :
50+ result = expr .format (obj , "System`OutputForm" )
51+ elif format == "xml" :
52+ result = Expression ("StandardForm" , expr ).format (obj , "System`MathMLForm" )
53+ elif format == "tex" :
54+ result = Expression ("StandardForm" , expr ).format (obj , "System`TeXForm" )
5755 else :
5856 raise ValueError
5957
@@ -63,10 +61,12 @@ def format_output(obj, expr, format=None):
6361 boxes = None
6462 if not hasattr (obj , "seen_box_error" ):
6563 obj .seen_box_error = True
66- obj .message ('General' , 'notboxes' ,
67- Expression ('FullForm' , result ).evaluate (obj ))
64+ obj .message (
65+ "General" , "notboxes" , Expression ("FullForm" , result ).evaluate (obj )
66+ )
6867 return boxes
6968
69+
7070Evaluation .format_output = format_output
7171
7272
@@ -96,14 +96,14 @@ def out(self, out):
9696 "--persist" ,
9797 default = False ,
9898 required = False ,
99- is_flag = True ,
99+ is_flag = True ,
100100 help = "go to interactive shell after evaluating FILE or -e" ,
101101)
102102@click .option (
103103 "--quiet" ,
104104 "-q" ,
105105 default = False ,
106- is_flag = True ,
106+ is_flag = True ,
107107 required = False ,
108108 help = "don't print message at startup" ,
109109)
@@ -148,25 +148,16 @@ def out(self, out):
148148 "--style" ,
149149 metavar = "PYGMENTS-STYLE" ,
150150 type = str ,
151- help = (
152- "Set pygments style. Use 'None' if you do not want any pygments styling."
153- ),
151+ help = ("Set pygments style. Use 'None' if you do not want any pygments styling." ),
154152 required = False ,
155153)
156154@click .option (
157155 "--pygments-tokens/--no-pygments-tokens" ,
158156 default = False ,
159- help = (
160- "Show pygments tokenization of output."
161- ),
162- required = False ,
163- )
164- @click .argument (
165- "file" ,
166- nargs = 1 ,
167- type = click .Path (readable = True ),
157+ help = ("Show pygments tokenization of output." ),
168158 required = False ,
169159)
160+ @click .argument ("file" , nargs = 1 , type = click .Path (readable = True ), required = False )
170161def main (
171162 full_form ,
172163 persist ,
@@ -192,20 +183,11 @@ def main(
192183 if pyextensions :
193184 for ext in pyextensions :
194185 extension_modules .append (ext )
195- else :
196- from mathics .settings import default_pymathics_modules
197186
198- extension_modules = default_pymathics_modules
199-
200- definitions = Definitions (add_builtin = True , extension_modules = extension_modules )
187+ definitions = Definitions (add_builtin = True )
201188 definitions .set_line_no (0 )
202189
203- shell = TerminalShell (
204- definitions ,
205- style ,
206- readline ,
207- completion ,
208- )
190+ shell = TerminalShell (definitions , style , readline , completion )
209191
210192 if initfile :
211193 feeder = FileLineFeeder (initfile )
@@ -215,7 +197,7 @@ def main(
215197 shell .definitions ,
216198 output = TerminalOutput (shell ),
217199 catch_interrupt = False ,
218- format = "text" ,
200+ format = "text" ,
219201 )
220202 query = evaluation .parse_feeder (feeder )
221203 if query is None :
@@ -229,8 +211,9 @@ def main(
229211 if execute :
230212 for expr in execute :
231213 print (shell .get_in_prompt () + expr )
232- evaluation = Evaluation (shell .definitions ,
233- output = TerminalOutput (shell ), format = "text" )
214+ evaluation = Evaluation (
215+ shell .definitions , output = TerminalOutput (shell ), format = "text"
216+ )
234217 result = evaluation .parse_evaluate (expr , timeout = settings .TIMEOUT )
235218 shell .print_result (result , debug_pygments = pygments_tokens )
236219
@@ -245,7 +228,7 @@ def main(
245228 shell .definitions ,
246229 output = TerminalOutput (shell ),
247230 catch_interrupt = False ,
248- format = "text" ,
231+ format = "text" ,
249232 )
250233 query = evaluation .parse_feeder (feeder )
251234 if query is None :
@@ -272,24 +255,23 @@ def main(
272255
273256 TeXForm = Symbol ("System`TeXForm" )
274257
275-
276258 while True :
277259 try :
278260 if shell .using_readline :
279261 import readline as GNU_readline
262+
280263 last_pos = GNU_readline .get_current_history_length ()
281264 evaluation = Evaluation (shell .definitions , output = TerminalOutput (shell ))
282265 query , source_code = evaluation .parse_feeder_returning_code (shell )
283266 if shell .using_readline :
284267 current_pos = GNU_readline .get_current_history_length ()
285- for pos in range (last_pos , current_pos - 1 ):
268+ for pos in range (last_pos , current_pos - 1 ):
286269 GNU_readline .remove_history_item (pos )
287270 GNU_readline .add_history (source_code .rstrip ())
288271
289272 if query is None :
290273 continue
291274
292-
293275 if hasattr (query , "head" ) and query .head == TeXForm :
294276 output_style = "//TeXForm"
295277 else :
0 commit comments