wxMaxima
Loading...
Searching...
No Matches
Data Structures | Functions
SyntaxErrorLocation.h File Reference

Finds where in a code cell a Maxima syntax error is (GH #289). More...

#include <wx/string.h>
#include <optional>
Include dependency graph for SyntaxErrorLocation.h:
This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

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.

Function Documentation

◆ LocateSyntaxError()

std::optional< TextRange > wxm::LocateSyntaxError ( const wxString &  maximaOutput,
const wxString &  cellText,
TextRange  statement 
)

Where in a cell the syntax error Maxima reported is.

Parameters
maximaOutputEverything Maxima printed in reply to one statement.
cellTextThe text of the code cell the statement came from.
statementThe statement's characters in cellText.
Returns
The characters to mark: the token Maxima stopped at, plus the one character after it it may have read ahead. Nothing if Maxima did not report a syntax error, or the echoed text can't be found in the statement (for example because wxMaxima stripped a comment from it before sending it).

◆ SyntaxErrorEcho()

std::optional< wxString > wxm::SyntaxErrorEcho ( const wxString &  maximaOutput)

The line Maxima echoes under its first "incorrect syntax:" message.

Parameters
maximaOutputEverything Maxima printed in reply to one statement.
Returns
The echoed input line, exactly as Maxima printed it, or nothing if the output contains no complete syntax error report (the caret line is what tells that the echo is complete).