throw LocatedParseError("(*UCP) must be at start of "
"expression, encountered");
};
- 'UTF16)' => {
- throw LocatedParseError("(*UTF16) not supported");
- };
- 'UTF32)' => {
- throw LocatedParseError("(*UTF32) not supported");
- };
- any => {
+ # Use the control verb mini-parser to report an error for this
+ # unsupported/unknown verb.
+ [^)]+ ')' => {
+ ParseMode temp_mode;
+ assert(ts - 2 >= ptr); // parser needs the '(*' at the start too.
+ read_control_verbs(ts - 2, te, (ts - 2 - ptr), temp_mode);
+ assert(0); // Should have thrown a parse error.
throw LocatedParseError("Unknown control verb");
};
*|;
// First, read the control verbs, set any global mode flags and move the
// ptr forward.
- p = read_control_verbs(p, pe, globalMode);
+ p = read_control_verbs(p, pe, 0, globalMode);
const char *eof = pe;
int cs;
#ifndef CONTROL_VERBS_H
#define CONTROL_VERBS_H
+#include "ue2common.h"
+
namespace ue2 {
struct ParseMode;
-const char *read_control_verbs(const char *ptr, const char *end,
+const char *read_control_verbs(const char *ptr, const char *end, size_t start,
ParseMode &mode);
} // namespace ue2
namespace ue2 {
-const char *read_control_verbs(const char *ptr, const char *end,
+const char *read_control_verbs(const char *ptr, const char *end, size_t start,
ParseMode &mode) {
const char *p = ptr;
const char *pe = end;
%% write exec;
} catch (LocatedParseError &error) {
if (ts >= ptr && ts <= pe) {
- error.locate(ts - ptr);
+ error.locate(ts - ptr + start);
} else {
error.locate(0);
}
/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
LocatedParseError::~LocatedParseError() {}
void LocatedParseError::locate(size_t offset) {
+ if (finalized) {
+ return;
+ }
std::ostringstream str;
str << reason << " at index " << offset << ".";
reason = str.str();
+ finalized = true;
}
}
/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* \brief Parse/Compile exceptions.
*/
-#ifndef PARSE_ERROR_H_A02047D1AA16C9
-#define PARSE_ERROR_H_A02047D1AA16C9
+#ifndef PARSE_ERROR_H
+#define PARSE_ERROR_H
#include "util/compile_error.h"
public:
// Note: 'why' should describe why the error occurred and end with a
// full stop, but no line break.
- explicit ParseError(const std::string &why) : CompileError(why) {}
+ explicit ParseError(std::string why) : CompileError(std::move(why)) {}
~ParseError() override;
};
class LocatedParseError : public ParseError {
public:
- explicit LocatedParseError(const std::string &why) : ParseError(".") {
- reason = why; // don't use ParseError ctor
+ explicit LocatedParseError(std::string why) : ParseError(".") {
+ reason = std::move(why); // don't use ParseError ctor
}
~LocatedParseError() override;
void locate(size_t offset);
+private:
+ bool finalized = false; //!< true when locate() has been called.
};
} // namespace ue2
-#endif /* PARSE_ERROR_H_A02047D1AA16C9 */
+#endif /* PARSE_ERROR_H */
93:/a\o{777}/ #Value in \o{...} sequence is too large at index 1.
94:/(*UTF16)foo/ #Unsupported control verb (*UTF16) at index 0.
95:/(*BSR_UNICODE)abc/ #Unsupported control verb (*BSR_UNICODE) at index 0.
-96:/a+(*SKIP)b/ #Unknown control verb at index 4.
+96:/a+(*SKIP)b/ #Unknown control verb (*SKIP) at index 2.
97:/foo(*/ #Invalid repeat at index 4.
98:/[:\]:]/ #POSIX named classes are only supported inside a class at index 0.
99:/[[:[:]/ #Invalid POSIX named class at index 1.