Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# THis is an EditorConfig file
# This is an EditorConfig file
# https://EditorConfig.org

root = true
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/consistency-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ jobs:
run: |
sudo apt update -qq && sudo apt install llvm-dev remake
python -m pip install --upgrade pip
pip install -e .
# We can comment out after next Mathics-Scanner release
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# git clone https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner/
# pip install -e .
# cd ..
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
pip install -e .

- name: Install Mathics with minimum dependencies
run: |
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ jobs:
cd stopit/
pip install -e .
cd ..
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# We can comment out after next Mathics-Scanner release
git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
cd mathics-scanner/
pip install -e .
cd ..
# python -m pip install Mathics-Scanner[full]
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
pip install -e .
remake -x develop-full
- name: Test Mathics3
run: |
Expand Down
22 changes: 9 additions & 13 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ jobs:
run: |
sudo apt update -qq && sudo apt install llvm-dev remake
python -m pip install --upgrade pip
pip install -e .
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# We can comment out after next Mathics-Scanner release
# git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner/
# pip install -e .
# cd ..

- name: Install Mathics with minimum dependencies
run: |
make develop
- name: Run mypy
run: |
pip install mypy==1.13 sympy==1.12
git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# Adjust below for right branch
git clone --depth 1 --branch mini-tweaks https://github.com/Mathics3/mathics-scanner.git
cd mathics-scanner/
pip install -e .
bash ./admin-tools/make-JSON-tables.sh
pip install -e .
cd ..
touch ./mathics-scanner/mathics_scanner/py.typed
pip install ./mathics-scanner/
mypy --install-types --non-interactive mathics
make develop
mypy --install-types --ignore-missing-imports --non-interactive mathics
8 changes: 1 addition & 7 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ jobs:
run: |
python -m pip install --upgrade pip
# We can comment out after next Mathics-Scanner release
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
cd src/mathics-scanner/
pip install -e .
python -m mathics_scanner.generate.build_tables
cd ../..
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
- name: Run Mathics3 Combinatorica tests
run: |
git submodule init
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pyodide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ jobs:
pip install "setuptools>=70.0.0" PyYAML click packaging pytest

# We can comment out after next Mathics-Scanner release
# git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner/
python -m pip install --no-build-isolation -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner
# pip install --no-build-isolation -e .
# cd ..

Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/ubuntu-cython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ jobs:
pip install -e .
cd ..
# We can comment out after next Mathics-Scanner release
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner/
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
pip install -e .
cd ..

Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ jobs:
pip install -e .
cd ..
# We can comment out after next Mathics-Scanner release
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner/
# pip install -e .
# python -m mathics_scanner.generate.build_tables
# cd ..

python -m pip install Mathics-Scanner[full]
# python -m pip install Mathics-Scanner[full]
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
pip install -e .
remake -x develop-full
- name: Test Mathics
run: |
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ jobs:
pip install -e .
cd ..
# We can comment out after next Mathics-Scanner release
# python -m pip install -e git+https://github.com/Mathics3/mathics-scanner#egg=Mathics-Scanner[full]
# git clone --depth 1 https://github.com/Mathics3/mathics-scanner.git
# git clone --single-branch --branch operator-refactor-part1.5 https://github.com/Mathics3/mathics-scanner.git
# cd mathics-scanner
# pip install -e .
# python -m mathics_scanner.generate.build_tables
# cd ..
python -m pip install -e git+https://github.com/Mathics3/mathics-scanner@mini-tweaks#egg=Mathics-Scanner[full]
pip install -e .

# python -m pip install Mathics-Scanner[full]
Expand Down
20 changes: 12 additions & 8 deletions mathics/builtin/atomic/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from heapq import heappop, heappush
from typing import Any, List

from mathics_scanner import TranslateError
from mathics_scanner.errors import TranslateError, TranslateErrorNew

from mathics.core.atoms import Integer, Integer0, Integer1, String
from mathics.core.attributes import A_LISTABLE, A_PROTECTED
Expand All @@ -20,7 +20,9 @@
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.parser import MathicsFileLineFeeder, parse
from mathics.core.parser import MathicsFileLineFeeder
from mathics.core.parser.convert import convert
from mathics.core.parser.util import parser
from mathics.core.systemsymbols import (
SymbolFailed,
SymbolInputForm,
Expand Down Expand Up @@ -788,7 +790,7 @@ class ToExpression(Builtin):
def eval(self, seq, evaluation: Evaluation):
"ToExpression[seq__]"

# Organise Arguments
# From `seq`, extract `inp`, `form`, and `head`.
py_seq = seq.get_sequence()
if len(py_seq) == 1:
(inp, form, head) = (py_seq[0], SymbolInputForm, None)
Expand All @@ -808,6 +810,7 @@ def eval(self, seq, evaluation: Evaluation):
)
return

result = None
# Apply the different forms
if form is SymbolInputForm:
if isinstance(inp, String):
Expand All @@ -819,13 +822,14 @@ def eval(self, seq, evaluation: Evaluation):
feeder = MathicsFileLineFeeder(f)
while not feeder.empty():
try:
query = parse(evaluation.definitions, feeder)
except TranslateError:
ast = parser.parse(feeder)
except (TranslateError, TranslateErrorNew):
return SymbolFailed
finally:
feeder.send_messages(evaluation)
if query is None: # blank line / comment
if ast is None: # blank line / comment
continue
query = convert(ast, evaluation.definitions)
result = query.evaluate(evaluation)

