tree-sitter/src/runtime/parse_stack.h

123 lines
3 KiB
C
Raw Normal View History

2015-05-25 20:21:13 -07:00
#ifndef RUNTIME_PARSE_STACK_H_
#define RUNTIME_PARSE_STACK_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tree_sitter/parser.h"
typedef struct ParseStack ParseStack;
2015-06-03 09:44:13 -07:00
typedef struct {
2015-05-25 20:21:13 -07:00
TSTree *tree;
TSStateId state;
2015-06-03 09:44:13 -07:00
} ParseStackEntry;
2015-05-25 20:21:13 -07:00
2015-06-03 09:44:13 -07:00
typedef struct {
int index;
int tree_count;
TSTree **trees;
} ParseStackPopResult;
typedef struct {
int size;
ParseStackPopResult *contents;
} ParseStackPopResultList;
typedef struct {
void *data;
2015-07-27 18:29:48 -07:00
TSTree *(*callback)(void *data, TSTree *, TSTree *);
} TreeSelectionCallback;
2015-06-03 09:44:13 -07:00
/*
2015-08-16 19:53:34 -07:00
* Create a parse stack.
2015-06-03 09:44:13 -07:00
*/
ParseStack *ts_parse_stack_new(TreeSelectionCallback);
2015-06-03 09:44:13 -07:00
/*
* Release any resources reserved by a parse stack.
*/
2015-05-25 20:21:13 -07:00
void ts_parse_stack_delete(ParseStack *);
2015-06-03 09:44:13 -07:00
/*
* Get the stack's current number of heads.
*/
2015-05-25 20:21:13 -07:00
int ts_parse_stack_head_count(const ParseStack *);
2015-06-03 09:44:13 -07:00
/*
* Get the state at given head of the stack. If the stack is empty, this
* returns the initial state (0).
2015-06-03 09:44:13 -07:00
*/
TSStateId ts_parse_stack_top_state(const ParseStack *, int head);
2015-06-03 09:44:13 -07:00
/*
* Get the tree at given head of the stack. If the stack is empty, this
* returns NULL.
*/
TSTree *ts_parse_stack_top_tree(const ParseStack *, int head);
/*
* Get the entry at the given head of the stack.
*/
ParseStackEntry *ts_parse_stack_head(ParseStack *, int head);
/*
* Get the number of successors for the parse stack entry.
2015-06-03 09:44:13 -07:00
*/
int ts_parse_stack_entry_next_count(const ParseStackEntry *);
/*
* Get the given successor for the parse stack entry.
2015-06-03 09:44:13 -07:00
*/
ParseStackEntry *ts_parse_stack_entry_next(const ParseStackEntry *, int);
2015-06-03 09:44:13 -07:00
/*
* Push a (tree, state) pair onto the given head of the stack. Returns
* a boolean indicating whether the stack head was merged with an
* existing head.
*/
bool ts_parse_stack_push(ParseStack *, int head, TSStateId, TSTree *);
/*
* Add an alternative tree for the given head of the stack.
*/
void ts_parse_stack_add_alternative(ParseStack *, int head, TSTree *);
2015-06-03 09:44:13 -07:00
/*
* Pop the given number of entries from the given head of the stack. This
* operation can increase the number of stack heads by revealing multiple heads
* which had previously been merged. It returns a struct that indicates the
* index of each revealed head and the trees removed from that head.
*/
2015-07-27 18:29:48 -07:00
ParseStackPopResultList ts_parse_stack_pop(ParseStack *, int head, int count,
bool count_extra);
/*
* Remove the given number of entries from the given head of the stack.
*/
void ts_parse_stack_shrink(ParseStack *, int head, int count);
2015-06-03 09:44:13 -07:00
/*
* Split the given stack head into two heads, so that the stack can be
* transformed from its current state in multiple alternative ways. Returns
* the index of the newly-created head.
*/
int ts_parse_stack_split(ParseStack *, int head);
2015-05-25 20:21:13 -07:00
/*
* Remove the given head from the stack.
*/
void ts_parse_stack_remove_head(ParseStack *, int head);
/*
* Remove all entries from the stack.
*/
void ts_parse_stack_clear(ParseStack *);
2015-05-25 20:21:13 -07:00
#ifdef __cplusplus
}
#endif
#endif // RUNTIME_PARSE_STACK_H_