Strip trailing binary operators
AbandonedPublic

Authored by yurchor on May 4 2020, 4:04 PM.

Details

Reviewers
cfeck
davidhurka
Summary

Adopt Mathematica way to translate even erroneous commands

BUG: 420671

Test Plan

Create Cartesian plot with 'f(x)=x+', 'f(x)=x*', 'f(x)=x/', 'f(x)=x^'

Diff Detail

Repository
R334 KmPlot
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 26339
Build 26357: arc lint + arc unit
yurchor created this revision.May 4 2020, 4:04 PM
Restricted Application added a project: KDE Edu. · View Herald TranscriptMay 4 2020, 4:04 PM
Restricted Application added a subscriber: kde-edu. · View Herald Transcript
yurchor requested review of this revision.May 4 2020, 4:04 PM
yurchor updated this revision to Diff 81914.May 4 2020, 4:06 PM

Add minus

Thanks for working on this. While this is an improvement, this solution is not what I had in mind. I think if the user enters a syntactically invalid expression, it should be recognized as syntax error.

My bug was titled “KmPlot plots another function instead”. With this fix, the function is usually more close to what the user wanted, but it is still not the entered function. I don’t think there is any way to fix a mathematic expression.

yurchor abandoned this revision.May 5 2020, 7:05 AM

Abandoned until someone implements Turing full parser.

Wouldn’t it be possible to check whether there are trailing binary operators, and then append something that reliably causes a syntax error in Mathematica?

Wouldn’t it be possible to check whether there are trailing binary operators, and then append something that reliably causes a syntax error in Mathematica?

I think that it breaks the whole concept of the current parser. For example, the input "sfgs" is marked as an error, but when you type "sin" (without an argument) it's Ok. The whole parser should be rewritten in the LabPlot2 style to make such things possible.

cfeck added a comment.May 5 2020, 12:02 PM

The problem is that the original author wanted input errors to be visible while typing.

If you check the expression after hitting Enter, you can detect more errors.

The problem is that the original author wanted input errors to be visible while typing.

If you check the expression after hitting Enter, you can detect more errors.

Sure, but such checks need a strict syntax and a new parser, imho.

The problem is that the original author wanted input errors to be visible while typing.

That makes sense. It actually works, so it works.

If you check the expression after hitting Enter, you can detect more errors.

That also already works. When you do not match an ( with a ), the expression is not accepted at Enter.

Currently I understand it that some parser function inside KmPlot parses the expression to a token stream, which is then passed to Mathematica. The parser requires matching brackets, so it could also require right arguments for binary operators, couldn’t it?

To me as a user it looks like the parser works in general, and it is fairly complex code, so I think we don’t need to replace it with a new parser. I don’t know the parser of LabPlot2. If it could be a drop-in replacement, hmm...

It appears that binary expressions are matched in heir0() to heir5() functions. Their logical structure is too complicated to understand it quickly, but I think one of these doesn’t monitor which operator makes sense now.

Currently I understand it that some parser function inside KmPlot parses the expression to a token stream, which is then passed to Mathematica.

No, sorry for misguiding. I meant that the Mathematica/Wolfram Alpha parser can produce any possible result from user input, not that we use Wolfram Mathematica.

Probably, this "fuzzy" parsing and trying to build everything you might input attracts me in KmPlot the most. Just tried to build "f(x)=cos /2". ;)