mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
Improved position reporting of script errors
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@931 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -59,20 +59,20 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
sp = new wxBoxSizer(wxVERTICAL);
|
||||
sp->Add(fixed, 0, wxEXPAND); sp->Show(fixed,false);
|
||||
wxSizer* s1 = new wxBoxSizer(wxVERTICAL);
|
||||
s1->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0);
|
||||
s1->Add(new wxStaticText(panel, wxID_ANY, _LABEL_("keyword")+_(":")), 0);
|
||||
s1->Add(keyword, 0, wxEXPAND | wxTOP, 2);
|
||||
s1->Add(new wxStaticText(panel, wxID_ANY, _("Mode:")), 0, wxTOP, 2);
|
||||
s1->Add(new wxStaticText(panel, wxID_ANY, _LABEL_("mode")+_(":")), 0, wxTOP, 2);
|
||||
s1->Add(mode, 0, wxEXPAND | wxTOP, 2);
|
||||
sp->Add(s1, 0, wxEXPAND | wxLEFT, 2);
|
||||
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
|
||||
wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
|
||||
s2->Add(new wxStaticText(panel, wxID_ANY, _("Match:")), 0);
|
||||
s2->Add(new wxStaticText(panel, wxID_ANY, _LABEL_("match")+_(":")), 0);
|
||||
s2->Add(match, 0, wxEXPAND | wxTOP, 2);
|
||||
s2->Add(add_param, 0, wxALIGN_LEFT | wxTOP, 2);
|
||||
sp->Add(s2, 0, wxEXPAND | wxLEFT, 2);
|
||||
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
|
||||
wxSizer* s3 = new wxBoxSizer(wxVERTICAL);
|
||||
s3->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0);
|
||||
s3->Add(new wxStaticText(panel, wxID_ANY, _LABEL_("reminder")+_(":")), 0);
|
||||
s3->Add(reminder, 1, wxEXPAND | wxTOP, 2);
|
||||
s3->Add(ref_param, 0, wxALIGN_LEFT | wxTOP, 2);
|
||||
s3->Add(errors, 0, wxEXPAND | wxTOP, 4);
|
||||
@@ -80,7 +80,7 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
sp->Add(s3, 1, wxEXPAND | wxLEFT, 2);
|
||||
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
|
||||
wxSizer* s4 = new wxBoxSizer(wxVERTICAL);
|
||||
s4->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0);
|
||||
s4->Add(new wxStaticText(panel, wxID_ANY, _LABEL_("rules")+_(":")), 0);
|
||||
s4->Add(rules, 1, wxEXPAND | wxTOP, 2);
|
||||
sp->Add(s4, 1, wxEXPAND | wxLEFT, 2);
|
||||
panel->SetSizer(sp);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# This file contains the keys expected to be in MSE locales
|
||||
# It was automatically generated by tools/locale/locale.pl
|
||||
# Generated on Sat May 31 21:42:09 2008
|
||||
# Generated on Sun Jun 1 02:54:59 2008
|
||||
|
||||
action:
|
||||
add control point: 0
|
||||
@@ -104,6 +104,7 @@ error:
|
||||
has no member value: 2
|
||||
images used for blending must have the same size: 0
|
||||
in function: 2
|
||||
in keyword reminder: 2
|
||||
in parameter: 2
|
||||
install packages successful: 1
|
||||
installing updates: 0
|
||||
@@ -291,6 +292,7 @@ label:
|
||||
reminder: 0
|
||||
remove package: 0
|
||||
result: 0
|
||||
rules: 0
|
||||
save changes: 1
|
||||
select cards print: 0
|
||||
select columns: 0
|
||||
|
||||
+20
-18
@@ -41,6 +41,7 @@ struct Token {
|
||||
TokenType type;
|
||||
String value;
|
||||
bool newline; ///< Is there a newline between this token and the previous one?
|
||||
size_t pos; ///< Start position of the token
|
||||
|
||||
inline bool operator == (TokenType t) const { return type == t; }
|
||||
inline bool operator != (TokenType t) const { return type != t; }
|
||||
@@ -92,7 +93,7 @@ class TokenIterator {
|
||||
stack<MoreInput> more; ///< Read tokens from here when we are done with the current input
|
||||
|
||||
/// Add a token to the buffer, with the current newline value, resets newline
|
||||
void addToken(TokenType type, const String& value);
|
||||
void addToken(TokenType type, const String& value, size_t start);
|
||||
/// Read the next token, and add it to the buffer
|
||||
void readToken();
|
||||
/// Read the next token which is a string (after the opening ")
|
||||
@@ -154,8 +155,8 @@ void TokenIterator::putBack() {
|
||||
buffer.insert(buffer.begin(), t);
|
||||
}
|
||||
|
||||
void TokenIterator::addToken(TokenType type, const String& value) {
|
||||
Token t = {type, value, newline};
|
||||
void TokenIterator::addToken(TokenType type, const String& value, size_t start) {
|
||||
Token t = {type, value, newline, start};
|
||||
buffer.push_back(t);
|
||||
newline = false;
|
||||
}
|
||||
@@ -170,7 +171,7 @@ void TokenIterator::readToken() {
|
||||
more.pop();
|
||||
} else {
|
||||
// EOF
|
||||
addToken(TOK_EOF, _("end of input"));
|
||||
addToken(TOK_EOF, _("end of input"), input.size());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -200,7 +201,7 @@ void TokenIterator::readToken() {
|
||||
// name
|
||||
size_t start = pos - 1;
|
||||
while (pos < input.size() && isAlnum_(input.GetChar(pos))) ++pos;
|
||||
addToken(TOK_NAME, cannocial_name_form(input.substr(start, pos-start))); // convert name to cannocial form
|
||||
addToken(TOK_NAME, cannocial_name_form(input.substr(start, pos-start)), start); // convert name to cannocial form
|
||||
} else if (isDigit(c)) {
|
||||
// number
|
||||
size_t start = pos - 1;
|
||||
@@ -208,16 +209,16 @@ void TokenIterator::readToken() {
|
||||
String num = input.substr(start, pos-start);
|
||||
addToken(
|
||||
num.find_first_of('.') == String::npos ? TOK_INT : TOK_DOUBLE,
|
||||
num
|
||||
num, start
|
||||
);
|
||||
} else if (isOper(c)) {
|
||||
// operator
|
||||
if (pos < input.size() && isLongOper(input.substr(pos - 1, 2))) {
|
||||
// long operator
|
||||
addToken(TOK_OPER, input.substr(pos - 1, 2));
|
||||
addToken(TOK_OPER, input.substr(pos - 1, 2), pos-1);
|
||||
pos += 1;
|
||||
} else {
|
||||
addToken(TOK_OPER, input.substr(pos - 1, 1));
|
||||
addToken(TOK_OPER, input.substr(pos - 1, 1), pos-1);
|
||||
}
|
||||
} else if (c==_('"')) {
|
||||
// string
|
||||
@@ -226,16 +227,16 @@ void TokenIterator::readToken() {
|
||||
} else if (c == _('}') && !open_braces.empty() && open_braces.top() != BRACE_PAREN) {
|
||||
// closing smart string, resume to string parsing
|
||||
// "a{e}b" --> "a" "{ e }" "b"
|
||||
addToken(TOK_RPAREN, _("}\""));
|
||||
addToken(TOK_RPAREN, _("}\""), pos-1);
|
||||
readStringToken();
|
||||
} else if (isLparen(c)) {
|
||||
// paranthesis/brace
|
||||
open_braces.push(BRACE_PAREN);
|
||||
addToken(TOK_LPAREN, String(1,c));
|
||||
addToken(TOK_LPAREN, String(1,c), pos-1);
|
||||
} else if (isRparen(c)) {
|
||||
// paranthesis/brace
|
||||
if (!open_braces.empty()) open_braces.pop();
|
||||
addToken(TOK_RPAREN, String(1,c));
|
||||
addToken(TOK_RPAREN, String(1,c), pos-1);
|
||||
} else if(c==_('#')) {
|
||||
// comment untill end of line
|
||||
while (pos < input.size() && input[pos] != _('\n')) ++pos;
|
||||
@@ -246,17 +247,18 @@ void TokenIterator::readToken() {
|
||||
}
|
||||
|
||||
void TokenIterator::readStringToken() {
|
||||
size_t start = max((size_t)1, pos) - 1;
|
||||
String str;
|
||||
while (true) {
|
||||
if (pos >= input.size()) {
|
||||
if (!open_braces.empty() && open_braces.top() == BRACE_STRING_MODE) {
|
||||
// in string mode: end of input = end of string
|
||||
addToken(TOK_STRING, str);
|
||||
addToken(TOK_STRING, str, start);
|
||||
return;
|
||||
} else {
|
||||
add_error(_("Unexpected end of input in string constant"));
|
||||
// fix up
|
||||
addToken(TOK_STRING, str);
|
||||
addToken(TOK_STRING, str, start);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +266,7 @@ void TokenIterator::readStringToken() {
|
||||
// parse the string constant
|
||||
if (c == _('"') && !open_braces.empty() && open_braces.top() == BRACE_STRING) {
|
||||
// end of string
|
||||
addToken(TOK_STRING, str);
|
||||
addToken(TOK_STRING, str, start);
|
||||
open_braces.pop();
|
||||
return;
|
||||
} else if (c == _('\\')) {
|
||||
@@ -272,7 +274,7 @@ void TokenIterator::readStringToken() {
|
||||
if (pos >= input.size()) {
|
||||
add_error(_("Unexpected end of input in string constant"));
|
||||
// fix up
|
||||
addToken(TOK_STRING, str);
|
||||
addToken(TOK_STRING, str, start);
|
||||
return;
|
||||
}
|
||||
c = input.GetChar(pos++);
|
||||
@@ -282,8 +284,8 @@ void TokenIterator::readStringToken() {
|
||||
} else if (c == _('{')) {
|
||||
// smart string
|
||||
// "a{e}b" --> "a" "{ e }" "b"
|
||||
addToken(TOK_STRING, str);
|
||||
addToken(TOK_LPAREN, _("\"{"));
|
||||
addToken(TOK_STRING, str, start);
|
||||
addToken(TOK_LPAREN, _("\"{"), pos-1);
|
||||
return;
|
||||
} else {
|
||||
str += c;
|
||||
@@ -302,7 +304,7 @@ void TokenIterator::add_error(const String& message) {
|
||||
errors.push_back(ScriptParseError(pos, line, filename, message));
|
||||
}
|
||||
void TokenIterator::expected(const String& expected) {
|
||||
size_t error_pos = pos - peek(0).value.size();
|
||||
size_t error_pos = peek(0).pos;
|
||||
if (!errors.empty() && errors.back().start == pos) return; // already an error here
|
||||
// find line number
|
||||
int line = 1;
|
||||
|
||||
Reference in New Issue
Block a user