-
-
Notifications
You must be signed in to change notification settings - Fork 205
catch malformed Pattern #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
catch malformed Pattern #1341
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,9 @@ | |
| Integer, | ||
| Rational, | ||
| Real, | ||
| SymbolFalse, | ||
| SymbolList, | ||
| SymbolTrue, | ||
| ) | ||
| from mathics.core.rules import Rule | ||
| from mathics.core.pattern import Pattern, StopGenerator | ||
|
|
@@ -451,6 +453,9 @@ class PatternTest(BinaryOperator, PatternObject): | |
| = True | ||
| >> MatchQ[-3, _Integer?(#>0&)] | ||
| = False | ||
| >> MatchQ[3, Pattern[3]] | ||
| : First element in pattern Pattern[3] is not a valid pattern name. | ||
| = False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmatera Here is what I get when I try running this in mathics When I run through test, I don't have a problem thought. Do you know what's up here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this error in the current master branch. The patch in this PR catches the exception producing a message
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This weird, and I don't understand. I just tried again, looking for this kind of problem of mismatched versions, and I removed any cythonized files and I still get the same thing. When you do the same thing you don't get a traceback to falls through to the top-level? |
||
| """ | ||
|
|
||
| operator = "?" | ||
|
|
@@ -660,16 +665,23 @@ class MatchQ(Builtin): | |
| = False | ||
| >> MatchQ[_Integer][123] | ||
| = True | ||
| >> MatchQ[3, Pattern[3]] | ||
| : First element in pattern Pattern[3] is not a valid pattern name. | ||
| = False | ||
| """ | ||
|
|
||
| rules = {"MatchQ[form_][expr_]": "MatchQ[expr, form]"} | ||
|
|
||
| def apply(self, expr, form, evaluation): | ||
| "MatchQ[expr_, form_]" | ||
|
|
||
| if match(expr, form, evaluation): | ||
| return Symbol("True") | ||
| return Symbol("False") | ||
| try: | ||
| if match(expr, form, evaluation): | ||
| return SymbolTrue | ||
| return SymbolFalse | ||
| except PatternError as e: | ||
| evaluation.message(e.name, e.tag, *(e.args)) | ||
| return SymbolFalse | ||
|
|
||
|
|
||
| class Verbatim(PatternObject): | ||
|
|
@@ -786,6 +798,7 @@ class Pattern_(PatternObject): | |
| "nodef": ( | ||
| "No default setting found for `1` in " "position `2` when length is `3`." | ||
| ), | ||
| "argr": "Pattern called with 1 argument; 2 arguments are expected.", | ||
| } | ||
|
|
||
| rules = { | ||
|
|
@@ -801,10 +814,13 @@ class Pattern_(PatternObject): | |
| } | ||
|
|
||
| def init(self, expr): | ||
| super(Pattern_, self).init(expr) | ||
| self.varname = expr.leaves[0].get_name() | ||
| if self.varname is None: | ||
| if len(expr.leaves) != 2: | ||
| self.error("patvar", expr) | ||
| varname = expr.leaves[0].get_name() | ||
| if varname is None or varname == "": | ||
| self.error("patvar", expr) | ||
| super(Pattern_, self).init(expr) | ||
| self.varname = varname | ||
| self.pattern = Pattern.create(expr.leaves[1]) | ||
|
|
||
| def __repr__(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.