else:
Expand All @@ -835,8 +839,8 @@ def eval(self, seq, evaluation: Evaluation):
return

# Apply head if present
if head is not None:
result = Expression(head, result).evaluate(evaluation)
if head is not None and result is not None:
return Expression(head, result).evaluate(evaluation)

return result

Expand Down
12 changes: 7 additions & 5 deletions mathics/builtin/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,26 +560,28 @@ def get_msg_list(expr):
evaluation.set_quiet_messages(old_quiet_messages)


# Consider removing. If this was this added just to test some expressions,
# this should be done in pytests instead.
class Syntax(Builtin):
r"""
<url>:WMA link:https://reference.wolfram.com/language/ref/Syntax.html</url>
<url>:WMA link:https://reference.wolfram.com/language/guide/Syntax.html</url>

<dl>
<dt>'Syntax'
<dd>is a symbol to which all syntax messages are assigned.
</dl>

>> 1 +
: Incomplete expression; more input is needed (line 1 of "<test>").
: Incomplete expression; more input is needed (line 1 of "<test-Syntax-1>").

>> Sin[1)
: "Sin[1" cannot be followed by ")" (line 1 of "<test>").
: "Sin[1" cannot be followed by ")" (line 1 of "<test-Syntax-2>").

>> ^ 2
: Expression cannot begin with "^ 2" (line 1 of "<test>").
: Expression cannot begin with "^ 2" (line 1 of "<test-Syntax-3>").

>> 1.5``
: "1.5`" cannot be followed by "`" (line 1 of "<test>").
: "1.5`" cannot be followed by "`" (line 1 of "<test-Syntax-4>").
"""

# Extension: WMA does not provide lineno and filename in its error messages
Expand Down
8 changes: 4 additions & 4 deletions mathics/builtin/testing_expressions/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re

from mathics_scanner import SingleLineFeeder, TranslateError
from mathics_scanner import SingleLineFeeder, TranslateError, TranslateErrorNew

from mathics.builtin.atomic.strings import anchor_pattern
from mathics.core.atoms import Integer1, String
Expand All @@ -13,7 +13,7 @@
from mathics.core.convert.regex import to_regex
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.parser.util import parse
from mathics.core.parser.util import parser
from mathics.core.symbols import Symbol, SymbolFalse, SymbolTrue
from mathics.core.systemsymbols import SymbolStringExpression, SymbolStringMatchQ
from mathics.eval.strings import eval_StringContainsQ
Expand Down Expand Up @@ -280,8 +280,8 @@ def eval(self, string, evaluation: Evaluation):

feeder = SingleLineFeeder(string.value)
try:
parse(evaluation.definitions, feeder)
except TranslateError:
parser.parse(feeder)
except (TranslateError, TranslateErrorNew):
return SymbolFalse
else:
return SymbolTrue
2 changes: 1 addition & 1 deletion mathics/core/convert/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def to_sympy_matrix(data, **kwargs) -> Optional[sympy.MutableDenseMatrix]:
return None


class SympyExpression(BasicSympy):
class SympyExpression(sympy.Expr):
"""A Sympy expression with an associated Mathics expression"""

is_Function = True
Expand Down
12 changes: 8 additions & 4 deletions mathics/core/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from abc import ABC
from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload

from mathics_scanner import TranslateError
from mathics_scanner.errors import IncompleteSyntaxError, InvalidSyntaxError, ScanError

from mathics import settings
from mathics.core.atoms import Integer, String
Expand Down Expand Up @@ -161,16 +161,20 @@ def parse_feeder_returning_code_and_messages(self, feeder) -> tuple:
Parse a single expression from feeder, print the messages it produces and
return the result, the source code for this and evaluated
messages created in evaluation.

If there was a TranslateError, the source code returned is "" and the result is None.
"""
from mathics.core.parser.util import parse_returning_code

try:
result, source_code = parse_returning_code(self.definitions, feeder)
except TranslateError:
except (InvalidSyntaxError, IncompleteSyntaxError, ScanError):
result = None
source_code = ""

if result is None:
self.recursion_depth = 0
self.stopped = False
source_code = ""
result = None
messages = feeder.send_messages(self)
return result, source_code, messages

Expand Down
4 changes: 2 additions & 2 deletions mathics/core/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def parse_binary(self, expr1, token, expr1_precedence: int) -> Node:

# handle nonassoc operators
if tag in nonassoc_binary_ops and expr1.get_head_name() == tag and not expr1.parenthesised:
self.tokeniser.sntx_message(token.pos)
raise InvalidSyntaxError()
tag, pre_error, post_error = self.tokeniser.sntx_message(token.pos)
raise InvalidSyntaxError(tag, pre_error, post_error)

result = Node(tag, expr1, expr2) # construct the result: `BINARY[expr1, expr2]`

Expand Down
4 changes: 4 additions & 0 deletions mathics/core/parser/feed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from typing import List

from mathics_scanner import (
FileLineFeeder,
LineFeeder,
Expand All @@ -8,6 +10,8 @@


class MathicsLineFeeder(LineFeeder):
messages: List[str]

def send_messages(self, evaluation) -> list:
evaluated_messages = []
for message in self.messages:
Expand Down
Loading
Loading