Skip to content

Commit

Permalink
Merge pull request #16 from transceptor-technology/fixprio
Browse files Browse the repository at this point in the history
Fix bug in Prio element
  • Loading branch information
Jeroen van der Heijden authored Feb 19, 2020
2 parents fd2eb9c + ced6716 commit a8a1adc
Show file tree
Hide file tree
Showing 21 changed files with 413 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Release/src/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ C_DEPS += \
src/%.o: ../src/%.c
@echo 'Building file: $<'
@echo 'Invoking: Cross GCC Compiler'
gcc -DNDEBUG -I../inc -O3 -Wall $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
gcc -DNDEBUG -I../inc -O3 -Winline -Wall $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
3 changes: 2 additions & 1 deletion inc/cleri/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef struct cleri_node_s cleri_node_t;

/* private functions */
cleri_node_t * cleri__node_new(cleri_t * cl_obj, const char * str, size_t len);
void cleri__node_free(cleri_node_t * node);

/* private use as empty node */
extern cleri_node_t * CLERI_EMPTY_NODE;
Expand All @@ -40,4 +39,6 @@ struct cleri_node_s
size_t ref;
};



#endif /* CLERI_NODE_H_ */
21 changes: 21 additions & 0 deletions inc/cleri/node.inline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CLERI_NODE_INLINE_H_
#define CLERI_NODE_INLINE_H_

#include <cleri/node.h>
#include <cleri/children.h>

/*
* Destroy node. (parsing NULL is allowed)
*/
static inline void cleri__node_free(cleri_node_t * node)
{
/* node can be NULL or this could be an CLERI_EMPTY_NODE */
if (node == NULL || node == CLERI_EMPTY_NODE || --node->ref)
{
return;
}
cleri__children_free(node->children);
free(node);
}

#endif /* CLERI_NODE_INLINE_H_ */
2 changes: 1 addition & 1 deletion inc/cleri/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define CLERI_VERSION_MAJOR 0
#define CLERI_VERSION_MINOR 12
#define CLERI_VERSION_PATCH 0
#define CLERI_VERSION_PATCH 1

#define VERSION__STRINGIFY(num) #num
#define VERSION___STR(major,minor,patch) \
Expand Down
2 changes: 1 addition & 1 deletion makefile.init
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAJOR := 0
MINOR := 12
PATCH := 0
PATCH := 1
VERSION := $(MAJOR).$(MINOR).$(PATCH)
1 change: 1 addition & 0 deletions src/children.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#include <stdlib.h>
#include <cleri/children.h>
#include <cleri/node.inline.h>

/*
* Appends a node to children.
Expand Down
3 changes: 2 additions & 1 deletion src/choice.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/
#include <cleri/choice.h>
#include <cleri/node.h>
#include <cleri/node.inline.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>

static void choice__free(cleri_t * cl_object);

Expand Down
1 change: 1 addition & 0 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* list.c - cleri list element.
*/
#include <cleri/list.h>
#include <cleri/node.inline.h>
#include <stdlib.h>

static void list__free(cleri_t * cl_object);
Expand Down
15 changes: 0 additions & 15 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,3 @@ cleri_node_t * cleri__node_new(cleri_t * cl_obj, const char * str, size_t len)
}
return node;
}

/*
* Destroy node. (parsing NULL is allowed)
*/
void cleri__node_free(cleri_node_t * node)
{
/* node can be NULL or this could be an CLERI_EMPTY_NODE */
if (node == NULL || node == CLERI_EMPTY_NODE || --node->ref)
{
return;
}
cleri__children_free(node->children);
free(node);
}

1 change: 1 addition & 0 deletions src/optional.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#include <cleri/optional.h>
#include <cleri/expecting.h>
#include <cleri/node.inline.h>
#include <stdlib.h>

static void optional__free(cleri_t * cl_object);
Expand Down
1 change: 1 addition & 0 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#include <cleri/expecting.h>
#include <cleri/parse.h>
#include <cleri/node.inline.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
Expand Down
16 changes: 14 additions & 2 deletions src/prio.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include <cleri/prio.h>
#include <cleri/expecting.h>
#include <cleri/olist.h>
#include <cleri/node.inline.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>


