Adding support for compiling approximate matching patterns

Adds new "edit_distance" extparam
This commit is contained in:
Anatoly Burakov
2017-02-10 15:37:35 +00:00
committed by Matthew Barr
parent 60fc975c81
commit 2de6706df2
16 changed files with 804 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, 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:
@@ -79,7 +79,8 @@ static
void validateExt(const hs_expr_ext &ext) {
static const unsigned long long ALL_EXT_FLAGS = HS_EXT_FLAG_MIN_OFFSET |
HS_EXT_FLAG_MAX_OFFSET |
HS_EXT_FLAG_MIN_LENGTH;
HS_EXT_FLAG_MIN_LENGTH |
HS_EXT_FLAG_EDIT_DISTANCE;
if (ext.flags & ~ALL_EXT_FLAGS) {
throw CompileError("Invalid hs_expr_ext flag set.");
}
@@ -111,7 +112,8 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression,
id(actionId),
min_offset(0),
max_offset(MAX_OFFSET),
min_length(0) {
min_length(0),
edit_distance(0) {
ParseMode mode(flags);
component = parse(expression, mode);
@@ -163,6 +165,9 @@ ParsedExpression::ParsedExpression(unsigned index_in, const char *expression,
if (ext->flags & HS_EXT_FLAG_MIN_LENGTH) {
min_length = ext->min_length;
}
if (ext->flags & HS_EXT_FLAG_EDIT_DISTANCE) {
edit_distance = ext->edit_distance;
}
}
// These are validated in validateExt, so an error will already have been

View File

@@ -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:
@@ -78,6 +78,7 @@ public:
u64a min_offset; //!< 0 if not used
u64a max_offset; //!< MAX_OFFSET if not used
u64a min_length; //!< 0 if not used
u32 edit_distance; //!< 0 if not used
};
/**