Reorganize repo, add rust CLI and binding code,
This commit is contained in:
commit
47607cecf4
221 changed files with 11359 additions and 18038 deletions
38
lib/include/tree_sitter/compiler.h
Normal file
38
lib/include/tree_sitter/compiler.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef TREE_SITTER_COMPILER_H_
|
||||
#define TREE_SITTER_COMPILER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum {
|
||||
TSCompileErrorTypeNone,
|
||||
TSCompileErrorTypeInvalidGrammar,
|
||||
TSCompileErrorTypeInvalidRegex,
|
||||
TSCompileErrorTypeUndefinedSymbol,
|
||||
TSCompileErrorTypeInvalidExtraToken,
|
||||
TSCompileErrorTypeInvalidExternalToken,
|
||||
TSCompileErrorTypeLexConflict,
|
||||
TSCompileErrorTypeParseConflict,
|
||||
TSCompileErrorTypeEpsilonRule,
|
||||
TSCompileErrorTypeInvalidTokenContents,
|
||||
TSCompileErrorTypeInvalidRuleName,
|
||||
TSCompileErrorTypeInvalidWordRule,
|
||||
} TSCompileErrorType;
|
||||
|
||||
typedef struct {
|
||||
char *code;
|
||||
char *error_message;
|
||||
TSCompileErrorType error_type;
|
||||
} TSCompileResult;
|
||||
|
||||
TSCompileResult ts_compile_grammar(const char *input, FILE *log_file);
|
||||
TSCompileResult ts_compile_property_sheet(const char *input, FILE *log_file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_COMPILER_H_
|
||||
195
lib/include/tree_sitter/parser.h
Normal file
195
lib/include/tree_sitter/parser.h
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
#ifndef TREE_SITTER_RUNTIME_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
typedef struct {
|
||||
bool visible : 1;
|
||||
bool named : 1;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
TSStateId state;
|
||||
bool extra : 1;
|
||||
bool repetition : 1;
|
||||
};
|
||||
struct {
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint8_t child_count;
|
||||
uint8_t alias_sequence_id;
|
||||
};
|
||||
} params;
|
||||
TSParseActionType type : 4;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable : 1;
|
||||
};
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
const char **symbol_names;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const uint16_t *parse_table;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const TSLexMode *lex_modes;
|
||||
const TSSymbol *alias_sequences;
|
||||
uint16_t max_alias_sequence_length;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)();
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
int32_t lookahead; \
|
||||
next_state: \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
lexer->advance(lexer, false); \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
lexer->advance(lexer, true); \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.params = {.state = state_value}, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.params = { \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
}, \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RECOVER() \
|
||||
{ \
|
||||
{ .type = TSParseActionTypeRecover } \
|
||||
}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.params = {.extra = true} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{ \
|
||||
{ \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.params = { \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{ \
|
||||
{ .type = TSParseActionTypeAccept } \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
156
lib/include/tree_sitter/runtime.h
Normal file
156
lib/include/tree_sitter/runtime.h
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
#ifndef TREE_SITTER_RUNTIME_H_
|
||||
#define TREE_SITTER_RUNTIME_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TREE_SITTER_LANGUAGE_VERSION 9
|
||||
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
typedef struct TSParser TSParser;
|
||||
typedef struct TSTree TSTree;
|
||||
|
||||
typedef enum {
|
||||
TSInputEncodingUTF8,
|
||||
TSInputEncodingUTF16,
|
||||
} TSInputEncoding;
|
||||
|
||||
typedef enum {
|
||||
TSSymbolTypeRegular,
|
||||
TSSymbolTypeAnonymous,
|
||||
TSSymbolTypeAuxiliary,
|
||||
} TSSymbolType;
|
||||
|
||||
typedef struct {
|
||||
uint32_t row;
|
||||
uint32_t column;
|
||||
} TSPoint;
|
||||
|
||||
typedef struct {
|
||||
TSPoint start_point;
|
||||
TSPoint end_point;
|
||||
uint32_t start_byte;
|
||||
uint32_t end_byte;
|
||||
} TSRange;
|
||||
|
||||
typedef struct {
|
||||
void *payload;
|
||||
const char *(*read)(void *payload, uint32_t byte_index, TSPoint position, uint32_t *bytes_read);
|
||||
TSInputEncoding encoding;
|
||||
} TSInput;
|
||||
|
||||
typedef enum {
|
||||
TSLogTypeParse,
|
||||
TSLogTypeLex,
|
||||
} TSLogType;
|
||||
|
||||
typedef struct {
|
||||
void *payload;
|
||||
void (*log)(void *payload, TSLogType, const char *);
|
||||
} TSLogger;
|
||||
|
||||
typedef struct {
|
||||
uint32_t start_byte;
|
||||
uint32_t old_end_byte;
|
||||
uint32_t new_end_byte;
|
||||
TSPoint start_point;
|
||||
TSPoint old_end_point;
|
||||
TSPoint new_end_point;
|
||||
} TSInputEdit;
|
||||
|
||||
typedef struct {
|
||||
uint32_t context[4];
|
||||
const void *id;
|
||||
const TSTree *tree;
|
||||
} TSNode;
|
||||
|
||||
typedef struct {
|
||||
const void *tree;
|
||||
const void *id;
|
||||
uint32_t context[2];
|
||||
} TSTreeCursor;
|
||||
|
||||
TSParser *ts_parser_new();
|
||||
void ts_parser_delete(TSParser *);
|
||||
const TSLanguage *ts_parser_language(const TSParser *);
|
||||
bool ts_parser_set_language(TSParser *, const TSLanguage *);
|
||||
TSLogger ts_parser_logger(const TSParser *);
|
||||
void ts_parser_set_logger(TSParser *, TSLogger);
|
||||
void ts_parser_print_dot_graphs(TSParser *, FILE *);
|
||||
void ts_parser_halt_on_error(TSParser *, bool);
|
||||
TSTree *ts_parser_parse(TSParser *, const TSTree *, TSInput);
|
||||
TSTree *ts_parser_parse_string(TSParser *, const TSTree *, const char *, uint32_t);
|
||||
TSTree *ts_parser_parse_string_encoding(TSParser *, const TSTree *, const char *, uint32_t, TSInputEncoding);
|
||||
bool ts_parser_enabled(const TSParser *);
|
||||
void ts_parser_set_enabled(TSParser *, bool);
|
||||
size_t ts_parser_operation_limit(const TSParser *);
|
||||
void ts_parser_set_operation_limit(TSParser *, size_t);
|
||||
void ts_parser_reset(TSParser *);
|
||||
void ts_parser_set_included_ranges(TSParser *, const TSRange *, uint32_t);
|
||||
const TSRange *ts_parser_included_ranges(const TSParser *, uint32_t *);
|
||||
|
||||
TSTree *ts_tree_copy(const TSTree *);
|
||||
void ts_tree_delete(TSTree *);
|
||||
TSNode ts_tree_root_node(const TSTree *);
|
||||
void ts_tree_edit(TSTree *, const TSInputEdit *);
|
||||
TSRange *ts_tree_get_changed_ranges(const TSTree *, const TSTree *, uint32_t *);
|
||||
void ts_tree_print_dot_graph(const TSTree *, FILE *);
|
||||
const TSLanguage *ts_tree_language(const TSTree *);
|
||||
|
||||
uint32_t ts_node_start_byte(TSNode);
|
||||
TSPoint ts_node_start_point(TSNode);
|
||||
uint32_t ts_node_end_byte(TSNode);
|
||||
TSPoint ts_node_end_point(TSNode);
|
||||
TSSymbol ts_node_symbol(TSNode);
|
||||
const char *ts_node_type(TSNode);
|
||||
char *ts_node_string(TSNode);
|
||||
bool ts_node_eq(TSNode, TSNode);
|
||||
bool ts_node_is_null(TSNode);
|
||||
bool ts_node_is_named(TSNode);
|
||||
bool ts_node_is_missing(TSNode);
|
||||
bool ts_node_has_changes(TSNode);
|
||||
bool ts_node_has_error(TSNode);
|
||||
TSNode ts_node_parent(TSNode);
|
||||
TSNode ts_node_child(TSNode, uint32_t);
|
||||
TSNode ts_node_named_child(TSNode, uint32_t);
|
||||
uint32_t ts_node_child_count(TSNode);
|
||||
uint32_t ts_node_named_child_count(TSNode);
|
||||
TSNode ts_node_next_sibling(TSNode);
|
||||
TSNode ts_node_next_named_sibling(TSNode);
|
||||
TSNode ts_node_prev_sibling(TSNode);
|
||||
TSNode ts_node_prev_named_sibling(TSNode);
|
||||
TSNode ts_node_first_child_for_byte(TSNode, uint32_t);
|
||||
TSNode ts_node_first_named_child_for_byte(TSNode, uint32_t);
|
||||
TSNode ts_node_descendant_for_byte_range(TSNode, uint32_t, uint32_t);
|
||||
TSNode ts_node_named_descendant_for_byte_range(TSNode, uint32_t, uint32_t);
|
||||
TSNode ts_node_descendant_for_point_range(TSNode, TSPoint, TSPoint);
|
||||
TSNode ts_node_named_descendant_for_point_range(TSNode, TSPoint, TSPoint);
|
||||
void ts_node_edit(TSNode *, const TSInputEdit *);
|
||||
|
||||
TSTreeCursor ts_tree_cursor_new(TSNode);
|
||||
void ts_tree_cursor_delete(TSTreeCursor *);
|
||||
void ts_tree_cursor_reset(TSTreeCursor *, TSNode);
|
||||
TSNode ts_tree_cursor_current_node(const TSTreeCursor *);
|
||||
bool ts_tree_cursor_goto_parent(TSTreeCursor *);
|
||||
bool ts_tree_cursor_goto_next_sibling(TSTreeCursor *);
|
||||
bool ts_tree_cursor_goto_first_child(TSTreeCursor *);
|
||||
int64_t ts_tree_cursor_goto_first_child_for_byte(TSTreeCursor *, uint32_t);
|
||||
|
||||
uint32_t ts_language_symbol_count(const TSLanguage *);
|
||||
const char *ts_language_symbol_name(const TSLanguage *, TSSymbol);
|
||||
TSSymbol ts_language_symbol_for_name(const TSLanguage *, const char *);
|
||||
TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol);
|
||||
uint32_t ts_language_version(const TSLanguage *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_RUNTIME_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue