mirror of https://gitee.com/bigwinds/arangodb
some refactoring of the parser
This commit is contained in:
parent
6ab4e2b570
commit
791232b8f1
|
@ -42,7 +42,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ABORT_OOM \
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \
|
||||
return NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -105,6 +105,16 @@ static inline void InitNode (TRI_aql_context_t* const context,
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an AST main node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_node_t* TRI_CreateNodeMainAql (TRI_aql_context_t* const context) {
|
||||
CREATE_NODE(AQL_NODE_MAIN)
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an AST for node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -119,7 +129,7 @@ TRI_aql_node_t* TRI_CreateNodeForAql (TRI_aql_context_t* const context,
|
|||
}
|
||||
|
||||
if (!TRI_IsValidVariableNameAql(name)) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_VARIABLE_NAME_INVALID, name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_VARIABLE_NAME_INVALID, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -131,6 +141,7 @@ TRI_aql_node_t* TRI_CreateNodeForAql (TRI_aql_context_t* const context,
|
|||
|
||||
return node;
|
||||
}
|
||||
|
||||
/*
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an AST let node
|
||||
|
@ -287,7 +298,7 @@ TRI_aql_node_t* TRI_CreateNodeVariableAql (TRI_aql_context_t* const context,
|
|||
|
||||
if (!TRI_AddVariableContextAql(context, name)) {
|
||||
// duplicate variable name
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_VARIABLE_REDECLARED, name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_VARIABLE_REDECLARED, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -842,7 +853,7 @@ TRI_aql_node_t* TRI_CreateNodeFcallAql (TRI_aql_context_t* const context,
|
|||
|
||||
if (!function) {
|
||||
// function name is unknown
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_FUNCTION_NAME_UNKNOWN, name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_FUNCTION_NAME_UNKNOWN, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ extern "C" {
|
|||
|
||||
typedef enum {
|
||||
AQL_NODE_UNDEFINED = 0,
|
||||
AQL_NODE_MAIN,
|
||||
AQL_NODE_FOR,
|
||||
AQL_NODE_LET,
|
||||
AQL_NODE_FILTER,
|
||||
|
@ -239,6 +240,12 @@ TRI_aql_node_t;
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an AST main node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_node_t* TRI_CreateNodeMainAql (TRI_aql_context_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create an AST for node
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -83,7 +83,7 @@ static TRI_aql_node_t* CreateNodeFromJson (TRI_aql_context_t* const context,
|
|||
TRI_PushBackVectorPointer(&node->_subNodes, (void*) subNode);
|
||||
}
|
||||
else {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ static TRI_aql_node_t* CreateNodeFromJson (TRI_aql_context_t* const context,
|
|||
|
||||
valueNode = CreateNodeFromJson(context, valueJson);
|
||||
if (!valueNode) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ static TRI_aql_node_t* CreateNodeFromJson (TRI_aql_context_t* const context,
|
|||
TRI_PushBackVectorPointer(&node->_subNodes, (void*) subNode);
|
||||
}
|
||||
else {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ static TRI_aql_node_t* CreateNodeFromJson (TRI_aql_context_t* const context,
|
|||
}
|
||||
|
||||
if (!node) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
}
|
||||
|
||||
return node;
|
||||
|
@ -287,7 +287,7 @@ bool TRI_AddParameterValuesAql (TRI_aql_context_t* const context,
|
|||
|
||||
if (parameters->_type != TRI_JSON_ARRAY) {
|
||||
// parameters must be a list
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_BIND_PARAMETERS_INVALID, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_BIND_PARAMETERS_INVALID, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ bool TRI_AddParameterValuesAql (TRI_aql_context_t* const context,
|
|||
|
||||
parameter = CreateParameter(name->_value._string.data, value);
|
||||
if (!parameter) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ bool TRI_ValidateBindParametersAql (TRI_aql_context_t* const context) {
|
|||
}
|
||||
|
||||
if (!TRI_LookupByKeyAssociativePointer(&context->_parameterValues, name)) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_BIND_PARAMETER_MISSING, name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_BIND_PARAMETER_MISSING, name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ bool TRI_ValidateBindParametersAql (TRI_aql_context_t* const context) {
|
|||
assert(parameter->_name);
|
||||
|
||||
if (!TRI_LookupByKeyAssociativePointer(&context->_parameterNames, parameter->_name)) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_BIND_PARAMETER_UNDECLARED, parameter->_name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_BIND_PARAMETER_UNDECLARED, parameter->_name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ bool TRI_InjectBindParametersAql (TRI_aql_context_t* const context,
|
|||
|
||||
walker = TRI_CreateModifyTreeWalkerAql(context, &ModifyNode);
|
||||
if (!walker) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ bool SetupCollections (TRI_aql_context_t* const context) {
|
|||
collection = CreateCollectionContainer(name);
|
||||
if (!collection) {
|
||||
result = false;
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ bool OpenCollections (TRI_aql_context_t* const context) {
|
|||
name = collection->_name;
|
||||
collection->_collection = TRI_UseCollectionByNameVocBase(context->_vocbase, name);
|
||||
if (!collection->_collection) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_COLLECTION_NOT_FOUND, name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_COLLECTION_NOT_FOUND, name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ bool TRI_ReadLockCollectionsAql (TRI_aql_context_t* const context) {
|
|||
if (lockResult != TRI_ERROR_NO_ERROR) {
|
||||
// couldn't acquire the read lock
|
||||
result = false;
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_COLLECTION_LOCK_FAILED, collection->_name);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_COLLECTION_LOCK_FAILED, collection->_name);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
@ -314,7 +314,7 @@ bool TRI_AddBarrierCollectionsAql (TRI_aql_context_t* const context) {
|
|||
if (!ce) {
|
||||
// couldn't create the barrier
|
||||
result = false;
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -50,7 +50,7 @@ static TRI_aql_node_t* OptimiseUnaryArithmeticOperation (TRI_aql_context_t* cons
|
|||
|
||||
if (!TRI_IsNumericValueNodeAql(operand)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ static TRI_aql_node_t* OptimiseUnaryArithmeticOperation (TRI_aql_context_t* cons
|
|||
// - number => eval!
|
||||
node = TRI_CreateNodeValueDoubleAql(context, - TRI_GetNumericNodeValueAql(operand));
|
||||
if (!node) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ static TRI_aql_node_t* OptimiseUnaryLogicalOperation (TRI_aql_context_t* const c
|
|||
|
||||
if (!TRI_IsBooleanValueNodeAql(operand)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ static TRI_aql_node_t* OptimiseUnaryLogicalOperation (TRI_aql_context_t* const c
|
|||
// ! bool => evaluate
|
||||
node = TRI_CreateNodeValueBoolAql(context, ! TRI_GetBooleanNodeValueAql(operand));
|
||||
if (!node) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,13 +125,13 @@ static TRI_aql_node_t* OptimiseBinaryLogicalOperation (TRI_aql_context_t* const
|
|||
|
||||
if (isEligibleLhs && !TRI_IsBooleanValueNodeAql(lhs)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
if (isEligibleRhs && !TRI_IsBooleanValueNodeAql(rhs)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -189,19 +189,19 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con
|
|||
|
||||
if (isEligibleLhs && !TRI_IsNumericValueNodeAql(lhs)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
if (isEligibleRhs && !TRI_IsNumericValueNodeAql(rhs)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
if (TRI_IsConstantValueNodeAql(rhs) && !TRI_IsNumericValueNodeAql(rhs)) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con
|
|||
else if (node->_type == AQL_NODE_OPERATOR_BINARY_DIV) {
|
||||
if (TRI_GetNumericNodeValueAql(rhs) == 0.0) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
value = TRI_GetNumericNodeValueAql(lhs) / TRI_GetNumericNodeValueAql(rhs);
|
||||
|
@ -235,7 +235,7 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con
|
|||
else if (node->_type == AQL_NODE_OPERATOR_BINARY_MOD) {
|
||||
if (TRI_GetNumericNodeValueAql(rhs) == 0.0) {
|
||||
// todo: fix error message
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
value = fmod(TRI_GetNumericNodeValueAql(lhs), TRI_GetNumericNodeValueAql(rhs));
|
||||
|
@ -243,7 +243,7 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con
|
|||
|
||||
node = TRI_CreateNodeValueDoubleAql(context, value);
|
||||
if (!node) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ TRI_aql_node_t* TRI_FoldConstantsAql (TRI_aql_context_t* const context,
|
|||
|
||||
walker = TRI_CreateModifyTreeWalkerAql((void*) context, &ModifyNode);
|
||||
if (!walker) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser types and helper functionality
|
||||
/// @brief Ahuacatl, query context
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
@ -25,11 +25,12 @@
|
|||
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-ast-node.h"
|
||||
#include "Ahuacatl/ahuacatl-bind-parameter.h"
|
||||
#include "Ahuacatl/ahuacatl-collections.h"
|
||||
#include "Ahuacatl/ahuacatl-constant-folder.h"
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-parser-functions.h"
|
||||
#include "Ahuacatl/ahuacatl-tree-dump.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -46,7 +47,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ABORT_OOM \
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \
|
||||
return NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -99,7 +100,7 @@ static bool EqualVariable (TRI_associative_pointer_t* array,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create and initialize a parse context
|
||||
/// @brief create and initialize a context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t* vocbase,
|
||||
|
@ -152,23 +153,24 @@ TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t* vocbase,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
context->_parser = (TRI_aql_parser_t*) TRI_Allocate(sizeof(TRI_aql_parser_t));
|
||||
context->_parser = TRI_CreateParserAql(context->_query);
|
||||
if (!context->_parser) {
|
||||
// could not create the parser
|
||||
TRI_FreeContextAql(context);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
context->_parser->_buffer = context->_query;
|
||||
context->_parser->_length = strlen(context->_query);
|
||||
|
||||
Ahuacatllex_init(&context->_parser->_scanner);
|
||||
Ahuacatlset_extra(context, context->_parser->_scanner);
|
||||
if (!TRI_InitParserAql(context)) {
|
||||
// could not initialise the lexer
|
||||
TRI_FreeContextAql(context);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief free a parse context
|
||||
/// @brief free a context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_FreeContextAql (TRI_aql_context_t* const context) {
|
||||
|
@ -237,17 +239,14 @@ void TRI_FreeContextAql (TRI_aql_context_t* const context) {
|
|||
TRI_FreeBindParametersAql(context);
|
||||
TRI_DestroyAssociativePointer(&context->_parameterValues);
|
||||
|
||||
// free parser/lexer
|
||||
TRI_FreeParserAql(context->_parser);
|
||||
|
||||
// free query string
|
||||
if (context->_query) {
|
||||
TRI_Free(context->_query);
|
||||
}
|
||||
|
||||
// free lexer
|
||||
if (context->_parser) {
|
||||
Ahuacatllex_destroy(context->_parser->_scanner);
|
||||
TRI_Free(context->_parser);
|
||||
}
|
||||
|
||||
// free error struct
|
||||
TRI_DestroyErrorAql(&context->_error);
|
||||
|
||||
|
@ -260,7 +259,7 @@ void TRI_FreeContextAql (TRI_aql_context_t* const context) {
|
|||
|
||||
bool TRI_ValidateQueryContextAql (TRI_aql_context_t* const context) {
|
||||
// parse the query
|
||||
if (Ahuacatlparse(context)) {
|
||||
if (!TRI_ParseAql(context)) {
|
||||
// lexing/parsing failed
|
||||
return false;
|
||||
}
|
||||
|
@ -388,7 +387,7 @@ void TRI_FreeScopeAql (TRI_aql_scope_t* const scope) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_RegisterNodeContextAql (TRI_aql_context_t* const context,
|
||||
void* const node) {
|
||||
void* const node) {
|
||||
assert(context);
|
||||
assert(node);
|
||||
|
||||
|
@ -401,9 +400,9 @@ bool TRI_RegisterNodeContextAql (TRI_aql_context_t* const context,
|
|||
/// @brief register an error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetErrorAql (TRI_aql_context_t* const context,
|
||||
const int code,
|
||||
const char* const data) {
|
||||
void TRI_SetErrorContextAql (TRI_aql_context_t* const context,
|
||||
const int code,
|
||||
const char* const data) {
|
||||
|
||||
assert(context);
|
||||
assert(code > 0);
|
||||
|
@ -419,27 +418,6 @@ void TRI_SetErrorAql (TRI_aql_context_t* const context,
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a parse error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetParseErrorAql (TRI_aql_context_t* const context,
|
||||
const char* const message,
|
||||
const int line,
|
||||
const int column) {
|
||||
char buffer[1024];
|
||||
|
||||
snprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"%d:%d %s near '%s'",
|
||||
line,
|
||||
column,
|
||||
message,
|
||||
TRI_GetContextErrorAql(context->_query, line, column));
|
||||
|
||||
TRI_SetErrorAql(context, TRI_ERROR_QUERY_PARSE, buffer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief push something on the stack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -536,7 +514,7 @@ bool TRI_AddStatementAql (TRI_aql_context_t* const context,
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create a new variable scope and stack it in the parser context
|
||||
/// @brief create a new variable scope and stack it in the context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_scope_t* TRI_StartScopeContextAql (TRI_aql_context_t* const context) {
|
||||
|
@ -554,7 +532,7 @@ TRI_aql_scope_t* TRI_StartScopeContextAql (TRI_aql_context_t* const context) {
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief remove a variable scope from parser context scopes stack
|
||||
/// @brief remove a variable scope from context scopes stack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_EndScopeContextAql (TRI_aql_context_t* const context) {
|
||||
|
@ -705,7 +683,7 @@ bool TRI_VariableExistsAql (TRI_aql_context_t* const context,
|
|||
size_t current = context->_scopes._length;
|
||||
|
||||
if (!name) {
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser types and helper functionality
|
||||
/// @brief Ahuacatl, query context
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
|
@ -25,8 +25,8 @@
|
|||
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_DURHAM_AHUACATL_PARSER_H
|
||||
#define TRIAGENS_DURHAM_AHUACATL_PARSER_H 1
|
||||
#ifndef TRIAGENS_DURHAM_AHUACATL_CONTEXT_H
|
||||
#define TRIAGENS_DURHAM_AHUACATL_CONTEXT_H 1
|
||||
|
||||
#include <BasicsC/common.h>
|
||||
#include <BasicsC/strings.h>
|
||||
|
@ -37,7 +37,9 @@
|
|||
|
||||
#include "VocBase/vocbase.h"
|
||||
#include "VocBase/collection.h"
|
||||
|
||||
#include "Ahuacatl/ahuacatl-error.h"
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -73,22 +75,11 @@ typedef struct TRI_aql_scope_s {
|
|||
}
|
||||
TRI_aql_scope_t;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the parser
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct TRI_aql_parser_s {
|
||||
void* _scanner;
|
||||
char* _buffer;
|
||||
size_t _length;
|
||||
}
|
||||
TRI_aql_parser_t;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the context for parsing a query
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct TRI_aql_parse_context_s {
|
||||
typedef struct TRI_aql_context_s {
|
||||
TRI_aql_parser_t* _parser;
|
||||
TRI_vector_pointer_t _scopes;
|
||||
TRI_vector_pointer_t _nodes;
|
||||
|
@ -119,14 +110,14 @@ TRI_aql_context_t;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create and initialize a parse context
|
||||
/// @brief create and initialize a context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_context_t* TRI_CreateContextAql (TRI_vocbase_t*,
|
||||
const char* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief free a parse context
|
||||
/// @brief free a context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_FreeContextAql (TRI_aql_context_t* const);
|
||||
|
@ -172,24 +163,15 @@ void TRI_FreeScopeAql (TRI_aql_scope_t* const);
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_RegisterNodeContextAql (TRI_aql_context_t* const,
|
||||
void* const);
|
||||
void* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register an error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetErrorAql (TRI_aql_context_t* const,
|
||||
const int,
|
||||
const char* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a parse error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetParseErrorAql (TRI_aql_context_t* const,
|
||||
const char* const,
|
||||
const int,
|
||||
const int);
|
||||
void TRI_SetErrorContextAql (TRI_aql_context_t* const,
|
||||
const int,
|
||||
const char* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief push something on the stack
|
||||
|
@ -222,13 +204,13 @@ void* TRI_GetFirstStatementAql (TRI_aql_context_t* const);
|
|||
bool TRI_AddStatementAql (TRI_aql_context_t* const, const void* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create a new variable scope and stack it in the parser context
|
||||
/// @brief create a new variable scope and stack it in the context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_scope_t* TRI_StartScopeContextAql (TRI_aql_context_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief remove a variable scope from parser context scopes stack
|
||||
/// @brief remove a variable scope from context scopes stack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_EndScopeContextAql (TRI_aql_context_t* const);
|
||||
|
@ -281,31 +263,6 @@ bool TRI_IsValidVariableNameAql (const char* const);
|
|||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- forwards
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief forwards for functions provided by the lexer (tokens.c)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Ahuacatlparse (TRI_aql_context_t* const);
|
||||
|
||||
int Ahuacatllex_destroy (void *);
|
||||
|
||||
void Ahuacatlset_extra (TRI_aql_context_t* const, void*);
|
||||
|
||||
int Ahuacatllex_init (void**);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -78,7 +78,6 @@
|
|||
/* Line 189 of yacc.c */
|
||||
#line 10 "Ahuacatl/ahuacatl-grammar.y"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -89,7 +88,8 @@
|
|||
#include "Ahuacatl/ahuacatl-ast-node.h"
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-error.h"
|
||||
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
#include "Ahuacatl/ahuacatl-parser-functions.h"
|
||||
|
||||
|
||||
/* Line 189 of yacc.c */
|
||||
|
@ -226,7 +226,7 @@ int Ahuacatllex (YYSTYPE*, YYLTYPE*, void*);
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ahuacatlerror (YYLTYPE* locp, TRI_aql_context_t* const context, const char* err) {
|
||||
TRI_SetParseErrorAql(context, err, locp->first_line, locp->first_column);
|
||||
TRI_SetErrorParseAql(context, err, locp->first_line, locp->first_column);
|
||||
}
|
||||
|
||||
#define scanner context->_parser->_scanner
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
%error-verbose
|
||||
|
||||
%{
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -19,7 +18,8 @@
|
|||
#include "Ahuacatl/ahuacatl-ast-node.h"
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-error.h"
|
||||
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
#include "Ahuacatl/ahuacatl-parser-functions.h"
|
||||
%}
|
||||
|
||||
%union {
|
||||
|
@ -42,7 +42,7 @@ int Ahuacatllex (YYSTYPE*, YYLTYPE*, void*);
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ahuacatlerror (YYLTYPE* locp, TRI_aql_context_t* const context, const char* err) {
|
||||
TRI_SetParseErrorAql(context, err, locp->first_line, locp->first_column);
|
||||
TRI_SetErrorParseAql(context, err, locp->first_line, locp->first_column);
|
||||
}
|
||||
|
||||
#define scanner context->_parser->_scanner
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser functionality
|
||||
///
|
||||
/// @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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Ahuacatl/ahuacatl-parser-functions.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private macros
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief shortcut macro for signalling out of memory
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ABORT_OOM \
|
||||
TRI_SetErrorAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); \
|
||||
return NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief init the lexer
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_InitParserAql (TRI_aql_context_t* const context) {
|
||||
assert(context);
|
||||
assert(context->_parser);
|
||||
|
||||
Ahuacatllex_init(&context->_parser->_scanner);
|
||||
Ahuacatlset_extra(context, context->_parser->_scanner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parse & validate the query string
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_ParseAql (TRI_aql_context_t* const context) {
|
||||
if (Ahuacatlparse(context)) {
|
||||
// lexing/parsing failed
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a parse error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetErrorParseAql (TRI_aql_context_t* const context,
|
||||
const char* const message,
|
||||
const int line,
|
||||
const int column) {
|
||||
char buffer[1024];
|
||||
|
||||
snprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"%d:%d %s near '%s'",
|
||||
line,
|
||||
column,
|
||||
message,
|
||||
TRI_GetContextErrorAql(context->_query, line, column));
|
||||
|
||||
TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_PARSE, buffer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -0,0 +1,121 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser functionality
|
||||
///
|
||||
/// @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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_DURHAM_AHUACATL_PARSER_FUNCTIONS_H
|
||||
#define TRIAGENS_DURHAM_AHUACATL_PARSER_FUNCTIONS_H 1
|
||||
|
||||
#include <BasicsC/common.h>
|
||||
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-error.h"
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- forwards
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief forwards for the parse function provided by the parser (.y)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Ahuacatlparse (TRI_aql_context_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief forward for the init function provided by the lexer (.l)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Ahuacatllex_init (void**);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief forward for the shutdown function provided by the lexer (.l)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Ahuacatllex_destroy (void *);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief forward for the context function provided by the lexer (.l)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ahuacatlset_extra (TRI_aql_context_t* const, void*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief init the lexer
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_InitParserAql (TRI_aql_context_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parse & validate the query string
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_ParseAql (TRI_aql_context_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief register a parse error
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_SetErrorParseAql (TRI_aql_context_t* const,
|
||||
const char* const,
|
||||
const int,
|
||||
const int);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -0,0 +1,78 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser
|
||||
///
|
||||
/// @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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create the parser
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_parser_t* TRI_CreateParserAql (const char* const query) {
|
||||
TRI_aql_parser_t* parser;
|
||||
|
||||
assert(query);
|
||||
|
||||
parser = (TRI_aql_parser_t*) TRI_Allocate(sizeof(TRI_aql_parser_t));
|
||||
if (!parser) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
parser->_buffer = (char*) query;
|
||||
parser->_length = strlen(query);
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief free a parse context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_FreeParserAql (TRI_aql_parser_t* const parser) {
|
||||
// free lexer
|
||||
if (parser) {
|
||||
Ahuacatllex_destroy(parser->_scanner);
|
||||
TRI_Free(parser);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -0,0 +1,95 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Ahuacatl, parser
|
||||
///
|
||||
/// @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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TRIAGENS_DURHAM_AHUACATL_PARSER_H
|
||||
#define TRIAGENS_DURHAM_AHUACATL_PARSER_H 1
|
||||
|
||||
#include <BasicsC/common.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public types
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the parser
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct TRI_aql_parser_s {
|
||||
void* _scanner; // the lexer generated by flex
|
||||
char* _buffer; // the currently procssed part of the query string
|
||||
size_t _length; // length of the query string
|
||||
}
|
||||
TRI_aql_parser_t;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup Ahuacatl
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create the parser
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_aql_parser_t* TRI_CreateParserAql (const char* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief free a parse context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_FreeParserAql (TRI_aql_parser_t* const);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
|
@ -654,6 +654,7 @@ static yyconst flex_int16_t yy_rule_linenum[47] =
|
|||
#include "Ahuacatl/ahuacatl-ast-node.h"
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-grammar.h"
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
|
||||
#define YY_EXTRA_TYPE TRI_aql_context_t*
|
||||
|
||||
|
@ -662,7 +663,7 @@ static yyconst flex_int16_t yy_rule_linenum[47] =
|
|||
#define YY_NO_INPUT 1
|
||||
|
||||
#define YY_INPUT(resultBuffer, resultState, maxBytesToRead) { \
|
||||
TRI_aql_parser_t* parser = (yyextra)->_parser; \
|
||||
TRI_aql_parser_t* parser = (TRI_aql_parser_t*) (yyextra)->_parser; \
|
||||
int length = parser->_length; \
|
||||
if (length > maxBytesToRead) { \
|
||||
length = maxBytesToRead; \
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Ahuacatl/ahuacatl-ast-node.h"
|
||||
#include "Ahuacatl/ahuacatl-context.h"
|
||||
#include "Ahuacatl/ahuacatl-grammar.h"
|
||||
#include "Ahuacatl/ahuacatl-parser.h"
|
||||
|
||||
#define YY_EXTRA_TYPE TRI_aql_context_t*
|
||||
|
||||
|
@ -22,7 +23,7 @@
|
|||
#define YY_NO_INPUT 1
|
||||
|
||||
#define YY_INPUT(resultBuffer, resultState, maxBytesToRead) { \
|
||||
TRI_aql_parser_t* parser = (yyextra)->_parser; \
|
||||
TRI_aql_parser_t* parser = (TRI_aql_parser_t*) (yyextra)->_parser; \
|
||||
int length = parser->_length; \
|
||||
if (length > maxBytesToRead) { \
|
||||
length = maxBytesToRead; \
|
||||
|
@ -37,7 +38,6 @@
|
|||
resultState = YY_NULL; \
|
||||
} \
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%%
|
||||
|
|
|
@ -45,6 +45,8 @@ static char* GetTypeName (const TRI_aql_node_type_e type) {
|
|||
case AQL_NODE_UNDEFINED:
|
||||
assert(false);
|
||||
return "undefined";
|
||||
case AQL_NODE_MAIN:
|
||||
return "main";
|
||||
case AQL_NODE_FOR:
|
||||
return "for";
|
||||
case AQL_NODE_LET:
|
||||
|
|
|
@ -159,6 +159,8 @@ avocado_SOURCES = \
|
|||
Ahuacatl/ahuacatl-error.c \
|
||||
Ahuacatl/ahuacatl-functions.c \
|
||||
Ahuacatl/ahuacatl-grammar.c \
|
||||
Ahuacatl/ahuacatl-parser.c \
|
||||
Ahuacatl/ahuacatl-parser-functions.c \
|
||||
Ahuacatl/ahuacatl-result.c \
|
||||
Ahuacatl/ahuacatl-tokens.c \
|
||||
Ahuacatl/ahuacatl-tree-dump.c \
|
||||
|
|
12
Makefile.in
12
Makefile.in
|
@ -335,6 +335,8 @@ am_avocado_OBJECTS = Admin/ApplicationAdminServer.$(OBJEXT) \
|
|||
Ahuacatl/ahuacatl-error.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-functions.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-grammar.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-parser.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-parser-functions.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-result.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-tokens.$(OBJEXT) \
|
||||
Ahuacatl/ahuacatl-tree-dump.$(OBJEXT) \
|
||||
|
@ -765,6 +767,8 @@ avocado_SOURCES = \
|
|||
Ahuacatl/ahuacatl-error.c \
|
||||
Ahuacatl/ahuacatl-functions.c \
|
||||
Ahuacatl/ahuacatl-grammar.c \
|
||||
Ahuacatl/ahuacatl-parser.c \
|
||||
Ahuacatl/ahuacatl-parser-functions.c \
|
||||
Ahuacatl/ahuacatl-result.c \
|
||||
Ahuacatl/ahuacatl-tokens.c \
|
||||
Ahuacatl/ahuacatl-tree-dump.c \
|
||||
|
@ -1663,6 +1667,10 @@ Ahuacatl/ahuacatl-functions.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
|
|||
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
|
||||
Ahuacatl/ahuacatl-grammar.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
|
||||
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
|
||||
Ahuacatl/ahuacatl-parser.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
|
||||
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
|
||||
Ahuacatl/ahuacatl-parser-functions.$(OBJEXT): \
|
||||
Ahuacatl/$(am__dirstamp) Ahuacatl/$(DEPDIR)/$(am__dirstamp)
|
||||
Ahuacatl/ahuacatl-result.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
|
||||
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
|
||||
Ahuacatl/ahuacatl-tokens.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
|
||||
|
@ -1921,6 +1929,8 @@ mostlyclean-compile:
|
|||
-rm -f Ahuacatl/ahuacatl-error.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-functions.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-grammar.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-parser-functions.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-parser.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-result.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-tokens.$(OBJEXT)
|
||||
-rm -f Ahuacatl/ahuacatl-tree-dump.$(OBJEXT)
|
||||
|
@ -2155,6 +2165,8 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-error.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-functions.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-grammar.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-parser-functions.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-parser.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-result.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-tokens.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-tree-dump.Po@am__quote@
|
||||
|
|
Loading…
Reference in New Issue