static void prio__free(cleri_t * cl_obj);

static cleri_node_t * prio__parse(
Expand Down Expand Up @@ -116,11 +116,23 @@ static cleri_node_t * prio__parse(
olist->cl_obj,
rule,
CLERI__EXP_MODE_REQUIRED);

if (rnode != NULL &&
(tested->node == NULL || node->len > tested->node->len))
{
cleri__node_free(tested->node);
if (tested->node != NULL)
{
/*
* It is required to decrement an extra reference here, one
* belongs to the parse result, and one for the tested rule.
* The node->ref increment below is required for when a str
* position is visited a second time by another parent.
*/
--tested->node->ref;
cleri__node_free(tested->node);
}
tested->node = node;
node->ref++;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* regex.c - cleri regular expression element.
*/
#include <cleri/regex.h>
#include <cleri/node.inline.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions src/repeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* repeat.c - cleri regular repeat element.
*/
#include <cleri/repeat.h>
#include <cleri/node.inline.h>
#include <stdlib.h>
#include <assert.h>

Expand Down
6 changes: 5 additions & 1 deletion src/rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* create a 'prio' instead which will be wrapped by a rule element)
*/
#include <cleri/rule.h>
#include <cleri/node.inline.h>
#include <stdlib.h>

static void rule__free(cleri_t * cl_object);
Expand Down Expand Up @@ -74,7 +75,7 @@ cleri_rule_test_t cleri__rule_init(
return CLERI_RULE_TRUE;
}

while ((*target) != NULL)
do
{
if ((*target)->str == str)
{
Expand All @@ -83,6 +84,8 @@ cleri_rule_test_t cleri__rule_init(
prev = (*target);
(*target) = (*target)->next;
}
while ((*target) != NULL);

*target = prev->next = cleri__malloc(cleri_rule_tested_t);

if (*target == NULL)
Expand Down Expand Up @@ -212,6 +215,7 @@ static void rule__tested_free(cleri_rule_tested_t * tested)
while (tested != NULL)
{
next = tested->next;
cleri__node_free(tested->node);
free(tested);
tested = next;
}
Expand Down
1 change: 1 addition & 0 deletions src/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* sequence.c - cleri sequence element.
*/
#include <cleri/sequence.h>
#include <cleri/node.inline.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
5 changes: 3 additions & 2 deletions src/this.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#include <cleri/expecting.h>
#include <cleri/this.h>
#include <cleri/node.inline.h>
#include <stdlib.h>
#include <assert.h>

Expand Down Expand Up @@ -59,13 +60,13 @@ static cleri_node_t * cleri_parse_this(
pr->is_valid = -1;
return NULL;
}
assert(tested->node == NULL);
tested->node = cleri__parse_walk(
pr,
node,
rule->root_obj,
rule,
CLERI__EXP_MODE_REQUIRED);

if (tested->node == NULL)
{
cleri__node_free(node);
Expand Down Expand Up @@ -94,7 +95,7 @@ static cleri_node_t * cleri_parse_this(
{
/* error occurred, reverse changes set mg_node to NULL */
pr->is_valid = -1;
parent->len -= tested->node->len;
parent->len -= tested->node->len;
cleri__node_free(node);
node = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions src/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* expression)
*/
#include <cleri/token.h>
#include <cleri/node.inline.h>
#include <stdlib.h>
#include <string.h>

Expand Down
1 change: 1 addition & 0 deletions src/tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* in one element)
*/
#include <cleri/tokens.h>
#include <cleri/node.inline.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand Down
22 changes: 22 additions & 0 deletions test/test_thingsdb_lang/sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
../src/children.c
../src/choice.c
../src/cleri.c
../src/dup.c
../src/expecting.c
../src/grammar.c
../src/keyword.c
../src/kwcache.c
../src/list.c
../src/node.c
../src/olist.c
../src/optional.c
../src/parse.c
../src/prio.c
../src/ref.c
../src/regex.c
../src/repeat.c
../src/rule.c
../src/sequence.c
../src/this.c
../src/token.c
../src/tokens.c
Loading

0 comments on commit a8a1adc

Please sign in to comment.