mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
parser: use control_verb parser inline
This commit is contained in:
parent
bfc8be5675
commit
bef6889844
@ -560,13 +560,13 @@ unichar readUtf8CodePoint4c(const char *s) {
|
||||
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");
|
||||
};
|
||||
*|;
|
||||
@ -1838,7 +1838,7 @@ unique_ptr<Component> parse(const char *ptr, ParseMode &globalMode) {
|
||||
|
||||
// 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;
|
||||
|
@ -34,11 +34,13 @@
|
||||
#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
|
||||
|
@ -43,7 +43,7 @@ using namespace std;
|
||||
|
||||
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;
|
||||
@ -108,7 +108,7 @@ const char *read_control_verbs(const char *ptr, const char *end,
|
||||
%% write exec;
|
||||
} catch (LocatedParseError &error) {
|
||||
if (ts >= ptr && ts <= pe) {
|
||||
error.locate(ts - ptr);
|
||||
error.locate(ts - ptr + start);
|
||||
} else {
|
||||
error.locate(0);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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:
|
||||
@ -44,9 +44,13 @@ ParseError::~ParseError() {}
|
||||
LocatedParseError::~LocatedParseError() {}
|
||||
|
||||
void LocatedParseError::locate(size_t offset) {
|
||||
if (finalized) {
|
||||
return;
|
||||
}
|
||||
std::ostringstream str;
|
||||
str << reason << " at index " << offset << ".";
|
||||
reason = str.str();
|
||||
finalized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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:
|
||||
@ -30,8 +30,8 @@
|
||||
* \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"
|
||||
|
||||
@ -44,22 +44,24 @@ class ParseError : public CompileError {
|
||||
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 */
|
||||
|
@ -92,7 +92,7 @@
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user