Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimaciel committed Jul 21, 2019
1 parent 767cd81 commit 6e20206
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/deserializer/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "token.h"

struct input_t {
unsigned char *limit;
unsigned char *cursor;
unsigned char *marker;
unsigned char *buffer;
unsigned char *token; /* points to the beginning of the current lexeme */
char *limit;
char *cursor;
char *marker;
char *buffer;
char *token; /* points to the beginning of the current lexeme */
size_t buffer_size;
unsigned short padding;
int has_reached_eof;
Expand Down
38 changes: 22 additions & 16 deletions src/deserializer/rivest_canonical_lexer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Generated by re2c 1.0.1 on Thu Apr 18 23:40:29 2019 */
/* Generated by re2c 1.0.1 on Sun Jul 21 09:47:00 2019 */
#line 1 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#include "rivest_canonical_lexer.h"

Expand All @@ -10,6 +10,8 @@

struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
{
char *t2 = NULL;

assert(stream != NULL);
assert(input != NULL);

Expand All @@ -21,10 +23,10 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
}

input->token = input->cursor;
unsigned char *t2 = input->token;
t2 = input->token;


#line 28 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 30 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
{
char yych;
yych = *input->cursor;
Expand All @@ -45,33 +47,33 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
}
yy2:
++input->cursor;
#line 73 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 79 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
{
return (struct token_t) {TOKEN_RIVEST_EOF, NULL} ;
}
#line 53 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 55 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
yy4:
++input->cursor;
yy5:
#line 77 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 83 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
{
return (struct token_t) {TOKEN_RIVEST_ERROR, NULL};
}
#line 61 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 63 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
yy6:
++input->cursor;
#line 34 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 36 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
{
return (struct token_t) {TOKEN_RIVEST_PARENTHESIS_OPEN, NULL};
}
#line 68 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 70 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
yy8:
++input->cursor;
#line 38 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 40 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
{
return (struct token_t) {TOKEN_RIVEST_PARENTHESIS_CLOSE, NULL};
}
#line 75 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 77 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
yy10:
yych = *(input->marker = ++input->cursor);
switch (yych) {
Expand Down Expand Up @@ -111,15 +113,18 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
yy14:
++input->cursor;
t2 = input->cursor;
#line 42 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 44 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
{
struct token_string_t *s = NULL;
char * text = NULL;

const long text_size = strtol((const char *)input->token, NULL, 10);
if(errno != 0)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
}

struct token_string_t *s = (struct token_string_t *)malloc(sizeof(struct token_string_t));
s = (struct token_string_t *)malloc(sizeof(struct token_string_t));
if(s == NULL)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
Expand All @@ -128,23 +133,24 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
input->cursor = input->marker = input->token = t2;
input_fill(stream,input,1);

char * text = (char *)malloc(sizeof(char)*text_size);
text = (char *)malloc(sizeof(char)*(text_size+1));
if(text ==NULL)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
}

text = strncpy(text, input->token, text_size);
text[text_size] = '\0';

*s = (struct token_string_t){text_size,text};

input->cursor = input->marker = input->token = input->token + text_size;

return (struct token_t) { TOKEN_RIVEST_LPVERBATIM_STRING, s};
}
#line 146 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
#line 152 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c"
}
#line 80 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"
#line 86 "/home/rui/development/C/msexpr/src/deserializer/rivest_canonical_lexer.c.re2c"


/* this part should not be reached */
Expand Down
12 changes: 9 additions & 3 deletions src/deserializer/rivest_canonical_lexer.c.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
{
char *t2 = NULL;

assert(stream != NULL);
assert(input != NULL);

Expand All @@ -19,7 +21,7 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
}

input->token = input->cursor;
unsigned char *t2 = input->token;
t2 = input->token;

/*!re2c
re2c:define:YYCTYPE = char;
Expand All @@ -40,13 +42,16 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
}

decimal ':' @t2 {
struct token_string_t *s = NULL;
char * text = NULL;

const long text_size = strtol((const char *)input->token, NULL, 10);
if(errno != 0)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
}

struct token_string_t *s = (struct token_string_t *)malloc(sizeof(struct token_string_t));
s = (struct token_string_t *)malloc(sizeof(struct token_string_t));
if(s == NULL)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
Expand All @@ -55,13 +60,14 @@ struct token_t rivest_canonical_lexer(FILE * stream, struct input_t * input)
input->cursor = input->marker = input->token = t2;
input_fill(stream,input,1);

char * text = (char *)malloc(sizeof(char)*text_size);
text = (char *)malloc(sizeof(char)*(text_size+1));
if(text ==NULL)
{
return (struct token_t) { TOKEN_RIVEST_ERROR, NULL};
}

text = strncpy(text, input->token, text_size);
text[text_size] = '\0';

*s = (struct token_string_t){text_size,text};

Expand Down

0 comments on commit 6e20206

Please sign in to comment.