diff --git a/include/document.h b/include/document.h deleted file mode 100644 index 6928531e..00000000 --- a/include/document.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __tree_sitter_document_h__ -#define __tree_sitter_document_h__ -#ifdef __cplusplus -extern "C" { -#endif - -#include "./tree.h" -#include "./parse_config.h" - -typedef struct TSDocument TSDocument; - -TSDocument * TSDocumentMake(); -void TSDocumentSetUp(TSDocument *document, TSParseConfig config); -void TSDocumentSetText(TSDocument *document, const char *text); -TSTree * TSDocumentTree(const TSDocument *document); -const char * TSDocumentToString(const TSDocument *document); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/parse_config.h b/include/parse_config.h deleted file mode 100644 index 50de56fb..00000000 --- a/include/parse_config.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __tree_sitter_parse_config_h__ -#define __tree_sitter_parse_config_h__ -#ifdef __cplusplus -extern "C" { -#endif - -#include "tree.h" - -typedef struct { - const char **expected_inputs; - size_t expected_input_count; - size_t position; - long lookahead_sym; -} TSParseError; - -const char * TSParseErrorToString(const TSParseError *error, const char *input_string, const char **symbol_names); - -typedef struct { - TSParseError error; - TSTree *tree; -} TSParseResult; - -typedef TSParseResult TSParseFn(const char *); - -typedef struct { - TSParseFn *parse_fn; - const char **symbol_names; -} TSParseConfig; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/parser.h b/include/parser.h index bf351c0f..ca5cc7ca 100644 --- a/include/parser.h +++ b/include/parser.h @@ -1,11 +1,11 @@ -#ifndef __tree_sitter_parser_h__ -#define __tree_sitter_parser_h__ +#ifndef tree_sitter_parser_h +#define tree_sitter_parser_h + #ifdef __cplusplus extern "C" { #endif -#include "tree.h" -#include "parse_config.h" +#include "runtime.h" #include #include @@ -23,7 +23,7 @@ extern "C" { #else #define DEBUG_PARSE(...) #endif - + static int INITIAL_STACK_SIZE = 100; static const char *ts_symbol_names[]; @@ -220,4 +220,5 @@ done: #ifdef __cplusplus } #endif + #endif diff --git a/include/runtime.h b/include/runtime.h new file mode 100644 index 00000000..b0d2f7dd --- /dev/null +++ b/include/runtime.h @@ -0,0 +1,59 @@ +#ifndef tree_sitter_runtime_h +#define tree_sitter_runtime_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct { + const char **expected_inputs; + size_t expected_input_count; + size_t position; + long lookahead_sym; +} TSParseError; + +const char * TSParseErrorToString(const TSParseError *error, const char *input_string, const char **symbol_names); + +typedef size_t TSSymbol; + +typedef struct TSTree { + TSSymbol value; + struct TSTree **children; + size_t child_count; + size_t ref_count; +} TSTree; + +TSTree * TSTreeMake(TSSymbol value, size_t child_count, TSTree **children); +void TSTreeRetain(TSTree *tree); +void TSTreeRelease(TSTree *tree); +int TSTreeEquals(const TSTree *tree1, const TSTree *tree2); +char * TSTreeToString(const TSTree *tree, const char **names); + +typedef struct { + TSParseError error; + TSTree *tree; +} TSParseResult; + +typedef TSParseResult TSParseFn(const char *); + +typedef struct { + TSParseFn *parse_fn; + const char **symbol_names; +} TSParseConfig; + +typedef struct TSDocument TSDocument; + +TSDocument * TSDocumentMake(); +void TSDocumentSetUp(TSDocument *document, TSParseConfig config); +void TSDocumentSetText(TSDocument *document, const char *text); +TSTree * TSDocumentTree(const TSDocument *document); +const char * TSDocumentToString(const TSDocument *document); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/tree.h b/include/tree.h deleted file mode 100644 index b5d046be..00000000 --- a/include/tree.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __tree_sitter_tree_h__ -#define __tree_sitter_tree_h__ -#ifdef __cplusplus -extern "C" { -#endif - - -#include - -typedef size_t TSSymbol; -typedef struct TSTree { - TSSymbol value; - struct TSTree **children; - size_t child_count; - size_t ref_count; -} TSTree; - -TSTree * TSTreeMake(TSSymbol value, size_t child_count, TSTree **children); -void TSTreeRetain(TSTree *tree); -void TSTreeRelease(TSTree *tree); - -int TSTreeEquals(const TSTree *tree1, const TSTree *tree2); -char * TSTreeToString(const TSTree *tree, const char **names); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/spec/runtime/arithmetic_spec.cpp b/spec/runtime/arithmetic_spec.cpp index b07b7a94..8a29852c 100644 --- a/spec/runtime/arithmetic_spec.cpp +++ b/spec/runtime/arithmetic_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "document.h" +#include "runtime.h" extern TSParseConfig ts_parse_config_arithmetic; diff --git a/spec/runtime/json_spec.cpp b/spec/runtime/json_spec.cpp index c6d72ae2..5d86c5fc 100644 --- a/spec/runtime/json_spec.cpp +++ b/spec/runtime/json_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "document.h" +#include "runtime.h" extern TSParseConfig ts_parse_config_json; diff --git a/spec/runtime/tree_spec.cpp b/spec/runtime/tree_spec.cpp index 4fd47408..15dba00d 100644 --- a/spec/runtime/tree_spec.cpp +++ b/spec/runtime/tree_spec.cpp @@ -1,5 +1,5 @@ #include "spec_helper.h" -#include "tree.h" +#include "runtime.h" START_TEST diff --git a/src/runtime/document.c b/src/runtime/document.c index 3d61ba93..f124aa74 100644 --- a/src/runtime/document.c +++ b/src/runtime/document.c @@ -1,4 +1,4 @@ -#include "document.h" +#include "runtime.h" struct TSDocument { TSParseFn *parse_fn; diff --git a/src/runtime/parse_config.cpp b/src/runtime/error.cpp similarity index 95% rename from src/runtime/parse_config.cpp rename to src/runtime/error.cpp index dd398c38..055dffac 100644 --- a/src/runtime/parse_config.cpp +++ b/src/runtime/error.cpp @@ -1,4 +1,4 @@ -#include "parse_config.h" +#include "runtime.h" #include using std::string; diff --git a/src/runtime/tree.c b/src/runtime/tree.c index e2814c5c..94c44e0d 100644 --- a/src/runtime/tree.c +++ b/src/runtime/tree.c @@ -1,4 +1,4 @@ -#include "tree.h" +#include "runtime.h" #include #include diff --git a/tree_sitter.xcodeproj/project.pbxproj b/tree_sitter.xcodeproj/project.pbxproj index 7bde2567..a1c95752 100644 --- a/tree_sitter.xcodeproj/project.pbxproj +++ b/tree_sitter.xcodeproj/project.pbxproj @@ -22,7 +22,7 @@ 127528B518AACB70006B682B /* rule_can_be_blank_spec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 127528B418AACB70006B682B /* rule_can_be_blank_spec.cpp */; }; 12AB465F188BD03E00DE79DF /* follow_sets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12AB465D188BD03E00DE79DF /* follow_sets.cpp */; }; 12AB4661188CB3A300DE79DF /* item_set_closure_spec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12AB4660188CB3A300DE79DF /* item_set_closure_spec.cpp */; }; - 12BC470518822B27005AC502 /* parse_config.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12BC470318822A17005AC502 /* parse_config.cpp */; }; + 12BC470518822B27005AC502 /* error.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12BC470318822A17005AC502 /* error.cpp */; }; 12BC470718830BC5005AC502 /* first_set_spec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12BC470618830BC5005AC502 /* first_set_spec.cpp */; }; 12D136A4183678A2005F3369 /* repeat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12D136A2183678A2005F3369 /* repeat.cpp */; }; 12E75A971891BD32001B8F10 /* json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12E75A961891BD32001B8F10 /* json.cpp */; }; @@ -107,11 +107,12 @@ 127528B118AACAAA006B682B /* rule_can_be_blank.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rule_can_be_blank.cpp; sourceTree = ""; }; 127528B218AACAAA006B682B /* rule_can_be_blank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rule_can_be_blank.h; sourceTree = ""; }; 127528B418AACB70006B682B /* rule_can_be_blank_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rule_can_be_blank_spec.cpp; sourceTree = ""; }; + 127528B918B041B6006B682B /* runtime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = runtime.h; sourceTree = ""; }; 12AB465D188BD03E00DE79DF /* follow_sets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = follow_sets.cpp; sourceTree = ""; }; 12AB465E188BD03E00DE79DF /* follow_sets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = follow_sets.h; sourceTree = ""; }; 12AB4660188CB3A300DE79DF /* item_set_closure_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = item_set_closure_spec.cpp; sourceTree = ""; }; 12AB4663188DCB9800DE79DF /* stream_methods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stream_methods.h; sourceTree = ""; }; - 12BC470318822A17005AC502 /* parse_config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parse_config.cpp; sourceTree = ""; }; + 12BC470318822A17005AC502 /* error.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = error.cpp; sourceTree = ""; }; 12BC470618830BC5005AC502 /* first_set_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = first_set_spec.cpp; sourceTree = ""; }; 12D1369E18342088005F3369 /* todo.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = todo.md; sourceTree = ""; }; 12D136A0183570F5005F3369 /* pattern_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pattern_spec.cpp; path = spec/compiler/rules/pattern_spec.cpp; sourceTree = SOURCE_ROOT; }; @@ -125,9 +126,7 @@ 12E75AA018930931001B8F10 /* expand_repeats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = expand_repeats.cpp; path = src/compiler/prepare_grammar/expand_repeats.cpp; sourceTree = SOURCE_ROOT; }; 12E75AA118930931001B8F10 /* expand_repeats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = expand_repeats.h; path = src/compiler/prepare_grammar/expand_repeats.h; sourceTree = SOURCE_ROOT; }; 12EDCF89187B498C005A7A07 /* tree_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tree_spec.cpp; sourceTree = ""; }; - 12EDCF8B187C6251005A7A07 /* document.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = document.h; sourceTree = ""; }; 12EDCF8C187C6282005A7A07 /* document.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = document.c; sourceTree = ""; }; - 12EDCF8E187DB33E005A7A07 /* parse_config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = parse_config.h; sourceTree = ""; }; 12EDCF8F1881FCCA005A7A07 /* extract_tokens.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = extract_tokens.cpp; path = src/compiler/prepare_grammar/extract_tokens.cpp; sourceTree = SOURCE_ROOT; }; 12EDCF901881FCCA005A7A07 /* extract_tokens.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = extract_tokens.h; path = src/compiler/prepare_grammar/extract_tokens.h; sourceTree = SOURCE_ROOT; }; 12EDCF911881FCCA005A7A07 /* perform.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = perform.cpp; path = src/compiler/prepare_grammar/perform.cpp; sourceTree = SOURCE_ROOT; }; @@ -162,7 +161,6 @@ 12FD4063185E75290041A84E /* compile_fixtures.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = compile_fixtures.cpp; path = spec/compiler/compile_fixtures.cpp; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 12FD4065185E7C2F0041A84E /* arithmetic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = arithmetic.c; path = spec/fixtures/parsers/arithmetic.c; sourceTree = SOURCE_ROOT; }; 12FD40D1185EEB5E0041A84E /* runtime_specs */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = runtime_specs; sourceTree = BUILT_PRODUCTS_DIR; }; - 12FD40D4185FED9A0041A84E /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = ""; }; 12FD40DA185FEF0D0041A84E /* arithmetic_spec.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = arithmetic_spec.cpp; sourceTree = ""; }; 12FD40DE1860064C0041A84E /* tree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = ""; }; 12FD40E41862B3530041A84E /* visitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = visitor.h; sourceTree = ""; }; @@ -386,7 +384,7 @@ children = ( 12FD40DE1860064C0041A84E /* tree.c */, 12EDCF8C187C6282005A7A07 /* document.c */, - 12BC470318822A17005AC502 /* parse_config.cpp */, + 12BC470318822A17005AC502 /* error.cpp */, ); path = runtime; sourceTree = ""; @@ -424,10 +422,8 @@ 12FD40D3185FED630041A84E /* include */ = { isa = PBXGroup; children = ( - 12FD40D4185FED9A0041A84E /* tree.h */, 121D8B3018795CC0003CF44B /* parser.h */, - 12EDCF8B187C6251005A7A07 /* document.h */, - 12EDCF8E187DB33E005A7A07 /* parse_config.h */, + 127528B918B041B6006B682B /* runtime.h */, ); path = include; sourceTree = ""; @@ -557,7 +553,7 @@ 12E75A9C1891C17D001B8F10 /* json_spec.cpp in Sources */, 12FD40DB185FEF0D0041A84E /* arithmetic_spec.cpp in Sources */, 12FD40C2185EEB5E0041A84E /* main.cpp in Sources */, - 12BC470518822B27005AC502 /* parse_config.cpp in Sources */, + 12BC470518822B27005AC502 /* error.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };