|
wxMaxima
|
Finds where in a code cell a Maxima syntax error is (GH #289). More...
#include <wx/string.h>#include <optional>Go to the source code of this file.
Data Structures | |
| struct | wxm::TextRange |
| A range of characters in a cell's text: [start, end) More... | |
Functions | |
| std::optional< wxString > | wxm::SyntaxErrorEcho (const wxString &maximaOutput) |
| The line Maxima echoes under its first "incorrect syntax:" message. | |
| std::optional< TextRange > | wxm::LocateSyntaxError (const wxString &maximaOutput, const wxString &cellText, TextRange statement) |
| Where in a cell the syntax error Maxima reported is. | |
Finds where in a code cell a Maxima syntax error is (GH #289).
wxMaxima sends a cell to Maxima one statement at a time, so it always knows which statement an error belongs to. For a syntax error Maxima also tells where in that statement it gave up – but only as text, for a human: its parser (mread-synerr in Maxima's nparse.lisp) prints
incorrect syntax: , is not a prefix operator f(a,, ^
i.e. the message, then the last (up to 20) characters of the current line it has read, then a caret. The second line ends where the parser stopped reading, which is at, or one character after, the offending token.
This file reads that text and finds the same characters in the statement. It deliberately changes nothing in Maxima and hooks none of its functions: it only reads what Maxima prints anyway, the same way wxMaxima already recognises an error at all by the words "incorrect syntax". If a future Maxima prints something else, LocateSyntaxError() finds nothing, and the worksheet falls back to marking the whole statement.
Two quirks of real Maxima versions are handled:
GUI-free, so test_SyntaxErrorLocation can pin it directly.
| std::optional< TextRange > wxm::LocateSyntaxError | ( | const wxString & | maximaOutput, |
| const wxString & | cellText, | ||
| TextRange | statement | ||
| ) |
| std::optional< wxString > wxm::SyntaxErrorEcho | ( | const wxString & | maximaOutput | ) |
The line Maxima echoes under its first "incorrect syntax:" message.
| maximaOutput | Everything Maxima printed in reply to one statement. |