1
0
Fork 0

Merge branch 'engine-vs-velocystream' of github.com:arangodb/arangodb into engine-vs-velocystream

This commit is contained in:
Michael Hackstein 2016-08-19 13:15:48 +02:00
commit 635641d4e5
20 changed files with 0 additions and 3274 deletions

View File

@ -294,11 +294,6 @@ BOOST_AUTO_TEST_CASE (tst_value_mchacki2_roundtrip) {
BOOST_CHECK_EQUAL(std::string("56.94837631946843"), std::string(buffer._buffer, buffer._current - buffer._buffer));
auto json2 = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, buffer._buffer);
BOOST_CHECK_EQUAL(TRI_JSON_NUMBER, json2->_type);
BOOST_CHECK_EQUAL(value, json2->_value._number);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json2);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
TRI_DestroyStringBuffer(&buffer);
}
@ -339,11 +334,6 @@ BOOST_AUTO_TEST_CASE (tst_one_third_roundtrip) {
BOOST_CHECK_EQUAL(std::string("0.3333333333333333"), std::string(buffer._buffer, buffer._current - buffer._buffer));
auto json2 = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, buffer._buffer);
BOOST_CHECK_EQUAL(TRI_JSON_NUMBER, json2->_type);
BOOST_CHECK_EQUAL(value, json2->_value._number);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json2);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
TRI_DestroyStringBuffer(&buffer);
}
@ -384,11 +374,6 @@ BOOST_AUTO_TEST_CASE (tst_04_roundtrip) {
BOOST_CHECK_EQUAL(std::string("0.4"), std::string(buffer._buffer, buffer._current - buffer._buffer));
auto json2 = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, buffer._buffer);
BOOST_CHECK_EQUAL(TRI_JSON_NUMBER, json2->_type);
BOOST_CHECK_EQUAL(value, json2->_value._number);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json2);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
TRI_DestroyStringBuffer(&buffer);
}
@ -410,11 +395,6 @@ BOOST_AUTO_TEST_CASE (tst_value_high_roundtrip) {
BOOST_CHECK_EQUAL(std::string("4.32e+261"), std::string(buffer._buffer, buffer._current - buffer._buffer));
auto json2 = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, buffer._buffer);
BOOST_CHECK_EQUAL(TRI_JSON_NUMBER, json2->_type);
BOOST_CHECK_EQUAL(value, json2->_value._number);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json2);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
TRI_DestroyStringBuffer(&buffer);
}
@ -435,11 +415,6 @@ BOOST_AUTO_TEST_CASE (tst_value_low_roundtrip) {
TRI_StringifyJson(&buffer, json);
BOOST_CHECK_EQUAL(std::string("-4.32e+261"), std::string(buffer._buffer, buffer._current - buffer._buffer));
auto json2 = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, buffer._buffer);
BOOST_CHECK_EQUAL(TRI_JSON_NUMBER, json2->_type);
BOOST_CHECK_EQUAL(value, json2->_value._number);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json2);
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
TRI_DestroyStringBuffer(&buffer);

View File

