Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified hl parsing #399

Merged
merged 7 commits into from
Mar 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions hl/src/H5LTanalyze.l
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/

%{
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <hdf5.h>
#include "H5LTparse.h"

static char *trim_quotes(const char *);
int my_yyinput(char *, int);
#undef YY_INPUT
#define YY_INPUT(b, r, ms) (r=my_yyinput(b, ms))
Expand Down Expand Up @@ -108,8 +110,7 @@ OPQ_TAG {return token(OPQ_TAG_TOKEN);}
}

["][^\"]+["] {
H5LTyylval.sval = strndup(yytext + 1, strlen(yytext) - 2);
BEGIN INITIAL;
H5LTyylval.sval = trim_quotes(yytext);
return STRING;
}

Expand All @@ -123,6 +124,25 @@ OPQ_TAG {return token(OPQ_TAG_TOKEN);}
"\n" { return 0; }

%%

/* Allocate a copy of `quoted` with the double quote character at
* the beginning and the one at the end both removed. The caller is
* responsible for free()ing the copy.
*/
static char *
trim_quotes(const char *quoted)
{
size_t len = strlen(quoted);
char *trimmed;

assert(quoted[0] == '"' && quoted[len - 1] == '"');

trimmed = strdup(quoted + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even MSVC 2015 supports enough C99 to do the declaration & initialization at once, as in: char *trimmed = strdup(quoted + 1); Is there a reason you do this C89 style? (I've noticed most of HDF5 is the same.)

trimmed[len - 2] = '\0';

return trimmed;
}

int my_yyinput(char *buf, int max_size)
{
int ret;
Expand Down