Skip to content

Commit 6775878

Browse files
committed
Get PyMathics minimally working
Works for both pymathics-hello and pymathics-natlang However pattern parsing is a little funky and should be improved.
1 parent d1d3b43 commit 6775878

File tree

18 files changed

+362
-2358
lines changed

18 files changed

+362
-2358
lines changed

mathics/builtin/base.py

Lines changed: 175 additions & 105 deletions
Large diffs are not rendered by default.

mathics/core/definitions.py

Lines changed: 171 additions & 118 deletions
Large diffs are not rendered by default.

mathics/core/expression.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ def valid_context_name(ctx, allow_initial_backquote=False) -> bool:
3333
(allow_initial_backquote or not ctx.startswith('`')))
3434

3535

36-
def ensure_context(name) -> str:
36+
def ensure_context(name, context="System`") -> str:
3737
assert isinstance(name, str)
3838
assert name != ''
3939
if '`' in name:
4040
# Symbol has a context mark -> it came from the parser
4141
assert fully_qualified_symbol_name(name)
4242
return name
4343
# Symbol came from Python code doing something like
44-
# Expression('Plus', ...) -> use System`
45-
return 'System`' + name
44+
# Expression('Plus', ...) -> use System` or more generally
45+
# context + name
46+
return context + name
4647

4748

4849
def strip_context(name) -> str:

mathics/core/parser/util.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ def lookup_name(self, name):
4444
return ensure_context(name)
4545

4646

47-
def parse_builtin_rule(string):
47+
class PyMathicsDefinitions(object):
48+
"""
49+
Dummy Definitions object that puts every unqualified symbol in
50+
PyMathics`.
51+
"""
52+
def lookup_name(self, name):
53+
assert isinstance(name, str)
54+
return ensure_context(name, "PyMathics`")
55+
56+
57+
def parse_builtin_rule(string, definitions=SystemDefinitions()):
4858
'''
4959
Parse rules specified in builtin docstrings/attributes. Every symbol
5060
in the input is created in the System` context.
5161
'''
52-
return parse(SystemDefinitions(), SingleLineFeeder(string, '<builtin_rules>'))
62+
return parse(definitions, SingleLineFeeder(string, '<builtin_rules>'))

pymathics/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

pymathics/Makefile

Lines changed: 0 additions & 34 deletions
This file was deleted.

pymathics/README.rst

Lines changed: 0 additions & 16 deletions
This file was deleted.

pymathics/doc/.placeholder

Whitespace-only changes.

pymathics/doc/documentation/.placeholder

Whitespace-only changes.

pymathics/doc/tex/.placeholder

Whitespace-only changes.

0 commit comments

Comments
 (0)