Skip to content

Commit

Permalink
feat: add base parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Gscienty committed Jul 2, 2019
1 parent 4b2d6b7 commit 532b541
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
37 changes: 37 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "parser.h"

static int graphql_parser_init(graphql_parser_t *, const char *, int, int);

int graphql_parse(const char *src, int no_loc, int no_src, graphql_ast_document_t *doc)
{
int err;
graphql_parser_t parser;
err = graphql_parser_init(&parser, src, no_loc, no_src);
if (err < 0) {
return err;
}

// TODO

return 0;
}

static int graphql_parser_init(graphql_parser_t *parser, const char *src, int no_loc, int no_src)
{
int err;
parser->src = src;
parser->opt.no_loc = no_loc;
parser->opt.no_src = no_src;
parser->prev_end = 0;
err = graphql_lex_init(&parser->lexer, src);
if (err < 0) {
return err;
}
err = parser->lexer.cb(&parser->lexer, &parser->tok, 0);
if (err < 0) {
return err;
}

return 0;
}

24 changes: 24 additions & 0 deletions parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _LIBGRAPHQL_PARSER_H
#define _LIBGRAPHQL_PARSER_H

#include "lexer.h"
#include "ast.h"

typedef struct graphql_parse_options_s graphql_parse_options_t;
struct graphql_parse_options_s {
int no_loc;
int no_src;
};

typedef struct graphql_parser_s graphql_parser_t;
struct graphql_parser_s {
graphql_lexer_ctx_t lexer;
const char *src;
graphql_parse_options_t opt;
int prev_end;
graphql_token_t tok;
};

int graphql_parse(const char *src, int no_loc, int no_src, graphql_ast_document_t *doc);

#endif

0 comments on commit 532b541

Please sign in to comment.