@ -1,224 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief test suite for json-utilities.c
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 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
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#define BOOST_TEST_INCLUDED
#include <boost/test/unit_test.hpp>
#include "Basics/json-utilities.h"
#include "Basics/StringBuffer.h"
#include "Basics/VelocyPackHelper.h"
#include "Basics/Utf8Helper.h"
#if _WIN32
#include "Basics/win-utils.h"
#define FIX_ICU_ENV TRI_FixIcuDataEnv()
#else
#define FIX_ICU_ENV
#endif
static bool Initialized = false;
// -----------------------------------------------------------------------------
// --SECTION-- private macros
// -----------------------------------------------------------------------------
#define JSON_CHECK(expected, func, lValue, rValue) \
l = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, lValue); \
r = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, rValue); \
if (l && r) { \
BOOST_CHECK_EQUAL(expected, func(l, r)); \
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, l); \
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, r); \
}
#define INIT_BUFFER TRI_string_buffer_t* sb = TRI_CreateStringBuffer(TRI_UNKNOWN_MEM_ZONE);
#define FREE_BUFFER TRI_FreeStringBuffer(TRI_UNKNOWN_MEM_ZONE, sb);
#define STRINGIFY TRI_StringifyJson(sb, json);
#define STRING_VALUE sb->_buffer
#define FREE_JSON TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
// -----------------------------------------------------------------------------
// --SECTION-- setup / tear-down
// -----------------------------------------------------------------------------
struct CJsonUtilitiesSetup {
CJsonUtilitiesSetup () {
FIX_ICU_ENV;
if (!arangodb::basics::Utf8Helper::DefaultUtf8Helper.setCollatorLanguage("")) {
std::string msg =
"cannot initialize ICU; please make sure ICU*dat is available; "
"the variable ICU_DATA='";
if (getenv("ICU_DATA") != nullptr) {
msg += getenv("ICU_DATA");
}
msg += "' should point the directory containing the ICU*dat file.";
BOOST_TEST_MESSAGE(msg);
BOOST_CHECK_EQUAL(false, true);
}
BOOST_TEST_MESSAGE("setup json utilities test");
if (!Initialized) {
Initialized = true;
arangodb::basics::VelocyPackHelper::initialize();
}
}
~CJsonUtilitiesSetup () {
BOOST_TEST_MESSAGE("tear-down json utilities test");
}
};
// -----------------------------------------------------------------------------
// --SECTION-- test suite
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief setup
////////////////////////////////////////////////////////////////////////////////
BOOST_FIXTURE_TEST_SUITE(CJsonUtilitiesTest, CJsonUtilitiesSetup)
////////////////////////////////////////////////////////////////////////////////
/// @brief test compare values with equal values
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_compare_values_equal) {
TRI_json_t* l;
TRI_json_t* r;
// With Utf8-mode:
JSON_CHECK(0, TRI_CompareValuesJson, "null", "null");
JSON_CHECK(0, TRI_CompareValuesJson, "false", "false");
JSON_CHECK(0, TRI_CompareValuesJson, "true", "true");
JSON_CHECK(0, TRI_CompareValuesJson, "0", "0");
JSON_CHECK(0, TRI_CompareValuesJson, "1", "1");
JSON_CHECK(0, TRI_CompareValuesJson, "1.5", "1.5");
JSON_CHECK(0, TRI_CompareValuesJson, "-43.2", "-43.2");
JSON_CHECK(0, TRI_CompareValuesJson, "\"\"", "\"\"");
JSON_CHECK(0, TRI_CompareValuesJson, "\" \"", "\" \"");
JSON_CHECK(0, TRI_CompareValuesJson, "\"the quick brown fox\"", "\"the quick brown fox\"");
JSON_CHECK(0, TRI_CompareValuesJson, "[]", "[]");
JSON_CHECK(0, TRI_CompareValuesJson, "[-1]", "[-1]");
JSON_CHECK(0, TRI_CompareValuesJson, "[0]", "[0]");
JSON_CHECK(0, TRI_CompareValuesJson, "[1]", "[1]");
JSON_CHECK(0, TRI_CompareValuesJson, "[true]", "[true]");
JSON_CHECK(0, TRI_CompareValuesJson, "{}", "{}");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test compare values with unequal values
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE (tst_compare_values_unequal) {
TRI_json_t* l;
TRI_json_t* r;
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "false");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "true");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "-1");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "0");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "1");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "-10");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "\"\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "\"0\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "\" \"");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "[]");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "[null]");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "[false]");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "[true]");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "[0]");
JSON_CHECK(-1, TRI_CompareValuesJson, "null", "{}");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "true");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "-1");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "0");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "1");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "-10");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "\"\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "\"0\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "\" \"");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "[]");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "[null]");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "[false]");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "[true]");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "[0]");
JSON_CHECK(-1, TRI_CompareValuesJson, "false", "{}");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "-1");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "0");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "1");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "-10");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "\"\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "\"0\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "\" \"");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "[]");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "[null]");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "[false]");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "[true]");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "[0]");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "{}");
JSON_CHECK(-1, TRI_CompareValuesJson, "-2", "-1");
JSON_CHECK(-1, TRI_CompareValuesJson, "-10", "-9");
JSON_CHECK(-1, TRI_CompareValuesJson, "-20", "-5");
JSON_CHECK(-1, TRI_CompareValuesJson, "-5", "-2");
JSON_CHECK(-1, TRI_CompareValuesJson, "true", "1");
JSON_CHECK(-1, TRI_CompareValuesJson, "1.5", "1.6");
JSON_CHECK(-1, TRI_CompareValuesJson, "10.5", "10.51");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "\"\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "\"0\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "\"-1\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "\"-1\"");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "\" \"");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[-1]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[0]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[1]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[null]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[false]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "[true]");
JSON_CHECK(-1, TRI_CompareValuesJson, "0", "{}");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[-1]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[0]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[1]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[null]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[false]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "[true]");
JSON_CHECK(-1, TRI_CompareValuesJson, "1", "{}");
}
////////////////////////////////////////////////////////////////////////////////
/// @brief generate tests
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_SUITE_END ()
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -15,7 +15,6 @@ add_executable(${TEST_BASICS_SUITE}
Basics/files-test.cpp
Basics/fpconv-test.cpp
Basics/json-test.cpp
Basics/json-utilities-test.cpp
Basics/hashes-test.cpp
Basics/associative-multi-pointer-test.cpp
Basics/associative-multi-pointer-nohashcache-test.cpp

View File

@ -29,7 +29,6 @@
#include "Aql/Expression.h"
#include "Aql/Variable.h"
#include "Aql/WalkerWorker.h"
#include "Basics/json-utilities.h"
#include "VocBase/voc-types.h"
#include "VocBase/vocbase.h"

View File

@ -32,7 +32,6 @@
#include "Basics/StringUtils.h"
#include "Basics/VelocyPackHelper.h"
#include "Basics/WriteLocker.h"
#include "Basics/json.h"
#include "Cluster/ServerState.h"
#include "Endpoint/Endpoint.h"
#include "GeneralServer/GeneralServerFeature.h"

View File

@ -27,7 +27,6 @@
#include "Basics/Common.h"
#include "Basics/ReadWriteLock.h"
#include "Basics/json.h"
#include "Rest/HttpRequest.h"
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>

View File

@ -36,8 +36,6 @@
#include "Basics/VelocyPackHelper.h"
#include "Basics/WriteLocker.h"
#include "Basics/hashes.h"
#include "Basics/json-utilities.h"
#include "Basics/json.h"
#include "Cluster/ServerState.h"
#include "Logger/Logger.h"
#include "Rest/HttpResponse.h"

View File

@ -24,7 +24,6 @@
#include "ContinuousSyncer.h"
#include "ApplicationFeatures/ApplicationServer.h"
#include "Basics/Exceptions.h"
#include "Basics/json.h"
#include "Basics/StringBuffer.h"
#include "Basics/VelocyPackHelper.h"
#include "Basics/WriteLocker.h"

View File

@ -24,7 +24,6 @@
#include "InitialSyncer.h"
#include "ApplicationFeatures/ApplicationServer.h"
#include "Basics/Exceptions.h"
#include "Basics/json.h"
#include "Basics/ReadLocker.h"
#include "Basics/StringUtils.h"
#include "Basics/VelocyPackHelper.h"

View File

@ -22,7 +22,6 @@
////////////////////////////////////////////////////////////////////////////////
#include "RestImportHandler.h"
#include "Basics/json-utilities.h"
#include "Basics/StaticStrings.h"
#include "Basics/StringUtils.h"
#include "Basics/VelocyPackHelper.h"

View File

@ -26,8 +26,6 @@
#include "Aql/Query.h"
#include "Aql/QueryList.h"
#include "Basics/conversions.h"
#include "Basics/json.h"
#include "Basics/json-utilities.h"
#include "Basics/StringBuffer.h"
#include "Basics/StringUtils.h"
#include "Basics/VelocyPackHelper.h"

View File

@ -31,7 +31,6 @@
#include "Basics/MutexLocker.h"
#include "Basics/StringUtils.h"
#include "Basics/Thread.h"
#include "Basics/json.h"
#include "Logger/Logger.h"
#include "Scheduler/SchedulerThread.h"
#include "Scheduler/Task.h"

View File

@ -23,7 +23,6 @@
////////////////////////////////////////////////////////////////////////////////
#include "TimerTask.h"
#include "Basics/json.h"
#include "Logger/Logger.h"
#include "Scheduler/Scheduler.h"

View File

@ -22,7 +22,6 @@
////////////////////////////////////////////////////////////////////////////////
#include "CursorRepository.h"
#include "Basics/json.h"
#include "Basics/MutexLocker.h"
#include "Logger/Logger.h"
#include "Utils/CollectionExport.h"

View File

@ -26,7 +26,6 @@
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
#include "Basics/json.h"
#include "Dispatcher/DispatcherQueue.h"
#include "Logger/Logger.h"
#include "V8/v8-utils.h"

View File

@ -22,8 +22,6 @@
////////////////////////////////////////////////////////////////////////////////
#include "V8QueueJob.h"
#include "Basics/json.h"
#include "Dispatcher/DispatcherQueue.h"
#include "Logger/Logger.h"
#include "V8/v8-utils.h"

View File

@ -293,12 +293,6 @@ int TRI_CopyToJson(TRI_memory_zone_t*, TRI_json_t* dst, TRI_json_t const* src);
TRI_json_t* TRI_CopyJson(TRI_memory_zone_t*, TRI_json_t const*);
////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json string
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonString(TRI_memory_zone_t*, char const* text);
////////////////////////////////////////////////////////////////////////////////
/// @brief default deleter for TRI_json_t
/// this can be used to put a TRI_json_t with TRI_UNKNOWN_MEM_ZONE into an

View File

@ -10,21 +10,6 @@ include_directories(.)
# generate inside the source tree
if (USE_MAINTAINER_MODE AND NOT MSVC)
add_custom_command(
OUTPUT
${CMAKE_SOURCE_DIR}/lib/JsonParser/json-parser.cpp
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
COMMAND
${CMAKE_SOURCE_DIR}/utils/flex-c++.sh
${FLEX_EXECUTABLE}
lib/JsonParser/json-parser.cpp
lib/JsonParser/json-parser.ll
MAIN_DEPENDENCY
${CMAKE_SOURCE_DIR}/lib/JsonParser/json-parser.ll
VERBATIM
)
add_custom_command(
OUTPUT
${CMAKE_SOURCE_DIR}/lib/V8/v8-json.cpp
@ -190,7 +175,6 @@ add_library(${LIB_ARANGO} STATIC
Endpoint/EndpointIpV4.cpp
Endpoint/EndpointIpV6.cpp
Endpoint/EndpointList.cpp
JsonParser/json-parser.cpp
Logger/LogAppender.cpp
Logger/LogAppenderFile.cpp
Logger/LogAppenderSyslog.cpp

File diff suppressed because it is too large Load Diff

View File

@ -1,544 +0,0 @@
%top{
////////////////////////////////////////////////////////////////////////////////
/// @brief json parser
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-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 Dr. Frank Celler
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/json.h"
#include "Basics/tri-strings.h"
#ifdef _WIN32
#define YY_NO_UNISTD_H 1
#else
#ifndef __FreeBSD__
int fileno(FILE *stream);
#endif
#endif
#define YY_NO_INPUT
}
%option noyywrap nounput batch
%option 8bit
%option reentrant
%option extra-type="struct jsonData"
%option prefix="tri_jsp_"
ZERO [0]
DIGIT [0-9]
DIGIT1 [1-9]
MINUS [-]
PLUS [+]
%{
#define END_OF_FILE 0
#define FALSE_CONSTANT 1
#define TRUE_CONSTANT 2
#define NULL_CONSTANT 3
#define NUMBER_CONSTANT 4
#define STRING_CONSTANT 5
#define OPEN_BRACE 6
#define CLOSE_BRACE 7
#define OPEN_BRACKET 8
#define CLOSE_BRACKET 9
#define COMMA 10
#define COLON 11
#define UNQUOTED_STRING 12
#define STRING_CONSTANT_ASCII 13
static char const* EmptyString = "";
struct jsonData {
TRI_memory_zone_t* _memoryZone;
char const* _message;
};
#define YY_FATAL_ERROR(a) \
do { \
if (false) { \
yy_fatal_error(a, nullptr); \
} \
} \
while (0)
%}
%%
/* -----------------------------------------------------------------------------
* keywords
* ----------------------------------------------------------------------------- */
(?i:false) {
return FALSE_CONSTANT;
}
(?i:null) {
return NULL_CONSTANT;
}
(?i:true) {
return TRUE_CONSTANT;
}
/* -----------------------------------------------------------------------------
* strings
* ----------------------------------------------------------------------------- */
\"[ !\x23-\x5b\x5d-\x7f]*\" {
// performance optimisation for all-ASCII strings without escape characters
// this matches the ASCII chars with ordinal numbers 35 (x23) to 127 (x7f),
// plus space (32) and ! (33) but no quotation marks (34, x22) and backslashes (92, x5c)
return STRING_CONSTANT_ASCII;
}
\"(\\.|[^\\\"])*\" {
return STRING_CONSTANT;
}
/* -----------------------------------------------------------------------------
* numbers
* ----------------------------------------------------------------------------- */
({MINUS}|{PLUS})?({ZERO}|({DIGIT1}{DIGIT}*))((\.{DIGIT}+)?([eE]({MINUS}|{PLUS})?{DIGIT}+)?)? {
return NUMBER_CONSTANT;
}
/* -----------------------------------------------------------------------------
* special characters
* ----------------------------------------------------------------------------- */
"{" {
return OPEN_BRACE;
}
"}" {
return CLOSE_BRACE;
}
"[" {
return OPEN_BRACKET;
}
"]" {
return CLOSE_BRACKET;
}
"," {
return COMMA;
}
":" {
return COLON;
}
/* -----------------------------------------------------------------------------
* Skip whitespaces. Whatever is left, should be an unquoted string appearing
* somewhere. This will be reported as an error.
* ----------------------------------------------------------------------------- */
[ \t\r\n]* {
}
. {
return UNQUOTED_STRING;
}
%%
// -----------------------------------------------------------------------------
// --SECTION-- forward declarations
// -----------------------------------------------------------------------------
static bool ParseObject (yyscan_t, TRI_json_t*);
static bool ParseValue (yyscan_t, TRI_json_t*, int);
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief do not use, only here to silence compiler
////////////////////////////////////////////////////////////////////////////////
void TRI_JsonError (const char* msg) {
YY_FATAL_ERROR(msg);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief parses an array
////////////////////////////////////////////////////////////////////////////////
static bool ParseArray (yyscan_t scanner, TRI_json_t* result) {
struct yyguts_t * yyg = (struct yyguts_t*) scanner;
TRI_InitArrayJson(yyextra._memoryZone, result);
int c = yylex(scanner);
bool comma = false;
while (c != END_OF_FILE) {
if (c == CLOSE_BRACKET) {
return true;
}
if (comma) {
if (c != COMMA) {
yyextra._message = "expecting comma";
return false;
}
c = yylex(scanner);
}
else {
comma = true;
}
{
// optimization: get the address of the next element in the array
// so we can create the upcoming element in place
TRI_json_t* next = static_cast<TRI_json_t*>(TRI_NextVector(&result->_value._objects));
if (next == nullptr) {
yyextra._message = "out-of-memory";
return false;
}
// be paranoid and initialize the memory
TRI_InitNullJson(next);
if (! ParseValue(scanner, next, c)) {
// be paranoid
return false;
}
}
c = yylex(scanner);
}
yyextra._message = "expecting a list element, got end-of-file";
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief parse an object
////////////////////////////////////////////////////////////////////////////////
static bool ParseObject (yyscan_t scanner, TRI_json_t* result) {
struct yyguts_t * yyg = (struct yyguts_t*) scanner;
bool comma = false;
TRI_InitObjectJson(yyextra._memoryZone, result);
int c = yylex(scanner);
while (c != END_OF_FILE) {
if (c == CLOSE_BRACE) {
return true;
}
if (comma) {
if (c != COMMA) {
yyextra._message = "expecting comma";
return false;
}
c = yylex(scanner);
}
else {
comma = true;
}
char* name;
size_t nameLen;
// attribute name
if (c == STRING_CONSTANT) {
// utf-8 attribute name
size_t outLength;
nameLen = yyleng - 2;
// do proper unescaping
name = TRI_UnescapeUtf8String(yyextra._memoryZone, yytext + 1, nameLen, &outLength, true);
nameLen = outLength;
}
else if (c == STRING_CONSTANT_ASCII) {
// ASCII-only attribute name
nameLen = yyleng - 2;
// no unescaping necessary. just copy it
name = TRI_DuplicateString(yyextra._memoryZone, yytext + 1, nameLen);
}
else {
// some other token found => invalid
yyextra._message = "expecting attribute name";
return false;
}
if (name == nullptr) {
yyextra._message = "out-of-memory";
return false;
}
// followed by a colon
c = yylex(scanner);
if (c != COLON) {
TRI_FreeString(yyextra._memoryZone, name);
yyextra._message = "expecting colon";
return false;
}
// followed by an object
c = yylex(scanner);
{
// optimization: we allocate room for two elements at once
int res = TRI_ReserveVector(&result->_value._objects, 2);
if (res != TRI_ERROR_NO_ERROR) {
yyextra._message = "out-of-memory";
return false;
}
// get the address of the next element so we can create the attribute name in place
TRI_json_t* next = static_cast<TRI_json_t*>(TRI_NextVector(&result->_value._objects));
// we made sure with the reserve call that we haven't run out of memory
TRI_ASSERT(next != nullptr);
// store attribute name
TRI_InitStringJson(next, name, nameLen);
// now process the value
next = static_cast<TRI_json_t*>(TRI_NextVector(&result->_value._objects));
// we made sure with the reserve call that we haven't run out of memory
TRI_ASSERT(next != nullptr);
// be paranoid and initialize the memory
TRI_InitNullJson(next);
if (! ParseValue(scanner, next, c)) {
// be paranoid
return false;
}
}
c = yylex(scanner);
}
yyextra._message = "expecting a object attribute name or element, got end-of-file";
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief parse an object
////////////////////////////////////////////////////////////////////////////////
static bool ParseValue (yyscan_t scanner, TRI_json_t* result, int c) {
struct yyguts_t * yyg = (struct yyguts_t*) scanner;
switch (c) {
case FALSE_CONSTANT:
TRI_InitBooleanJson(result, false);
return true;
case TRUE_CONSTANT:
TRI_InitBooleanJson(result, true);
return true;
case NULL_CONSTANT:
TRI_InitNullJson(result);
return true;
case NUMBER_CONSTANT: {
char* ep;
double d;
if ((size_t) yyleng >= 512) {
yyextra._message = "number too big";
return false;
}
// need to reset errno because return value of 0 is not distinguishable from an error on Linux
errno = 0;
// yytext is null-terminated. can use it directly without copying it into a temporary buffer
d = strtod(yytext, &ep);
if (d == HUGE_VAL && errno == ERANGE) {
yyextra._message = "number too big";
return false;
}
if (d == 0 && errno == ERANGE) {
yyextra._message = "number too small";
return false;
}
if (ep != yytext + yyleng) {
yyextra._message = "cannot parse number";
return false;
}
TRI_InitNumberJson(result, d);
return true;
}
case STRING_CONSTANT: {
if (yyleng <= 2) {
// string is empty
char const* ptr = EmptyString; // we'll create a reference to this compiled-in string
TRI_InitStringReferenceJson(result, ptr, 0);
}
else {
// string is not empty, so process it
size_t outLength;
char* ptr = TRI_UnescapeUtf8String(yyextra._memoryZone, yytext + 1, yyleng - 2, &outLength, true);
if (ptr == nullptr) {
yyextra._message = "out-of-memory";
return false;
}
TRI_InitStringJson(result, ptr, outLength);
}
return true;
}
case STRING_CONSTANT_ASCII: {
if (yyleng <= 2) {
// string is empty
char const* ptr = EmptyString; // we'll create a reference to this compiled-in string
TRI_InitStringReferenceJson(result, ptr, 0);
}
else {
char* ptr = TRI_DuplicateString(yyextra._memoryZone, yytext + 1, yyleng - 2);
if (ptr == nullptr) {
yyextra._message = "out-of-memory";
return false;
}
TRI_InitStringJson(result, ptr, yyleng - 2);
}
return true;
}
case OPEN_BRACE:
return ParseObject(scanner, result);
case OPEN_BRACKET:
return ParseArray(scanner, result);
case CLOSE_BRACE:
yyextra._message = "expected object, got '}'";
return false;
case CLOSE_BRACKET:
yyextra._message = "expected object, got ']'";
return false;
case COMMA:
yyextra._message = "expected object, got ','";
return false;
case COLON:
yyextra._message = "expected object, got ':'";
return false;
case UNQUOTED_STRING:
yyextra._message = "expected object, got unquoted string";
return false;
case END_OF_FILE:
yyextra._message = "expecting atom, got end-of-file";
return false;
}
yyextra._message = "unknown atom";
return false;
}
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief parses a json string
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_JsonString (TRI_memory_zone_t* zone, char const* text) {
TRI_json_t* object;
YY_BUFFER_STATE buf;
int c;
struct yyguts_t * yyg;
yyscan_t scanner;
object = static_cast<TRI_json_t*>
(TRI_Allocate(zone, sizeof(TRI_json_t), false));
if (object == nullptr) {
// out of memory
return nullptr;
}
// init as a JSON null object so the memory in object is initialized
TRI_InitNullJson(object);
yylex_init(&scanner);
yyg = (struct yyguts_t*) scanner;
yyextra._memoryZone = zone;
buf = yy_scan_string((char yyconst*) text, scanner);
c = yylex(scanner);
if (! ParseValue(scanner, object, c)) {
TRI_FreeJson(zone, object);
object = nullptr;
}
else {
c = yylex(scanner);
if (c != END_OF_FILE) {
TRI_FreeJson(zone, object);
object = nullptr;
yyextra._message = "failed to parse json object: expecting EOF";
}
}
yy_delete_buffer(buf, scanner);
yylex_destroy(scanner);
return object;
}