Skip to content

Commit 60a519d

Browse files
committed
Sandbox DumpParse tests...
and add a return value to DumpParse
1 parent 091d172 commit 60a519d

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

mathics/builtin/files_io/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ class DumpParse(Builtin):
237237
a Pickle file $output$. $True$ is returned if everthing want okay.
238238
</dl>
239239
240-
>> DumpParse["BoolEval/BoolEval.m", "/tmp/BoolEval.mx3"]
241-
= ...
240+
>S dumpParsedFile = FileNameJoin[{$TemporaryDirectory, "BoolEval.mx3"}]
241+
>S DumpParse["BoolEval/BoolEval.m", dumpParsedFile]
242+
= True
243+
#> Clear[dumpParsedFile]
242244
"""
243245

244246
options = {

mathics/core/parser/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@
1313
from mathics.core.parser.convert import convert
1414
from mathics.core.parser.feed import MathicsSingleLineFeeder
1515
from mathics.core.parser.parser import Parser
16-
from mathics.core.symbols import Symbol, ensure_context
16+
from mathics.core.symbols import Symbol, SymbolTrue, ensure_context
17+
from mathics.core.systemsymbols import SymbolFailed
1718

1819
parser = Parser()
1920

2021

21-
def dump_exprs_to_pcl_file(exprs, pickle_file: str) -> Optional[str]:
22+
def dump_exprs_to_pcl_file(exprs, pickle_file: str) -> Symbol:
2223
"""
2324
Parse input from `feeder` and pickle serialize the parsed M-expression Python written
2425
to pickle_file.
2526
Serializes a Mathics3 AST Node to a file `pickle_file` using Python pickle.
27+
28+
Return SymbolTrue if things went okay.
2629
"""
2730
# Open the file in binary write mode
2831
with open(pickle_file, "wb") as f:
2932
# Protocol -1 uses the highest available binary protocol for efficiency
3033
pickle.dump(exprs, f, protocol=pickle.HIGHEST_PROTOCOL)
34+
return SymbolTrue
3135

3236

3337
def parse(definitions, feeder: LineFeeder) -> Optional[BaseElement]:
@@ -99,7 +103,7 @@ def parse_returning_code(
99103
return converted, source_text
100104

101105

102-
def parse_dump_to_pcl_file(feeder: LineFeeder, pickle_file: str) -> Optional[str]:
106+
def parse_dump_to_pcl_file(feeder: LineFeeder, pickle_file: str) -> Symbol:
103107
"""
104108
Parse input from `feeder` and pickle serialize the parsed M-expression Python written
105109
to pickle_file.
@@ -108,7 +112,7 @@ def parse_dump_to_pcl_file(feeder: LineFeeder, pickle_file: str) -> Optional[str
108112
ast = parser.parse(feeder)
109113

110114
if ast is None:
111-
return None
115+
return SymbolFailed
112116
# Ensure the input is actually a Node (optional safety check)
113117
if not isinstance(ast, ASTNode):
114118
raise TypeError(f"Expected mathics.core.parser.ast.Node, got {type(ast)}")
@@ -117,6 +121,7 @@ def parse_dump_to_pcl_file(feeder: LineFeeder, pickle_file: str) -> Optional[str
117121
with open(pickle_file, "wb") as f:
118122
# Protocol -1 uses the highest available binary protocol for efficiency
119123
pickle.dump(ast, f, protocol=pickle.HIGHEST_PROTOCOL)
124+
return SymbolTrue
120125

121126

122127
def parse_from_pcl_file(definitions, pickle_file: str):

0 commit comments

Comments
 (0)