Remove generated parsers' dependency on the runtime library

Generated parsers no longer export a parser constructor function.
They now export an opaque Language object which can be set on
Documents directly. This way, the logic for constructing parsers
lives entirely in the runtime. The Languages are just structs which
have no load-time dependency on the runtime
This commit is contained in:
Max Brunsfeld 2014-07-30 23:40:02 -07:00
parent 048a479b5f
commit eecbcccee0
21 changed files with 219 additions and 173 deletions

View file

@ -1,4 +1,4 @@
#include "runtime/helpers/dummy_parser.h"
#include "runtime/helpers/dummy_language.h"
#include "tree_sitter/parser.h"
const TSParseAction parse_table[3][5] = {
@ -30,9 +30,11 @@ const int hidden_symbols[5] = {
[dummy_sym3] = 1,
};
TSParserConfig dummy_parser = {
static TSLanguage language = {
.symbol_count = 5,
.parse_table = (const TSParseAction *)parse_table,
.lex_states = lex_states,
.hidden_symbol_flags = hidden_symbols,
};
TSLanguage *dummy_language = &language;

View file

@ -1,5 +1,5 @@
#ifndef HELPERS_DUMMY_PARSER_H_
#define HELPERS_DUMMY_PARSER_H_
#ifndef HELPERS_DUMMY_LANGUAGE_H_
#define HELPERS_DUMMY_LANGUAGE_H_
#ifdef __cplusplus
extern "C" {
@ -14,10 +14,10 @@ enum {
dummy_sym3 = 4,
};
extern TSParserConfig dummy_parser;
extern TSLanguage *dummy_language;
#ifdef __cplusplus
}
#endif
#endif // HELPERS_DUMMY_PARSER_H_
#endif // HELPERS_DUMMY_LANGUAGE_H_