mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
Fix: correct line numbers for parse errors in included files
This commit is contained in:
@@ -63,7 +63,7 @@ enum OpenBrace
|
|||||||
/** Also stores errors found when tokenizing or parsing */
|
/** Also stores errors found when tokenizing or parsing */
|
||||||
class TokenIterator {
|
class TokenIterator {
|
||||||
public:
|
public:
|
||||||
TokenIterator(const String& str, Packaged* package, bool string_mode, vector<ScriptParseError>& errors);
|
TokenIterator(const String& str, Packaged* package, bool string_mode, String const& filename, vector<ScriptParseError>& errors);
|
||||||
|
|
||||||
/// Peek at the next token, doesn't move to the one after that
|
/// Peek at the next token, doesn't move to the one after that
|
||||||
/** Can peek further forward by using higher values of offset.
|
/** Can peek further forward by using higher values of offset.
|
||||||
@@ -83,7 +83,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
String::const_iterator pos;
|
String::const_iterator pos;
|
||||||
const String::const_iterator begin, end;
|
const String::const_iterator begin, end;
|
||||||
String filename; ///< Filename of include files, "" for the main input
|
String const& filename; ///< Filename of include files, "" for the main input
|
||||||
vector<Token> buffer; ///< buffer of unread tokens, front() = current
|
vector<Token> buffer; ///< buffer of unread tokens, front() = current
|
||||||
stack<OpenBrace> open_braces; ///< braces/quotes we entered from script mode
|
stack<OpenBrace> open_braces; ///< braces/quotes we entered from script mode
|
||||||
bool newline; ///< Did we just pass a newline?
|
bool newline; ///< Did we just pass a newline?
|
||||||
@@ -127,10 +127,11 @@ bool isLongOper(StringView s) { return s==_(":=") || s==_("==") || s==_("!=") ||
|
|||||||
// moveme
|
// moveme
|
||||||
// ----------------------------------------------------------------------------- : Tokenizing
|
// ----------------------------------------------------------------------------- : Tokenizing
|
||||||
|
|
||||||
TokenIterator::TokenIterator(const String& str, Packaged* package, bool string_mode, vector<ScriptParseError>& errors)
|
TokenIterator::TokenIterator(const String& str, Packaged* package, bool string_mode, String const& filename, vector<ScriptParseError>& errors)
|
||||||
: pos(str.begin())
|
: pos(str.begin())
|
||||||
, begin(str.begin())
|
, begin(str.begin())
|
||||||
, end(str.end())
|
, end(str.end())
|
||||||
|
, filename(filename)
|
||||||
, package(package)
|
, package(package)
|
||||||
, newline(false)
|
, newline(false)
|
||||||
, errors(errors)
|
, errors(errors)
|
||||||
@@ -407,7 +408,8 @@ ExprType parseTopLevel(TokenIterator& input, Script& script) {
|
|||||||
ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<ScriptParseError>& errors_out) {
|
ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<ScriptParseError>& errors_out) {
|
||||||
errors_out.clear();
|
errors_out.clear();
|
||||||
// parse
|
// parse
|
||||||
TokenIterator input(s, package, string_mode, errors_out);
|
const String filename;
|
||||||
|
TokenIterator input(s, package, string_mode, filename, errors_out);
|
||||||
ScriptP script(new Script);
|
ScriptP script(new Script);
|
||||||
ExprType type = parseTopLevel(input, *script);
|
ExprType type = parseTopLevel(input, *script);
|
||||||
// were there fatal errors?
|
// were there fatal errors?
|
||||||
@@ -684,7 +686,7 @@ ExprType parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
|
|||||||
auto stream = package_manager.openFileFromPackage(input.package, filename);
|
auto stream = package_manager.openFileFromPackage(input.package, filename);
|
||||||
eat_utf8_bom(*stream);
|
eat_utf8_bom(*stream);
|
||||||
String included_input = read_utf8_line(*stream, true);
|
String included_input = read_utf8_line(*stream, true);
|
||||||
TokenIterator included_tokens(included_input, input.package, false, input.errors);
|
TokenIterator included_tokens(included_input, input.package, false, filename, input.errors);
|
||||||
return parseTopLevel(included_tokens, script);
|
return parseTopLevel(included_tokens, script);
|
||||||
} else {
|
} else {
|
||||||
// variable
|
// variable
|
||||||
|
|||||||
Reference in New Issue
Block a user