toonarmycaptain / toonarmycaptain/parseplot
Parser does not recognise form 'nx'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Parser does not recognise expressions or parts with the form nx where n is an integer/float.
Expressions taking form n*x evaluate fine.
expression 2x:
>>> p = parseplot.Parser('2x')
>>> p.plot(-5, 5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/parseplot/parse/parser.py", line 29, in plot
xy = (x, self._parser.evaluate(self._function))
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/plusminus/plusminus.py", line 853, in evaluate
parsed = self.parse(arith_expression, parseAll=True)
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/plusminus/plusminus.py", line 845, in parse
parsed = self.get_parser().parseString(*args, **kwargs)
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found 'x' (at char 1), (line:1, col:2)
>>> p = parseplot.Parser('2*x')
>>> p.plot(-5, 5)
[(-5, -10), (-4, -8), (-3, -6), (-2, -4), (-1, -2), (0, 0), (1, 2), (2, 4), (3, 6), (4, 8), (5, 10)]
expression x^3 + 4x -5
>>> p = parseplot.Parser('x^3+4x-5')
>>> p.plot(-5, 5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/parseplot/parse/parser.py", line 29, in plot
xy = (x, self._parser.evaluate(self._function))
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/plusminus/plusminus.py", line 853, in evaluate
parsed = self.parse(arith_expression, parseAll=True)
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/plusminus/plusminus.py", line 845, in parse
parsed = self.get_parser().parseString(*args, **kwargs)
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/home/toonarmycaptain/PycharmProjects/parseplot/test_install_env/lib/python3.9/site-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected end of text, found 'x' (at char 6), (line:1, col:7)
>>> p = parseplot.Parser('x^3+4*x-5')
>>> p.plot(-5, 5)
[(-5, -150), (-4, -85), (-3, -44), (-2, -21), (-1, -10), (0, -5), (1, 0), (2, 11), (3, 34), (4, 75), (5, 140)]
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two failing expressions and their working n*x equivalents through parseplot.Parser.plot, then inspect the parse/parser.py entry point named in the traceback and the underlying plusminus parsing call. Done means forms such as 2x and x^3+4x-5 parse and evaluate like their explicit-multiplication equivalents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100