error reporting now reports accurately to the line.

This commit is contained in:
Brad Arant 2024-11-26 11:17:22 -08:00
parent 79d68d6c34
commit e3d788bc92
6 changed files with 23 additions and 8 deletions

View File

@ -165,7 +165,7 @@ namespace jet {
formdata.goeol();
}
else
throw coreutils::Exception("expecting closing double quote on vairable name in received CGI data.");
throw coreutils::Exception("expecting closing double quote on variable name in received CGI data.");
} else
throw coreutils::Exception("expecting name subfield in received CGI data.");
} else

View File

@ -27,6 +27,7 @@ namespace jet {
void outputHeaders();
void setupFormData(coreutils::ZString &formdata);
void setupFormURLEncoded(coreutils::ZString &formdata);
char *errorCursor = NULL;
std::map<coreutils::MString, coreutils::MString> variables;
std::map<coreutils::MString, coreutils::MString> cgiVariables;

10
Tag.cpp
View File

@ -31,6 +31,7 @@ namespace jet {
Tag::Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, coreutils::ZString splitTagName)
: ZString(in), parentOut(parentOut), global(global), parent(parent) {
this->splitTagName = splitTagName;
global.errorCursor = in.getCursor();
if(parent && in.ifNext("<")) {
name = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!");
if(in.startsWith(" ") || in.startsWith("/") || in.startsWith(">")) {
@ -196,15 +197,14 @@ namespace jet {
in.ifNext("/>");
continue;
} else {
out.write(in.charAt(0));
in.nextChar();
out.write(in.nextChar());
continue;
}
} else if(in.startsWith("$[") || in.startsWith("#[")) {
} else if(in.startsWith("$[") || in.startsWith("#[")) {
global.errorCursor = in.getCursor();
out.write(global.getVariable(in, variables));
} else {
out.write(in.charAt(0));
in.nextChar();
out.write(in.nextChar());
}
}
}

View File

@ -3,6 +3,8 @@
#include "Tag.h"
#include "ZString.h"
#include "MString.h"
#include <map>
namespace jet {
@ -10,6 +12,8 @@ namespace jet {
public:
__tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent);
std::map<coreutils::MString, coreutils::MString> tags;
};

View File

@ -16,16 +16,23 @@ int main(int argc, char **argv, char **envp) {
try {
coreutils::MString out;
data.reset();
global.errorCursor = data.getCursor();
jet::__jet *jet = new jet::__jet(data, out, global, NULL);
delete jet;
global.outputHeaders();
std::cout << out;
}
catch(coreutils::Exception e) {
data.setCursor(global.errorCursor);
data.moveBackToLineStart();
std::cout << "-----------------------------" << std::endl;
std::cout << "Error in jet script '" << argv[1] << "' at line " << data.getLineNumberAtCursor() << std::endl;
std::cout << "Error text: " << e.text << std::endl;
std::cout << "-----------------------------" << std::endl;
std::cout << data.parsed() << std::endl;
std::cout << "******** Error caught: " << e.text << std::endl;
std::cout << data.unparsed() << std::endl;
std::cout << "Error caught: " << e.text << std::endl;
global.dump();
}

View File

@ -10,6 +10,8 @@
$[modified1;$[tohex]]
<set name="complete" value="$[modified1];$[tohex]" />
$[complete]
<set name="" value="xxx" />
the unnamed variable value: [$[]]
---
$[nonexistant]
$[%HOME]
@ -21,7 +23,8 @@
<set name="division" expr="5/3" />
<set name="divisor" value="8" />
<set name="nested" expr="(2*(4+4)/$[divisor])*32" />
$[nested]
<set name="error" value="$[$x]" />
$[$nested]
<set name="numbers">0123456789</set>
<set name="lefty" expr="LEFT($[numbers],5)" />
lefty=[$[lefty]]