Store location during Ascii input parsing for use in error messages

This commit is contained in:
Tim Wojtulewicz 2022-05-12 14:40:31 -07:00
parent 098a5d3348
commit ec50b66ff3
8 changed files with 60 additions and 16 deletions

View file

@ -62,7 +62,7 @@ public:
*
* @param val the Value to render to the ODesc object.
*
* @param The name of a field associated with the value.
* @param name The name of a field associated with the value.
*
* @return Returns true on success, false on error. Errors are also
* flagged via the thread.
@ -75,7 +75,7 @@ public:
*
* @param s The string to parse.
*
* @param The name of a field associated with the value. Used only
* @param name The name of a field associated with the value. Used only
* for error reporting.
*
* @return The new value, or null on error. Errors must also be

View file

@ -253,9 +253,16 @@ struct Value
static Val* ValueToVal(const std::string& source, const threading::Value* val,
bool& have_error);
void SetFileLineNumber(int line) { line_number = line; }
int GetFileLineNumber() const { return line_number; }
private:
friend class IPAddr;
Value(const Value& other) = delete;
// For values read by the input framework, this can represent the line number
// containing this value. Used by the Ascii reader primarily.
int line_number = -1;
};
} // namespace zeek::threading

View file

@ -47,13 +47,13 @@ public:
* separators.
*/
Ascii(MsgThread* t, const SeparatorInfo& info);
virtual ~Ascii();
~Ascii() override;
virtual bool Describe(ODesc* desc, Value* val, const std::string& name = "") const;
virtual bool Describe(ODesc* desc, Value* val, const std::string& name = "") const override;
virtual bool Describe(ODesc* desc, int num_fields, const Field* const* fields,
Value** vals) const;
Value** vals) const override;
virtual Value* ParseValue(const std::string& s, const std::string& name, TypeTag type,
TypeTag subtype = TYPE_ERROR) const;
TypeTag subtype = TYPE_ERROR) const override;
private:
bool CheckNumberError(const char* start, const char* end, bool nonneg_only = false) const;