Clean up Stack API
* Remove StackPopResult * Rename top_state() -> state() * Rename top_position() -> position() * Improve docs
This commit is contained in:
parent
ee995c3d6b
commit
5520983144
4 changed files with 169 additions and 180 deletions
|
|
@ -19,12 +19,14 @@ typedef struct {
|
|||
TreeArray trees;
|
||||
StackVersion version;
|
||||
} StackSlice;
|
||||
|
||||
typedef Array(StackSlice) StackSliceArray;
|
||||
|
||||
typedef struct {
|
||||
StackSliceArray slices;
|
||||
} StackPopResult;
|
||||
Length position;
|
||||
unsigned depth;
|
||||
TSStateId state;
|
||||
} StackSummaryEntry;
|
||||
typedef Array(StackSummaryEntry) StackSummary;
|
||||
|
||||
typedef unsigned StackIterateAction;
|
||||
enum {
|
||||
|
|
@ -33,81 +35,74 @@ enum {
|
|||
StackIteratePop = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
Length position;
|
||||
unsigned depth;
|
||||
TSStateId state;
|
||||
} StackSummaryEntry;
|
||||
|
||||
typedef Array(StackSummaryEntry) StackSummary;
|
||||
|
||||
typedef StackIterateAction (*StackIterateCallback)(void *, TSStateId state,
|
||||
const TreeArray *trees,
|
||||
uint32_t tree_count);
|
||||
|
||||
/*
|
||||
* Create a parse stack.
|
||||
*/
|
||||
// Create a stack.
|
||||
Stack *ts_stack_new(TreePool *);
|
||||
|
||||
/*
|
||||
* Release any resources reserved by a parse stack.
|
||||
*/
|
||||
// Release the memory reserved for a given stack.
|
||||
void ts_stack_delete(Stack *);
|
||||
|
||||
/*
|
||||
* Get the stack's current number of versions.
|
||||
*/
|
||||
// Get the stack's current number of versions.
|
||||
uint32_t ts_stack_version_count(const Stack *);
|
||||
|
||||
/*
|
||||
* Get the state at the top of the given version of the stack. If the stack is
|
||||
* empty, this returns the initial state (0).
|
||||
*/
|
||||
TSStateId ts_stack_top_state(const Stack *, StackVersion);
|
||||
// Get the state at the top of the given version of the stack. If the stack is
|
||||
// empty, this returns the initial state, 0.
|
||||
TSStateId ts_stack_state(const Stack *, StackVersion);
|
||||
|
||||
// Get the number of trees that have been pushed to a given version of
|
||||
// the stack.
|
||||
unsigned ts_stack_push_count(const Stack *, StackVersion);
|
||||
|
||||
// In the event that trees were permanently removed from some version
|
||||
// of the stack, decrease the version's push count to account for the
|
||||
// removal.
|
||||
void ts_stack_decrease_push_count(Stack *, StackVersion, unsigned);
|
||||
|
||||
// Get the last external token associated with a given version of the stack.
|
||||
Tree *ts_stack_last_external_token(const Stack *, StackVersion);
|
||||
|
||||
// Set the last external token associated with a given version of the stack.
|
||||
void ts_stack_set_last_external_token(Stack *, StackVersion, Tree *);
|
||||
|
||||
/*
|
||||
* Get the position at the top of the given version of the stack. If the stack
|
||||
* is empty, this returns zero.
|
||||
*/
|
||||
Length ts_stack_top_position(const Stack *, StackVersion);
|
||||
// Get the position of the given version of the stack within the document.
|
||||
Length ts_stack_position(const Stack *, StackVersion);
|
||||
|
||||
/*
|
||||
* Push a tree and state onto the given head of the stack.
|
||||
*/
|
||||
// Push a tree and state onto the given version of the stack.
|
||||
//
|
||||
// This transfers ownership of the tree to the Stack. Callers that
|
||||
// need to retain ownership of the tree for their own purposes should
|
||||
// first retain the tree.
|
||||
void ts_stack_push(Stack *, StackVersion, Tree *, bool, TSStateId);
|
||||
|
||||
/*
|
||||
* Pop the given number of entries from the given version of the stack. This
|
||||
* operation can increase the number of stack versions by revealing multiple
|
||||
* versions which had previously been merged. It returns a struct that
|
||||
* indicates the index of each revealed version and the trees removed from that
|
||||
* version.
|
||||
*/
|
||||
StackPopResult ts_stack_pop_count(Stack *, StackVersion, uint32_t count);
|
||||
// Pop the given number of entries from the given version of the stack. This
|
||||
// operation can increase the number of stack versions by revealing multiple
|
||||
// versions which had previously been merged. It returns an array that
|
||||
// specifies the index of each revealed version and the trees that were
|
||||
// removed from that version.
|
||||
StackSliceArray ts_stack_pop_count(Stack *, StackVersion, uint32_t count);
|
||||
|
||||
StackPopResult ts_stack_iterate(Stack *, StackVersion, StackIterateCallback, void *);
|
||||
// Remove an error at the top of the given version of the stack.
|
||||
StackSliceArray ts_stack_pop_error(Stack *, StackVersion);
|
||||
|
||||
StackPopResult ts_stack_pop_error(Stack *, StackVersion);
|
||||
// Remove any pending trees from the top of the given version of the stack.
|
||||
StackSliceArray ts_stack_pop_pending(Stack *, StackVersion);
|
||||
|
||||
StackPopResult ts_stack_pop_pending(Stack *, StackVersion);
|
||||
|
||||
StackPopResult ts_stack_pop_all(Stack *, StackVersion);
|
||||
// Remove any all trees from the given version of the stack.
|
||||
StackSliceArray ts_stack_pop_all(Stack *, StackVersion);
|
||||
|
||||
unsigned ts_stack_depth_since_error(Stack *, StackVersion);
|
||||
|
||||
int ts_stack_dynamic_precedence(Stack *, StackVersion);
|
||||
|
||||
// Compute a summary of all the parse states near the top of the given
|
||||
// version of the stack and store the summary for later retrieval.
|
||||
void ts_stack_record_summary(Stack *, StackVersion, unsigned max_depth);
|
||||
|
||||
// Retrieve a summary of all the parse states near the top of the
|
||||
// given version of the stack.
|
||||
StackSummary *ts_stack_get_summary(Stack *, StackVersion);
|
||||
|
||||
unsigned ts_stack_error_cost(const Stack *, StackVersion version);
|
||||
|
|
@ -128,17 +123,13 @@ void ts_stack_swap_versions(Stack *, StackVersion, StackVersion);
|
|||
|
||||
StackVersion ts_stack_copy_version(Stack *, StackVersion);
|
||||
|
||||
/*
|
||||
* Remove the given version from the stack.
|
||||
*/
|
||||
// Remove the given version from the stack.
|
||||
void ts_stack_remove_version(Stack *, StackVersion);
|
||||
|
||||
/*
|
||||
* Remove all entries from the stack.
|
||||
*/
|
||||
void ts_stack_clear(Stack *);
|
||||
|
||||
bool ts_stack_print_dot_graph(Stack *, const char **, FILE *);
|
||||
StackSliceArray ts_stack_iterate(Stack *, StackVersion, StackIterateCallback, void *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue