1
0
Fork 0

added regex operators ~= and !~

This commit is contained in:
Jan Steemann 2016-06-07 12:20:03 +02:00
parent 80d3164622
commit 274cfeb5c2
7 changed files with 1619 additions and 1417 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 3.0.2. */
/* A Bison parser, made by GNU Bison 3.0.4. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -79,46 +79,48 @@ extern int Aqldebug;
T_AND = 288,
T_OR = 289,
T_NIN = 290,
T_EQ = 291,
T_NE = 292,
T_LT = 293,
T_GT = 294,
T_LE = 295,
T_GE = 296,
T_LIKE = 297,
T_PLUS = 298,
T_MINUS = 299,
T_TIMES = 300,
T_DIV = 301,
T_MOD = 302,
T_QUESTION = 303,
T_COLON = 304,
T_SCOPE = 305,
T_RANGE = 306,
T_COMMA = 307,
T_OPEN = 308,
T_CLOSE = 309,
T_OBJECT_OPEN = 310,
T_OBJECT_CLOSE = 311,
T_ARRAY_OPEN = 312,
T_ARRAY_CLOSE = 313,
T_OUTBOUND = 314,
T_INBOUND = 315,
T_ANY = 316,
T_ALL = 317,
T_NONE = 318,
UMINUS = 319,
UPLUS = 320,
FUNCCALL = 321,
REFERENCE = 322,
INDEXED = 323,
EXPANSION = 324
T_REGEX_MATCH = 291,
T_REGEX_NON_MATCH = 292,
T_EQ = 293,
T_NE = 294,
T_LT = 295,
T_GT = 296,
T_LE = 297,
T_GE = 298,
T_LIKE = 299,
T_PLUS = 300,
T_MINUS = 301,
T_TIMES = 302,
T_DIV = 303,
T_MOD = 304,
T_QUESTION = 305,
T_COLON = 306,
T_SCOPE = 307,
T_RANGE = 308,
T_COMMA = 309,
T_OPEN = 310,
T_CLOSE = 311,
T_OBJECT_OPEN = 312,
T_OBJECT_CLOSE = 313,
T_ARRAY_OPEN = 314,
T_ARRAY_CLOSE = 315,
T_OUTBOUND = 316,
T_INBOUND = 317,
T_ANY = 318,
T_ALL = 319,
T_NONE = 320,
UMINUS = 321,
UPLUS = 322,
FUNCCALL = 323,
REFERENCE = 324,
INDEXED = 325,
EXPANSION = 326
};
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE YYSTYPE;
union YYSTYPE
{
#line 19 "Aql/grammar.y" /* yacc.c:1909 */
@ -131,8 +133,10 @@ union YYSTYPE
bool boolval;
int64_t intval;
#line 135 "Aql/grammar.hpp" /* yacc.c:1909 */
#line 137 "Aql/grammar.hpp" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif

View File

@ -238,6 +238,9 @@ static AstNode const* GetIntoExpression(AstNode const* node) {
%token T_OR "or operator"
%token T_NIN "not in operator"
%token T_REGEX_MATCH "~= operator"
%token T_REGEX_NON_MATCH "~! operator"
%token T_EQ "== operator"
%token T_NE "!= operator"
%token T_LT "< operator"
@ -285,7 +288,7 @@ static AstNode const* GetIntoExpression(AstNode const* node) {
%left T_OR
%left T_AND
%nonassoc T_OUTBOUND T_INBOUND T_ANY T_ALL T_NONE
%left T_EQ T_NE T_LIKE
%left T_EQ T_NE T_LIKE T_REGEX_MATCH T_REGEX_NON_MATCH
%left T_IN T_NIN
%left T_LT T_GT T_LE T_GE
%left T_RANGE
@ -1147,6 +1150,19 @@ operator_binary:
arguments->addMember($3);
$$ = parser->ast()->createNodeFunctionCall("LIKE", arguments);
}
| expression T_REGEX_MATCH expression {
AstNode* arguments = parser->ast()->createNodeArray(2);
arguments->addMember($1);
arguments->addMember($3);
$$ = parser->ast()->createNodeFunctionCall("REGEX_TEST", arguments);
}
| expression T_REGEX_NON_MATCH expression {
AstNode* arguments = parser->ast()->createNodeArray(2);
arguments->addMember($1);
arguments->addMember($3);
AstNode* node = parser->ast()->createNodeFunctionCall("REGEX_TEST", arguments);
$$ = parser->ast()->createNodeUnaryOperator(NODE_TYPE_OPERATOR_UNARY_NOT, node);
}
| expression quantifier T_EQ expression {
$$ = parser->ast()->createNodeBinaryArrayOperator(NODE_TYPE_OPERATOR_BINARY_ARRAY_EQ, $1, $4, $2);
}

File diff suppressed because it is too large Load Diff

View File

@ -199,6 +199,14 @@ namespace arangodb {
* operators
* --------------------------------------------------------------------------- */
"=~" {
return T_REGEX_MATCH;
}
"!~" {
return T_REGEX_NON_MATCH;
}
"==" {
return T_EQ;
}

View File

@ -225,8 +225,13 @@ function ahuacatlStringFunctionsTestSuite () {
query = "RETURN NOOPT(V8(REGEX_TEST(@what, @re)))";
assertEqual(v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
query = "RETURN @what =~ @re";
assertEqual(v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
query = "RETURN @what !~ @re";
assertEqual(!v[2], getQueryResults(query, { what: v[0], re: v[1] })[0], v);
});
},
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,113 @@
/*jshint globalstrict:false, strict:false, maxlen:5000 */
/*global assertEqual, AQL_EXECUTE */
////////////////////////////////////////////////////////////////////////////////
/// @brief tests for query language, functions
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
var internal = require("internal");
var jsunity = require("jsunity");
var db = internal.db;
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////
function ahuacatlRegexTestSuite () {
var c;
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////
setUp : function () {
db._drop("UnitTestsAhuacatlRegex");
c = db._create("UnitTestsAhuacatlRegex");
for (var i = 0; i < 1000; ++i) {
c.insert({ _key: "test" + i });
}
},
////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////
tearDown : function () {
db._drop("UnitTestsAhuacatlRegex");
c = null;
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test regex matching
////////////////////////////////////////////////////////////////////////////////
testRegexMatch : function () {
var values = [
[ '^test$', 0 ],
[ '^test\\d+$', 1000 ],
[ '^test1$', 1 ],
[ '^test1', 111 ],
[ '^test1*', 1000 ],
[ '^test1+', 111 ],
[ '^test1..$', 100 ],
[ '^test1.$', 10 ],
[ '^test11.', 10 ],
[ 'test', 1000 ],
[ 'test123', 1 ],
[ 'test12', 11 ],
[ '111', 1 ],
[ '111$', 1 ],
[ '11$', 10 ],
[ '1$', 100 ]
];
values.forEach(function(v) {
// test match
var query = "FOR doc IN @@collection FILTER doc._key =~ @re RETURN doc._key";
var result = AQL_EXECUTE(query, { "@collection": c.name(), re: v[0] }).json;
assertEqual(v[1], result.length);
// test non-match
query = "FOR doc IN @@collection FILTER doc._key !~ @re RETURN doc._key";
result = AQL_EXECUTE(query, { "@collection": c.name(), re: v[0] }).json;
assertEqual(1000 - v[1], result.length);
});
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suite
////////////////////////////////////////////////////////////////////////////////
jsunity.run(ahuacatlRegexTestSuite);
return jsunity.done();