✨ feat(lsp_server): support rdo_expression and normalize call field
- rename tree-sitter fields for inherited/rdo to 'call' - regenerate parser sources and sync into lsp-server - add RdoExpression to AST + symbol/semantic visitors
This commit is contained in:
parent
d1c35de70c
commit
476e83beb8
|
|
@ -1,6 +1,5 @@
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
|
||||||
module lsp.language.ast:detail;
|
module lsp.language.ast:detail;
|
||||||
import tree_sitter;
|
import tree_sitter;
|
||||||
|
|
||||||
|
|
@ -113,6 +112,7 @@ namespace lsp::language::ast::detail
|
||||||
ExpressionPtr ParseEchoExpression(TSNode node, ParseContext& ctx);
|
ExpressionPtr ParseEchoExpression(TSNode node, ParseContext& ctx);
|
||||||
ExpressionPtr ParseRaiseExpression(TSNode node, ParseContext& ctx);
|
ExpressionPtr ParseRaiseExpression(TSNode node, ParseContext& ctx);
|
||||||
ExpressionPtr ParseInheritedExpression(TSNode node, ParseContext& ctx);
|
ExpressionPtr ParseInheritedExpression(TSNode node, ParseContext& ctx);
|
||||||
|
ExpressionPtr ParseRdoExpression(TSNode node, ParseContext& ctx);
|
||||||
|
|
||||||
ExpressionPtr ParseArrayExpression(TSNode node, ParseContext& ctx);
|
ExpressionPtr ParseArrayExpression(TSNode node, ParseContext& ctx);
|
||||||
ExpressionPtr ParseParenthesizedExpression(TSNode node, ParseContext& ctx);
|
ExpressionPtr ParseParenthesizedExpression(TSNode node, ParseContext& ctx);
|
||||||
|
|
@ -589,6 +589,8 @@ namespace lsp::language::ast::detail
|
||||||
return ParseRaiseExpression(node, ctx);
|
return ParseRaiseExpression(node, ctx);
|
||||||
if (node_type == "inherited_expression")
|
if (node_type == "inherited_expression")
|
||||||
return ParseInheritedExpression(node, ctx);
|
return ParseInheritedExpression(node, ctx);
|
||||||
|
if (node_type == "rdo_expression")
|
||||||
|
return ParseRdoExpression(node, ctx);
|
||||||
|
|
||||||
if (node_type == "array_expression")
|
if (node_type == "array_expression")
|
||||||
return ParseArrayExpression(node, ctx);
|
return ParseArrayExpression(node, ctx);
|
||||||
|
|
@ -751,7 +753,26 @@ namespace lsp::language::ast::detail
|
||||||
auto expr = MakeNode<InheritedExpression>();
|
auto expr = MakeNode<InheritedExpression>();
|
||||||
expr->span = ts_utils::NodeLocation(node);
|
expr->span = ts_utils::NodeLocation(node);
|
||||||
|
|
||||||
TSNode call_node = ts_node_child_by_field_name(node, "class", 5);
|
TSNode call_node = ts_node_child_by_field_name(node, "call", 4);
|
||||||
|
if (!ts_node_is_null(call_node))
|
||||||
|
{
|
||||||
|
auto call_expr = ParseExpression(call_node, ctx);
|
||||||
|
if (call_expr && call_expr->kind == NodeKind::kCallExpression)
|
||||||
|
{
|
||||||
|
expr->call = std::unique_ptr<CallExpression>(
|
||||||
|
static_cast<CallExpression*>(call_expr.release()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionPtr ParseRdoExpression(TSNode node, ParseContext& ctx)
|
||||||
|
{
|
||||||
|
auto expr = MakeNode<RdoExpression>();
|
||||||
|
expr->span = ts_utils::NodeLocation(node);
|
||||||
|
|
||||||
|
TSNode call_node = ts_node_child_by_field_name(node, "call", 4);
|
||||||
if (!ts_node_is_null(call_node))
|
if (!ts_node_is_null(call_node))
|
||||||
{
|
{
|
||||||
auto call_expr = ParseExpression(call_node, ctx);
|
auto call_expr = ParseExpression(call_node, ctx);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
|
||||||
export module lsp.language.ast:types;
|
export module lsp.language.ast:types;
|
||||||
import tree_sitter;
|
import tree_sitter;
|
||||||
|
|
||||||
|
|
@ -213,6 +212,7 @@ export namespace lsp::language::ast
|
||||||
kEchoExpression,
|
kEchoExpression,
|
||||||
kRaiseExpression,
|
kRaiseExpression,
|
||||||
kInheritedExpression,
|
kInheritedExpression,
|
||||||
|
kRdoExpression,
|
||||||
|
|
||||||
kTSSQLExpression,
|
kTSSQLExpression,
|
||||||
kColumnReference,
|
kColumnReference,
|
||||||
|
|
@ -327,6 +327,7 @@ export namespace lsp::language::ast
|
||||||
class EchoExpression;
|
class EchoExpression;
|
||||||
class RaiseExpression;
|
class RaiseExpression;
|
||||||
class InheritedExpression;
|
class InheritedExpression;
|
||||||
|
class RdoExpression;
|
||||||
class TSSQLExpression;
|
class TSSQLExpression;
|
||||||
class ColumnReference;
|
class ColumnReference;
|
||||||
|
|
||||||
|
|
@ -473,6 +474,7 @@ export namespace lsp::language::ast
|
||||||
virtual void VisitEchoExpression(EchoExpression& node) = 0;
|
virtual void VisitEchoExpression(EchoExpression& node) = 0;
|
||||||
virtual void VisitRaiseExpression(RaiseExpression& node) = 0;
|
virtual void VisitRaiseExpression(RaiseExpression& node) = 0;
|
||||||
virtual void VisitInheritedExpression(InheritedExpression& node) = 0;
|
virtual void VisitInheritedExpression(InheritedExpression& node) = 0;
|
||||||
|
virtual void VisitRdoExpression(RdoExpression& node) = 0;
|
||||||
virtual void VisitTSSQLExpression(TSSQLExpression& node) = 0;
|
virtual void VisitTSSQLExpression(TSSQLExpression& node) = 0;
|
||||||
virtual void VisitColumnReference(ColumnReference& node) = 0;
|
virtual void VisitColumnReference(ColumnReference& node) = 0;
|
||||||
|
|
||||||
|
|
@ -895,6 +897,16 @@ export namespace lsp::language::ast
|
||||||
std::optional<std::unique_ptr<CallExpression>> call;
|
std::optional<std::unique_ptr<CallExpression>> call;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RdoExpression : public Expression
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RdoExpression() { kind = NodeKind::kRdoExpression; }
|
||||||
|
void Accept(ASTVisitor& visitor) override { visitor.VisitRdoExpression(*this); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::optional<std::unique_ptr<CallExpression>> call;
|
||||||
|
};
|
||||||
|
|
||||||
class TSSQLExpression : public Expression
|
class TSSQLExpression : public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -780,6 +780,15 @@ namespace lsp::language::semantic
|
||||||
// TODO: 处理 inherited 调用
|
// TODO: 处理 inherited 调用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Analyzer::VisitRdoExpression(ast::RdoExpression& node)
|
||||||
|
{
|
||||||
|
if (node.call && *node.call)
|
||||||
|
{
|
||||||
|
(*node.call)->Accept(*this);
|
||||||
|
}
|
||||||
|
// TODO: 处理 rdo/rdo2 语义
|
||||||
|
}
|
||||||
|
|
||||||
void Analyzer::VisitParenthesizedExpression(ast::ParenthesizedExpression& node)
|
void Analyzer::VisitParenthesizedExpression(ast::ParenthesizedExpression& node)
|
||||||
{
|
{
|
||||||
for (const auto& element : node.elements)
|
for (const auto& element : node.elements)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
module;
|
module;
|
||||||
|
|
||||||
|
|
||||||
export module lsp.language.semantic:interface;
|
export module lsp.language.semantic:interface;
|
||||||
import tree_sitter;
|
import tree_sitter;
|
||||||
|
|
||||||
|
|
@ -628,6 +627,7 @@ export namespace lsp::language::semantic
|
||||||
void VisitEchoExpression(ast::EchoExpression& node) override;
|
void VisitEchoExpression(ast::EchoExpression& node) override;
|
||||||
void VisitRaiseExpression(ast::RaiseExpression& node) override;
|
void VisitRaiseExpression(ast::RaiseExpression& node) override;
|
||||||
void VisitInheritedExpression(ast::InheritedExpression& node) override;
|
void VisitInheritedExpression(ast::InheritedExpression& node) override;
|
||||||
|
void VisitRdoExpression(ast::RdoExpression& node) override;
|
||||||
void VisitParenthesizedExpression(ast::ParenthesizedExpression& node) override;
|
void VisitParenthesizedExpression(ast::ParenthesizedExpression& node) override;
|
||||||
|
|
||||||
void VisitExpressionStatement(ast::ExpressionStatement& node) override;
|
void VisitExpressionStatement(ast::ExpressionStatement& node) override;
|
||||||
|
|
|
||||||
|
|
@ -1158,6 +1158,14 @@ namespace lsp::language::symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Builder::VisitRdoExpression(ast::RdoExpression& node)
|
||||||
|
{
|
||||||
|
if (node.call && *node.call)
|
||||||
|
{
|
||||||
|
(*node.call)->Accept(*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Builder::VisitParenthesizedExpression(ast::ParenthesizedExpression& node)
|
void Builder::VisitParenthesizedExpression(ast::ParenthesizedExpression& node)
|
||||||
{
|
{
|
||||||
for (auto& elem : node.elements)
|
for (auto& elem : node.elements)
|
||||||
|
|
|
||||||
|
|
@ -508,6 +508,7 @@ export namespace lsp::language::symbol
|
||||||
void VisitEchoExpression(ast::EchoExpression& node) override;
|
void VisitEchoExpression(ast::EchoExpression& node) override;
|
||||||
void VisitRaiseExpression(ast::RaiseExpression& node) override;
|
void VisitRaiseExpression(ast::RaiseExpression& node) override;
|
||||||
void VisitInheritedExpression(ast::InheritedExpression& node) override;
|
void VisitInheritedExpression(ast::InheritedExpression& node) override;
|
||||||
|
void VisitRdoExpression(ast::RdoExpression& node) override;
|
||||||
void VisitParenthesizedExpression(ast::ParenthesizedExpression& node) override;
|
void VisitParenthesizedExpression(ast::ParenthesizedExpression& node) override;
|
||||||
|
|
||||||
void VisitExpressionStatement(ast::ExpressionStatement& node) override;
|
void VisitExpressionStatement(ast::ExpressionStatement& node) override;
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -12,37 +12,37 @@ extern "C" {
|
||||||
// Allow clients to override allocation functions
|
// Allow clients to override allocation functions
|
||||||
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
||||||
|
|
||||||
extern void* (*ts_current_malloc)(size_t size);
|
extern void *(*ts_current_malloc)(size_t size);
|
||||||
extern void* (*ts_current_calloc)(size_t count, size_t size);
|
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
||||||
extern void* (*ts_current_realloc)(void* ptr, size_t size);
|
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
||||||
extern void (*ts_current_free)(void* ptr);
|
extern void (*ts_current_free)(void *ptr);
|
||||||
|
|
||||||
#ifndef ts_malloc
|
#ifndef ts_malloc
|
||||||
#define ts_malloc ts_current_malloc
|
#define ts_malloc ts_current_malloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_calloc
|
#ifndef ts_calloc
|
||||||
#define ts_calloc ts_current_calloc
|
#define ts_calloc ts_current_calloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_realloc
|
#ifndef ts_realloc
|
||||||
#define ts_realloc ts_current_realloc
|
#define ts_realloc ts_current_realloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_free
|
#ifndef ts_free
|
||||||
#define ts_free ts_current_free
|
#define ts_free ts_current_free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef ts_malloc
|
#ifndef ts_malloc
|
||||||
#define ts_malloc malloc
|
#define ts_malloc malloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_calloc
|
#ifndef ts_calloc
|
||||||
#define ts_calloc calloc
|
#define ts_calloc calloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_realloc
|
#ifndef ts_realloc
|
||||||
#define ts_realloc realloc
|
#define ts_realloc realloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_free
|
#ifndef ts_free
|
||||||
#define ts_free free
|
#define ts_free free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -21,25 +21,24 @@ extern "C" {
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Array(T) \
|
#define Array(T) \
|
||||||
struct \
|
struct { \
|
||||||
{ \
|
T *contents; \
|
||||||
T* contents; \
|
uint32_t size; \
|
||||||
uint32_t size; \
|
uint32_t capacity; \
|
||||||
uint32_t capacity; \
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Initialize an array.
|
/// Initialize an array.
|
||||||
#define array_init(self) \
|
#define array_init(self) \
|
||||||
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
||||||
|
|
||||||
/// Create an empty array.
|
/// Create an empty array.
|
||||||
#define array_new() \
|
#define array_new() \
|
||||||
{ NULL, 0, 0 }
|
{ NULL, 0, 0 }
|
||||||
|
|
||||||
/// Get a pointer to the element at a given `index` in the array.
|
/// Get a pointer to the element at a given `index` in the array.
|
||||||
#define array_get(self, _index) \
|
#define array_get(self, _index) \
|
||||||
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
||||||
|
|
||||||
/// Get a pointer to the first element in the array.
|
/// Get a pointer to the first element in the array.
|
||||||
#define array_front(self) array_get(self, 0)
|
#define array_front(self) array_get(self, 0)
|
||||||
|
|
@ -54,64 +53,66 @@ extern "C" {
|
||||||
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
||||||
/// less than the array's current capacity, this function has no effect.
|
/// less than the array's current capacity, this function has no effect.
|
||||||
#define array_reserve(self, new_capacity) \
|
#define array_reserve(self, new_capacity) \
|
||||||
_array__reserve((Array*)(self), array_elem_size(self), new_capacity)
|
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
|
||||||
|
|
||||||
/// Free any memory allocated for this array. Note that this does not free any
|
/// Free any memory allocated for this array. Note that this does not free any
|
||||||
/// memory allocated for the array's contents.
|
/// memory allocated for the array's contents.
|
||||||
#define array_delete(self) _array__delete((Array*)(self))
|
#define array_delete(self) _array__delete((Array *)(self))
|
||||||
|
|
||||||
/// Push a new `element` onto the end of the array.
|
/// Push a new `element` onto the end of the array.
|
||||||
#define array_push(self, element) \
|
#define array_push(self, element) \
|
||||||
(_array__grow((Array*)(self), 1, array_elem_size(self)), \
|
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
|
||||||
(self)->contents[(self)->size++] = (element))
|
(self)->contents[(self)->size++] = (element))
|
||||||
|
|
||||||
/// Increase the array's size by `count` elements.
|
/// Increase the array's size by `count` elements.
|
||||||
/// New elements are zero-initialized.
|
/// New elements are zero-initialized.
|
||||||
#define array_grow_by(self, count) \
|
#define array_grow_by(self, count) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
if ((count) == 0) break; \
|
||||||
if ((count) == 0) \
|
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
||||||
break; \
|
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
||||||
_array__grow((Array*)(self), count, array_elem_size(self)); \
|
(self)->size += (count); \
|
||||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
} while (0)
|
||||||
(self)->size += (count); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Append all elements from one array to the end of another.
|
/// Append all elements from one array to the end of another.
|
||||||
#define array_push_all(self, other) \
|
#define array_push_all(self, other) \
|
||||||
array_extend((self), (other)->size, (other)->contents)
|
array_extend((self), (other)->size, (other)->contents)
|
||||||
|
|
||||||
/// Append `count` elements to the end of the array, reading their values from the
|
/// Append `count` elements to the end of the array, reading their values from the
|
||||||
/// `contents` pointer.
|
/// `contents` pointer.
|
||||||
#define array_extend(self, count, contents) \
|
#define array_extend(self, count, contents) \
|
||||||
_array__splice( \
|
_array__splice( \
|
||||||
(Array*)(self), array_elem_size(self), (self)->size, 0, count, contents)
|
(Array *)(self), array_elem_size(self), (self)->size, \
|
||||||
|
0, count, contents \
|
||||||
|
)
|
||||||
|
|
||||||
/// Remove `old_count` elements from the array starting at the given `index`. At
|
/// Remove `old_count` elements from the array starting at the given `index`. At
|
||||||
/// the same index, insert `new_count` new elements, reading their values from the
|
/// the same index, insert `new_count` new elements, reading their values from the
|
||||||
/// `new_contents` pointer.
|
/// `new_contents` pointer.
|
||||||
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
||||||
_array__splice( \
|
_array__splice( \
|
||||||
(Array*)(self), array_elem_size(self), _index, old_count, new_count, new_contents)
|
(Array *)(self), array_elem_size(self), _index, \
|
||||||
|
old_count, new_count, new_contents \
|
||||||
|
)
|
||||||
|
|
||||||
/// Insert one `element` into the array at the given `index`.
|
/// Insert one `element` into the array at the given `index`.
|
||||||
#define array_insert(self, _index, element) \
|
#define array_insert(self, _index, element) \
|
||||||
_array__splice((Array*)(self), array_elem_size(self), _index, 0, 1, &(element))
|
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
|
||||||
|
|
||||||
/// Remove one element from the array at the given `index`.
|
/// Remove one element from the array at the given `index`.
|
||||||
#define array_erase(self, _index) \
|
#define array_erase(self, _index) \
|
||||||
_array__erase((Array*)(self), array_elem_size(self), _index)
|
_array__erase((Array *)(self), array_elem_size(self), _index)
|
||||||
|
|
||||||
/// Pop the last element off the array, returning the element by value.
|
/// Pop the last element off the array, returning the element by value.
|
||||||
#define array_pop(self) ((self)->contents[--(self)->size])
|
#define array_pop(self) ((self)->contents[--(self)->size])
|
||||||
|
|
||||||
/// Assign the contents of one array to another, reallocating if necessary.
|
/// Assign the contents of one array to another, reallocating if necessary.
|
||||||
#define array_assign(self, other) \
|
#define array_assign(self, other) \
|
||||||
_array__assign((Array*)(self), (const Array*)(other), array_elem_size(self))
|
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
|
||||||
|
|
||||||
/// Swap one array with another
|
/// Swap one array with another
|
||||||
#define array_swap(self, other) \
|
#define array_swap(self, other) \
|
||||||
_array__swap((Array*)(self), (Array*)(other))
|
_array__swap((Array *)(self), (Array *)(other))
|
||||||
|
|
||||||
/// Get the size of the array contents
|
/// Get the size of the array contents
|
||||||
#define array_elem_size(self) (sizeof *(self)->contents)
|
#define array_elem_size(self) (sizeof *(self)->contents)
|
||||||
|
|
@ -125,176 +126,153 @@ extern "C" {
|
||||||
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
||||||
/// is set to false.
|
/// is set to false.
|
||||||
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
||||||
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
||||||
|
|
||||||
/// Search a sorted array for a given `needle` value, using integer comparisons
|
/// Search a sorted array for a given `needle` value, using integer comparisons
|
||||||
/// of a given struct field (specified with a leading dot) to determine the order.
|
/// of a given struct field (specified with a leading dot) to determine the order.
|
||||||
///
|
///
|
||||||
/// See also `array_search_sorted_with`.
|
/// See also `array_search_sorted_with`.
|
||||||
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
||||||
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
||||||
|
|
||||||
/// Insert a given `value` into a sorted array, using the given `compare`
|
/// Insert a given `value` into a sorted array, using the given `compare`
|
||||||
/// callback to determine the order.
|
/// callback to determine the order.
|
||||||
#define array_insert_sorted_with(self, compare, value) \
|
#define array_insert_sorted_with(self, compare, value) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
unsigned _index, _exists; \
|
||||||
unsigned _index, _exists; \
|
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
||||||
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
if (!_exists) array_insert(self, _index, value); \
|
||||||
if (!_exists) \
|
} while (0)
|
||||||
array_insert(self, _index, value); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Insert a given `value` into a sorted array, using integer comparisons of
|
/// Insert a given `value` into a sorted array, using integer comparisons of
|
||||||
/// a given struct field (specified with a leading dot) to determine the order.
|
/// a given struct field (specified with a leading dot) to determine the order.
|
||||||
///
|
///
|
||||||
/// See also `array_search_sorted_by`.
|
/// See also `array_search_sorted_by`.
|
||||||
#define array_insert_sorted_by(self, field, value) \
|
#define array_insert_sorted_by(self, field, value) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
unsigned _index, _exists; \
|
||||||
unsigned _index, _exists; \
|
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
|
||||||
array_search_sorted_by(self, field, (value)field, &_index, &_exists); \
|
if (!_exists) array_insert(self, _index, value); \
|
||||||
if (!_exists) \
|
} while (0)
|
||||||
array_insert(self, _index, value); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
typedef Array(void) Array;
|
typedef Array(void) Array;
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_delete`.
|
/// This is not what you're looking for, see `array_delete`.
|
||||||
static inline void _array__delete(Array* self)
|
static inline void _array__delete(Array *self) {
|
||||||
{
|
if (self->contents) {
|
||||||
if (self->contents)
|
ts_free(self->contents);
|
||||||
{
|
self->contents = NULL;
|
||||||
ts_free(self->contents);
|
self->size = 0;
|
||||||
self->contents = NULL;
|
self->capacity = 0;
|
||||||
self->size = 0;
|
}
|
||||||
self->capacity = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_erase`.
|
/// This is not what you're looking for, see `array_erase`.
|
||||||
static inline void _array__erase(Array* self, size_t element_size, uint32_t index)
|
static inline void _array__erase(Array *self, size_t element_size,
|
||||||
{
|
uint32_t index) {
|
||||||
assert(index < self->size);
|
assert(index < self->size);
|
||||||
char* contents = (char*)self->contents;
|
char *contents = (char *)self->contents;
|
||||||
memmove(contents + index * element_size, contents + (index + 1) * element_size, (self->size - index - 1) * element_size);
|
memmove(contents + index * element_size, contents + (index + 1) * element_size,
|
||||||
self->size--;
|
(self->size - index - 1) * element_size);
|
||||||
|
self->size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_reserve`.
|
/// This is not what you're looking for, see `array_reserve`.
|
||||||
static inline void _array__reserve(Array* self, size_t element_size, uint32_t new_capacity)
|
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
|
||||||
{
|
if (new_capacity > self->capacity) {
|
||||||
if (new_capacity > self->capacity)
|
if (self->contents) {
|
||||||
{
|
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
||||||
if (self->contents)
|
} else {
|
||||||
{
|
self->contents = ts_malloc(new_capacity * element_size);
|
||||||
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
self->contents = ts_malloc(new_capacity * element_size);
|
|
||||||
}
|
|
||||||
self->capacity = new_capacity;
|
|
||||||
}
|
}
|
||||||
|
self->capacity = new_capacity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_assign`.
|
/// This is not what you're looking for, see `array_assign`.
|
||||||
static inline void _array__assign(Array* self, const Array* other, size_t element_size)
|
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
|
||||||
{
|
_array__reserve(self, element_size, other->size);
|
||||||
_array__reserve(self, element_size, other->size);
|
self->size = other->size;
|
||||||
self->size = other->size;
|
memcpy(self->contents, other->contents, self->size * element_size);
|
||||||
memcpy(self->contents, other->contents, self->size * element_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_swap`.
|
/// This is not what you're looking for, see `array_swap`.
|
||||||
static inline void _array__swap(Array* self, Array* other)
|
static inline void _array__swap(Array *self, Array *other) {
|
||||||
{
|
Array swap = *other;
|
||||||
Array swap = *other;
|
*other = *self;
|
||||||
*other = *self;
|
*self = swap;
|
||||||
*self = swap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
||||||
static inline void _array__grow(Array* self, uint32_t count, size_t element_size)
|
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
|
||||||
{
|
uint32_t new_size = self->size + count;
|
||||||
uint32_t new_size = self->size + count;
|
if (new_size > self->capacity) {
|
||||||
if (new_size > self->capacity)
|
uint32_t new_capacity = self->capacity * 2;
|
||||||
{
|
if (new_capacity < 8) new_capacity = 8;
|
||||||
uint32_t new_capacity = self->capacity * 2;
|
if (new_capacity < new_size) new_capacity = new_size;
|
||||||
if (new_capacity < 8)
|
_array__reserve(self, element_size, new_capacity);
|
||||||
new_capacity = 8;
|
}
|
||||||
if (new_capacity < new_size)
|
|
||||||
new_capacity = new_size;
|
|
||||||
_array__reserve(self, element_size, new_capacity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_splice`.
|
/// This is not what you're looking for, see `array_splice`.
|
||||||
static inline void _array__splice(Array* self, size_t element_size, uint32_t index, uint32_t old_count, uint32_t new_count, const void* elements)
|
static inline void _array__splice(Array *self, size_t element_size,
|
||||||
{
|
uint32_t index, uint32_t old_count,
|
||||||
uint32_t new_size = self->size + new_count - old_count;
|
uint32_t new_count, const void *elements) {
|
||||||
uint32_t old_end = index + old_count;
|
uint32_t new_size = self->size + new_count - old_count;
|
||||||
uint32_t new_end = index + new_count;
|
uint32_t old_end = index + old_count;
|
||||||
assert(old_end <= self->size);
|
uint32_t new_end = index + new_count;
|
||||||
|
assert(old_end <= self->size);
|
||||||
|
|
||||||
_array__reserve(self, element_size, new_size);
|
_array__reserve(self, element_size, new_size);
|
||||||
|
|
||||||
char* contents = (char*)self->contents;
|
char *contents = (char *)self->contents;
|
||||||
if (self->size > old_end)
|
if (self->size > old_end) {
|
||||||
{
|
memmove(
|
||||||
memmove(
|
contents + new_end * element_size,
|
||||||
contents + new_end * element_size,
|
contents + old_end * element_size,
|
||||||
contents + old_end * element_size,
|
(self->size - old_end) * element_size
|
||||||
(self->size - old_end) * element_size);
|
);
|
||||||
|
}
|
||||||
|
if (new_count > 0) {
|
||||||
|
if (elements) {
|
||||||
|
memcpy(
|
||||||
|
(contents + index * element_size),
|
||||||
|
elements,
|
||||||
|
new_count * element_size
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
memset(
|
||||||
|
(contents + index * element_size),
|
||||||
|
0,
|
||||||
|
new_count * element_size
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (new_count > 0)
|
}
|
||||||
{
|
self->size += new_count - old_count;
|
||||||
if (elements)
|
|
||||||
{
|
|
||||||
memcpy(
|
|
||||||
(contents + index * element_size),
|
|
||||||
elements,
|
|
||||||
new_count * element_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(
|
|
||||||
(contents + index * element_size),
|
|
||||||
0,
|
|
||||||
new_count * element_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self->size += new_count - old_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
||||||
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
||||||
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
*(_index) = start; \
|
||||||
*(_index) = start; \
|
*(_exists) = false; \
|
||||||
*(_exists) = false; \
|
uint32_t size = (self)->size - *(_index); \
|
||||||
uint32_t size = (self)->size - *(_index); \
|
if (size == 0) break; \
|
||||||
if (size == 0) \
|
int comparison; \
|
||||||
break; \
|
while (size > 1) { \
|
||||||
int comparison; \
|
uint32_t half_size = size / 2; \
|
||||||
while (size > 1) \
|
uint32_t mid_index = *(_index) + half_size; \
|
||||||
{ \
|
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
||||||
uint32_t half_size = size / 2; \
|
if (comparison <= 0) *(_index) = mid_index; \
|
||||||
uint32_t mid_index = *(_index) + half_size; \
|
size -= half_size; \
|
||||||
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
} \
|
||||||
if (comparison <= 0) \
|
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
||||||
*(_index) = mid_index; \
|
if (comparison == 0) *(_exists) = true; \
|
||||||
size -= half_size; \
|
else if (comparison < 0) *(_index) += 1; \
|
||||||
} \
|
} while (0)
|
||||||
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
|
||||||
if (comparison == 0) \
|
|
||||||
*(_exists) = true; \
|
|
||||||
else if (comparison < 0) \
|
|
||||||
*(_index) += 1; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
||||||
/// parameter by reference in order to work with the generic sorting function above.
|
/// parameter by reference in order to work with the generic sorting function above.
|
||||||
|
|
@ -310,4 +288,4 @@ static inline void _array__splice(Array* self, size_t element_size, uint32_t ind
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TREE_SITTER_ARRAY_H_
|
#endif // TREE_SITTER_ARRAY_H_
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ts_builtin_sym_error ((TSSymbol) - 1)
|
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||||
#define ts_builtin_sym_end 0
|
#define ts_builtin_sym_end 0
|
||||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||||
|
|
||||||
|
|
@ -18,176 +18,155 @@ typedef uint16_t TSStateId;
|
||||||
typedef uint16_t TSSymbol;
|
typedef uint16_t TSSymbol;
|
||||||
typedef uint16_t TSFieldId;
|
typedef uint16_t TSFieldId;
|
||||||
typedef struct TSLanguage TSLanguage;
|
typedef struct TSLanguage TSLanguage;
|
||||||
typedef struct TSLanguageMetadata
|
typedef struct TSLanguageMetadata {
|
||||||
{
|
uint8_t major_version;
|
||||||
uint8_t major_version;
|
uint8_t minor_version;
|
||||||
uint8_t minor_version;
|
uint8_t patch_version;
|
||||||
uint8_t patch_version;
|
|
||||||
} TSLanguageMetadata;
|
} TSLanguageMetadata;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
TSFieldId field_id;
|
||||||
TSFieldId field_id;
|
uint8_t child_index;
|
||||||
uint8_t child_index;
|
bool inherited;
|
||||||
bool inherited;
|
|
||||||
} TSFieldMapEntry;
|
} TSFieldMapEntry;
|
||||||
|
|
||||||
// Used to index the field and supertype maps.
|
// Used to index the field and supertype maps.
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t index;
|
||||||
uint16_t index;
|
uint16_t length;
|
||||||
uint16_t length;
|
|
||||||
} TSMapSlice;
|
} TSMapSlice;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
bool visible;
|
||||||
bool visible;
|
bool named;
|
||||||
bool named;
|
bool supertype;
|
||||||
bool supertype;
|
|
||||||
} TSSymbolMetadata;
|
} TSSymbolMetadata;
|
||||||
|
|
||||||
typedef struct TSLexer TSLexer;
|
typedef struct TSLexer TSLexer;
|
||||||
|
|
||||||
struct TSLexer
|
struct TSLexer {
|
||||||
{
|
int32_t lookahead;
|
||||||
int32_t lookahead;
|
TSSymbol result_symbol;
|
||||||
TSSymbol result_symbol;
|
void (*advance)(TSLexer *, bool);
|
||||||
void (*advance)(TSLexer*, bool);
|
void (*mark_end)(TSLexer *);
|
||||||
void (*mark_end)(TSLexer*);
|
uint32_t (*get_column)(TSLexer *);
|
||||||
uint32_t (*get_column)(TSLexer*);
|
bool (*is_at_included_range_start)(const TSLexer *);
|
||||||
bool (*is_at_included_range_start)(const TSLexer*);
|
bool (*eof)(const TSLexer *);
|
||||||
bool (*eof)(const TSLexer*);
|
void (*log)(const TSLexer *, const char *, ...);
|
||||||
void (*log)(const TSLexer*, const char*, ...);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
TSParseActionTypeShift,
|
||||||
TSParseActionTypeShift,
|
TSParseActionTypeReduce,
|
||||||
TSParseActionTypeReduce,
|
TSParseActionTypeAccept,
|
||||||
TSParseActionTypeAccept,
|
TSParseActionTypeRecover,
|
||||||
TSParseActionTypeRecover,
|
|
||||||
} TSParseActionType;
|
} TSParseActionType;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
struct {
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t type;
|
|
||||||
TSStateId state;
|
|
||||||
bool extra;
|
|
||||||
bool repetition;
|
|
||||||
} shift;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t type;
|
|
||||||
uint8_t child_count;
|
|
||||||
TSSymbol symbol;
|
|
||||||
int16_t dynamic_precedence;
|
|
||||||
uint16_t production_id;
|
|
||||||
} reduce;
|
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
TSStateId state;
|
||||||
|
bool extra;
|
||||||
|
bool repetition;
|
||||||
|
} shift;
|
||||||
|
struct {
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t child_count;
|
||||||
|
TSSymbol symbol;
|
||||||
|
int16_t dynamic_precedence;
|
||||||
|
uint16_t production_id;
|
||||||
|
} reduce;
|
||||||
|
uint8_t type;
|
||||||
} TSParseAction;
|
} TSParseAction;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t lex_state;
|
||||||
uint16_t lex_state;
|
uint16_t external_lex_state;
|
||||||
uint16_t external_lex_state;
|
|
||||||
} TSLexMode;
|
} TSLexMode;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t lex_state;
|
||||||
uint16_t lex_state;
|
uint16_t external_lex_state;
|
||||||
uint16_t external_lex_state;
|
uint16_t reserved_word_set_id;
|
||||||
uint16_t reserved_word_set_id;
|
|
||||||
} TSLexerMode;
|
} TSLexerMode;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
TSParseAction action;
|
||||||
TSParseAction action;
|
struct {
|
||||||
struct
|
uint8_t count;
|
||||||
{
|
bool reusable;
|
||||||
uint8_t count;
|
} entry;
|
||||||
bool reusable;
|
|
||||||
} entry;
|
|
||||||
} TSParseActionEntry;
|
} TSParseActionEntry;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
int32_t start;
|
||||||
int32_t start;
|
int32_t end;
|
||||||
int32_t end;
|
|
||||||
} TSCharacterRange;
|
} TSCharacterRange;
|
||||||
|
|
||||||
struct TSLanguage
|
struct TSLanguage {
|
||||||
{
|
uint32_t abi_version;
|
||||||
uint32_t abi_version;
|
uint32_t symbol_count;
|
||||||
uint32_t symbol_count;
|
uint32_t alias_count;
|
||||||
uint32_t alias_count;
|
uint32_t token_count;
|
||||||
uint32_t token_count;
|
uint32_t external_token_count;
|
||||||
uint32_t external_token_count;
|
uint32_t state_count;
|
||||||
uint32_t state_count;
|
uint32_t large_state_count;
|
||||||
uint32_t large_state_count;
|
uint32_t production_id_count;
|
||||||
uint32_t production_id_count;
|
uint32_t field_count;
|
||||||
uint32_t field_count;
|
uint16_t max_alias_sequence_length;
|
||||||
uint16_t max_alias_sequence_length;
|
const uint16_t *parse_table;
|
||||||
const uint16_t* parse_table;
|
const uint16_t *small_parse_table;
|
||||||
const uint16_t* small_parse_table;
|
const uint32_t *small_parse_table_map;
|
||||||
const uint32_t* small_parse_table_map;
|
const TSParseActionEntry *parse_actions;
|
||||||
const TSParseActionEntry* parse_actions;
|
const char * const *symbol_names;
|
||||||
const char* const* symbol_names;
|
const char * const *field_names;
|
||||||
const char* const* field_names;
|
const TSMapSlice *field_map_slices;
|
||||||
const TSMapSlice* field_map_slices;
|
const TSFieldMapEntry *field_map_entries;
|
||||||
const TSFieldMapEntry* field_map_entries;
|
const TSSymbolMetadata *symbol_metadata;
|
||||||
const TSSymbolMetadata* symbol_metadata;
|
const TSSymbol *public_symbol_map;
|
||||||
const TSSymbol* public_symbol_map;
|
const uint16_t *alias_map;
|
||||||
const uint16_t* alias_map;
|
const TSSymbol *alias_sequences;
|
||||||
const TSSymbol* alias_sequences;
|
const TSLexerMode *lex_modes;
|
||||||
const TSLexerMode* lex_modes;
|
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||||
bool (*lex_fn)(TSLexer*, TSStateId);
|
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||||
bool (*keyword_lex_fn)(TSLexer*, TSStateId);
|
TSSymbol keyword_capture_token;
|
||||||
TSSymbol keyword_capture_token;
|
struct {
|
||||||
struct
|
const bool *states;
|
||||||
{
|
const TSSymbol *symbol_map;
|
||||||
const bool* states;
|
void *(*create)(void);
|
||||||
const TSSymbol* symbol_map;
|
void (*destroy)(void *);
|
||||||
void* (*create)(void);
|
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||||
void (*destroy)(void*);
|
unsigned (*serialize)(void *, char *);
|
||||||
bool (*scan)(void*, TSLexer*, const bool* symbol_whitelist);
|
void (*deserialize)(void *, const char *, unsigned);
|
||||||
unsigned (*serialize)(void*, char*);
|
} external_scanner;
|
||||||
void (*deserialize)(void*, const char*, unsigned);
|
const TSStateId *primary_state_ids;
|
||||||
} external_scanner;
|
const char *name;
|
||||||
const TSStateId* primary_state_ids;
|
const TSSymbol *reserved_words;
|
||||||
const char* name;
|
uint16_t max_reserved_word_set_size;
|
||||||
const TSSymbol* reserved_words;
|
uint32_t supertype_count;
|
||||||
uint16_t max_reserved_word_set_size;
|
const TSSymbol *supertype_symbols;
|
||||||
uint32_t supertype_count;
|
const TSMapSlice *supertype_map_slices;
|
||||||
const TSSymbol* supertype_symbols;
|
const TSSymbol *supertype_map_entries;
|
||||||
const TSMapSlice* supertype_map_slices;
|
TSLanguageMetadata metadata;
|
||||||
const TSSymbol* supertype_map_entries;
|
|
||||||
TSLanguageMetadata metadata;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, int32_t lookahead)
|
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
||||||
{
|
uint32_t index = 0;
|
||||||
uint32_t index = 0;
|
uint32_t size = len - index;
|
||||||
uint32_t size = len - index;
|
while (size > 1) {
|
||||||
while (size > 1)
|
uint32_t half_size = size / 2;
|
||||||
{
|
uint32_t mid_index = index + half_size;
|
||||||
uint32_t half_size = size / 2;
|
const TSCharacterRange *range = &ranges[mid_index];
|
||||||
uint32_t mid_index = index + half_size;
|
if (lookahead >= range->start && lookahead <= range->end) {
|
||||||
const TSCharacterRange* range = &ranges[mid_index];
|
return true;
|
||||||
if (lookahead >= range->start && lookahead <= range->end)
|
} else if (lookahead > range->end) {
|
||||||
{
|
index = mid_index;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (lookahead > range->end)
|
|
||||||
{
|
|
||||||
index = mid_index;
|
|
||||||
}
|
|
||||||
size -= half_size;
|
|
||||||
}
|
}
|
||||||
const TSCharacterRange* range = &ranges[index];
|
size -= half_size;
|
||||||
return (lookahead >= range->start && lookahead <= range->end);
|
}
|
||||||
|
const TSCharacterRange *range = &ranges[index];
|
||||||
|
return (lookahead >= range->start && lookahead <= range->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -200,49 +179,47 @@ static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, in
|
||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define START_LEXER() \
|
#define START_LEXER() \
|
||||||
bool result = false; \
|
bool result = false; \
|
||||||
bool skip = false; \
|
bool skip = false; \
|
||||||
UNUSED \
|
UNUSED \
|
||||||
bool eof = false; \
|
bool eof = false; \
|
||||||
int32_t lookahead; \
|
int32_t lookahead; \
|
||||||
goto start; \
|
goto start; \
|
||||||
next_state: \
|
next_state: \
|
||||||
lexer->advance(lexer, skip); \
|
lexer->advance(lexer, skip); \
|
||||||
start: \
|
start: \
|
||||||
skip = false; \
|
skip = false; \
|
||||||
lookahead = lexer->lookahead;
|
lookahead = lexer->lookahead;
|
||||||
|
|
||||||
#define ADVANCE(state_value) \
|
#define ADVANCE(state_value) \
|
||||||
{ \
|
{ \
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADVANCE_MAP(...) \
|
#define ADVANCE_MAP(...) \
|
||||||
{ \
|
{ \
|
||||||
static const uint16_t map[] = { __VA_ARGS__ }; \
|
static const uint16_t map[] = { __VA_ARGS__ }; \
|
||||||
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) \
|
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
||||||
{ \
|
if (map[i] == lookahead) { \
|
||||||
if (map[i] == lookahead) \
|
state = map[i + 1]; \
|
||||||
{ \
|
goto next_state; \
|
||||||
state = map[i + 1]; \
|
} \
|
||||||
goto next_state; \
|
} \
|
||||||
} \
|
}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SKIP(state_value) \
|
#define SKIP(state_value) \
|
||||||
{ \
|
{ \
|
||||||
skip = true; \
|
skip = true; \
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ACCEPT_TOKEN(symbol_value) \
|
#define ACCEPT_TOKEN(symbol_value) \
|
||||||
result = true; \
|
result = true; \
|
||||||
lexer->result_symbol = symbol_value; \
|
lexer->result_symbol = symbol_value; \
|
||||||
lexer->mark_end(lexer);
|
lexer->mark_end(lexer);
|
||||||
|
|
||||||
#define END_STATE() return result;
|
#define END_STATE() return result;
|
||||||
|
|
||||||
|
|
@ -256,66 +233,54 @@ static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, in
|
||||||
|
|
||||||
#define ACTIONS(id) id
|
#define ACTIONS(id) id
|
||||||
|
|
||||||
#define SHIFT(state_value) \
|
#define SHIFT(state_value) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.state = (state_value) \
|
||||||
.state = (state_value) \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SHIFT_REPEAT(state_value) \
|
#define SHIFT_REPEAT(state_value) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.state = (state_value), \
|
||||||
.state = (state_value), \
|
.repetition = true \
|
||||||
.repetition = true \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SHIFT_EXTRA() \
|
#define SHIFT_EXTRA() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.extra = true \
|
||||||
.extra = true \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.reduce = { \
|
||||||
.reduce = { \
|
.type = TSParseActionTypeReduce, \
|
||||||
.type = TSParseActionTypeReduce, \
|
.symbol = symbol_name, \
|
||||||
.symbol = symbol_name, \
|
.child_count = children, \
|
||||||
.child_count = children, \
|
.dynamic_precedence = precedence, \
|
||||||
.dynamic_precedence = precedence, \
|
.production_id = prod_id \
|
||||||
.production_id = prod_id \
|
}, \
|
||||||
}, \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RECOVER() \
|
#define RECOVER() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.type = TSParseActionTypeRecover \
|
||||||
.type = TSParseActionTypeRecover \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ACCEPT_INPUT() \
|
#define ACCEPT_INPUT() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.type = TSParseActionTypeAccept \
|
||||||
.type = TSParseActionTypeAccept \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TREE_SITTER_PARSER_H_
|
#endif // TREE_SITTER_PARSER_H_
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ export namespace lsp::language::ast::debug
|
||||||
void VisitEchoExpression(EchoExpression& node) override;
|
void VisitEchoExpression(EchoExpression& node) override;
|
||||||
void VisitRaiseExpression(RaiseExpression& node) override;
|
void VisitRaiseExpression(RaiseExpression& node) override;
|
||||||
void VisitInheritedExpression(InheritedExpression& node) override;
|
void VisitInheritedExpression(InheritedExpression& node) override;
|
||||||
|
void VisitRdoExpression(RdoExpression& node) override;
|
||||||
void VisitTSSQLExpression(TSSQLExpression& node) override;
|
void VisitTSSQLExpression(TSSQLExpression& node) override;
|
||||||
void VisitColumnReference(ColumnReference& node) override;
|
void VisitColumnReference(ColumnReference& node) override;
|
||||||
|
|
||||||
|
|
@ -2082,6 +2083,26 @@ export namespace lsp::language::ast::debug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DebugPrinter::VisitRdoExpression(RdoExpression& node)
|
||||||
|
{
|
||||||
|
PrintIndent();
|
||||||
|
PrintColored("RdoExpression", Color::BrightCyan);
|
||||||
|
|
||||||
|
if (options_.show_location)
|
||||||
|
{
|
||||||
|
os_ << " ";
|
||||||
|
PrintLocation(node.span);
|
||||||
|
}
|
||||||
|
os_ << "\n";
|
||||||
|
|
||||||
|
if (node.call)
|
||||||
|
{
|
||||||
|
IncreaseIndent();
|
||||||
|
PrintExpression(node.call.value().get(), "Call", true);
|
||||||
|
DecreaseIndent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DebugPrinter::VisitTSSQLExpression(TSSQLExpression& node)
|
void DebugPrinter::VisitTSSQLExpression(TSSQLExpression& node)
|
||||||
{
|
{
|
||||||
PrintIndent();
|
PrintIndent();
|
||||||
|
|
|
||||||
|
|
@ -1151,6 +1151,7 @@ module.exports = grammar({
|
||||||
$.echo_expression,
|
$.echo_expression,
|
||||||
$.raise_expression,
|
$.raise_expression,
|
||||||
$.inherited_expression,
|
$.inherited_expression,
|
||||||
|
$.rdo_expression,
|
||||||
),
|
),
|
||||||
|
|
||||||
new_expression: ($) => seq(kw("new"), field("constructor", $.expression)),
|
new_expression: ($) => seq(kw("new"), field("constructor", $.expression)),
|
||||||
|
|
@ -1162,7 +1163,13 @@ module.exports = grammar({
|
||||||
inherited_expression: ($) =>
|
inherited_expression: ($) =>
|
||||||
prec.right(
|
prec.right(
|
||||||
kPrec.kCall,
|
kPrec.kCall,
|
||||||
seq(kw("inherited"), optional(field("class", $.call_expression))),
|
seq(kw("inherited"), optional(field("call", $.call_expression))),
|
||||||
|
),
|
||||||
|
|
||||||
|
rdo_expression: ($) =>
|
||||||
|
prec.right(
|
||||||
|
kPrec.kCall,
|
||||||
|
seq(choice(kw("rdo"), kw("rdo2")), optional(field("call", $.call_expression))),
|
||||||
),
|
),
|
||||||
|
|
||||||
array_expression: ($) =>
|
array_expression: ($) =>
|
||||||
|
|
|
||||||
|
|
@ -6754,6 +6754,10 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "inherited_expression"
|
"name": "inherited_expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "rdo_expression"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -6864,7 +6868,55 @@
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "FIELD",
|
||||||
"name": "class",
|
"name": "call",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "call_expression"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rdo_expression": {
|
||||||
|
"type": "PREC_RIGHT",
|
||||||
|
"value": 18,
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "ALIAS",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "(?i)rdo"
|
||||||
|
},
|
||||||
|
"named": false,
|
||||||
|
"value": "rdo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ALIAS",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "(?i)rdo2"
|
||||||
|
},
|
||||||
|
"named": false,
|
||||||
|
"value": "rdo2"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "FIELD",
|
||||||
|
"name": "call",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "call_expression"
|
"name": "call_expression"
|
||||||
|
|
|
||||||
|
|
@ -2256,6 +2256,10 @@
|
||||||
"type": "raise_expression",
|
"type": "raise_expression",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "rdo_expression",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "select_expression",
|
"type": "select_expression",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -3600,7 +3604,7 @@
|
||||||
"type": "inherited_expression",
|
"type": "inherited_expression",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {
|
"fields": {
|
||||||
"class": {
|
"call": {
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
"required": false,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
|
|
@ -4863,6 +4867,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "rdo_expression",
|
||||||
|
"named": true,
|
||||||
|
"fields": {
|
||||||
|
"call": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "call_expression",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "reference_modifier",
|
"type": "reference_modifier",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
@ -7001,6 +7021,14 @@
|
||||||
"type": "raise",
|
"type": "raise",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "rdo",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "rdo2",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "read",
|
"type": "read",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -12,37 +12,37 @@ extern "C" {
|
||||||
// Allow clients to override allocation functions
|
// Allow clients to override allocation functions
|
||||||
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
||||||
|
|
||||||
extern void* (*ts_current_malloc)(size_t size);
|
extern void *(*ts_current_malloc)(size_t size);
|
||||||
extern void* (*ts_current_calloc)(size_t count, size_t size);
|
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
||||||
extern void* (*ts_current_realloc)(void* ptr, size_t size);
|
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
||||||
extern void (*ts_current_free)(void* ptr);
|
extern void (*ts_current_free)(void *ptr);
|
||||||
|
|
||||||
#ifndef ts_malloc
|
#ifndef ts_malloc
|
||||||
#define ts_malloc ts_current_malloc
|
#define ts_malloc ts_current_malloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_calloc
|
#ifndef ts_calloc
|
||||||
#define ts_calloc ts_current_calloc
|
#define ts_calloc ts_current_calloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_realloc
|
#ifndef ts_realloc
|
||||||
#define ts_realloc ts_current_realloc
|
#define ts_realloc ts_current_realloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_free
|
#ifndef ts_free
|
||||||
#define ts_free ts_current_free
|
#define ts_free ts_current_free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifndef ts_malloc
|
#ifndef ts_malloc
|
||||||
#define ts_malloc malloc
|
#define ts_malloc malloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_calloc
|
#ifndef ts_calloc
|
||||||
#define ts_calloc calloc
|
#define ts_calloc calloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_realloc
|
#ifndef ts_realloc
|
||||||
#define ts_realloc realloc
|
#define ts_realloc realloc
|
||||||
#endif
|
#endif
|
||||||
#ifndef ts_free
|
#ifndef ts_free
|
||||||
#define ts_free free
|
#define ts_free free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -21,25 +21,24 @@ extern "C" {
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define Array(T) \
|
#define Array(T) \
|
||||||
struct \
|
struct { \
|
||||||
{ \
|
T *contents; \
|
||||||
T* contents; \
|
uint32_t size; \
|
||||||
uint32_t size; \
|
uint32_t capacity; \
|
||||||
uint32_t capacity; \
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Initialize an array.
|
/// Initialize an array.
|
||||||
#define array_init(self) \
|
#define array_init(self) \
|
||||||
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
||||||
|
|
||||||
/// Create an empty array.
|
/// Create an empty array.
|
||||||
#define array_new() \
|
#define array_new() \
|
||||||
{ NULL, 0, 0 }
|
{ NULL, 0, 0 }
|
||||||
|
|
||||||
/// Get a pointer to the element at a given `index` in the array.
|
/// Get a pointer to the element at a given `index` in the array.
|
||||||
#define array_get(self, _index) \
|
#define array_get(self, _index) \
|
||||||
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
||||||
|
|
||||||
/// Get a pointer to the first element in the array.
|
/// Get a pointer to the first element in the array.
|
||||||
#define array_front(self) array_get(self, 0)
|
#define array_front(self) array_get(self, 0)
|
||||||
|
|
@ -54,64 +53,66 @@ extern "C" {
|
||||||
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
||||||
/// less than the array's current capacity, this function has no effect.
|
/// less than the array's current capacity, this function has no effect.
|
||||||
#define array_reserve(self, new_capacity) \
|
#define array_reserve(self, new_capacity) \
|
||||||
_array__reserve((Array*)(self), array_elem_size(self), new_capacity)
|
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
|
||||||
|
|
||||||
/// Free any memory allocated for this array. Note that this does not free any
|
/// Free any memory allocated for this array. Note that this does not free any
|
||||||
/// memory allocated for the array's contents.
|
/// memory allocated for the array's contents.
|
||||||
#define array_delete(self) _array__delete((Array*)(self))
|
#define array_delete(self) _array__delete((Array *)(self))
|
||||||
|
|
||||||
/// Push a new `element` onto the end of the array.
|
/// Push a new `element` onto the end of the array.
|
||||||
#define array_push(self, element) \
|
#define array_push(self, element) \
|
||||||
(_array__grow((Array*)(self), 1, array_elem_size(self)), \
|
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
|
||||||
(self)->contents[(self)->size++] = (element))
|
(self)->contents[(self)->size++] = (element))
|
||||||
|
|
||||||
/// Increase the array's size by `count` elements.
|
/// Increase the array's size by `count` elements.
|
||||||
/// New elements are zero-initialized.
|
/// New elements are zero-initialized.
|
||||||
#define array_grow_by(self, count) \
|
#define array_grow_by(self, count) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
if ((count) == 0) break; \
|
||||||
if ((count) == 0) \
|
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
||||||
break; \
|
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
||||||
_array__grow((Array*)(self), count, array_elem_size(self)); \
|
(self)->size += (count); \
|
||||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
} while (0)
|
||||||
(self)->size += (count); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Append all elements from one array to the end of another.
|
/// Append all elements from one array to the end of another.
|
||||||
#define array_push_all(self, other) \
|
#define array_push_all(self, other) \
|
||||||
array_extend((self), (other)->size, (other)->contents)
|
array_extend((self), (other)->size, (other)->contents)
|
||||||
|
|
||||||
/// Append `count` elements to the end of the array, reading their values from the
|
/// Append `count` elements to the end of the array, reading their values from the
|
||||||
/// `contents` pointer.
|
/// `contents` pointer.
|
||||||
#define array_extend(self, count, contents) \
|
#define array_extend(self, count, contents) \
|
||||||
_array__splice( \
|
_array__splice( \
|
||||||
(Array*)(self), array_elem_size(self), (self)->size, 0, count, contents)
|
(Array *)(self), array_elem_size(self), (self)->size, \
|
||||||
|
0, count, contents \
|
||||||
|
)
|
||||||
|
|
||||||
/// Remove `old_count` elements from the array starting at the given `index`. At
|
/// Remove `old_count` elements from the array starting at the given `index`. At
|
||||||
/// the same index, insert `new_count` new elements, reading their values from the
|
/// the same index, insert `new_count` new elements, reading their values from the
|
||||||
/// `new_contents` pointer.
|
/// `new_contents` pointer.
|
||||||
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
||||||
_array__splice( \
|
_array__splice( \
|
||||||
(Array*)(self), array_elem_size(self), _index, old_count, new_count, new_contents)
|
(Array *)(self), array_elem_size(self), _index, \
|
||||||
|
old_count, new_count, new_contents \
|
||||||
|
)
|
||||||
|
|
||||||
/// Insert one `element` into the array at the given `index`.
|
/// Insert one `element` into the array at the given `index`.
|
||||||
#define array_insert(self, _index, element) \
|
#define array_insert(self, _index, element) \
|
||||||
_array__splice((Array*)(self), array_elem_size(self), _index, 0, 1, &(element))
|
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
|
||||||
|
|
||||||
/// Remove one element from the array at the given `index`.
|
/// Remove one element from the array at the given `index`.
|
||||||
#define array_erase(self, _index) \
|
#define array_erase(self, _index) \
|
||||||
_array__erase((Array*)(self), array_elem_size(self), _index)
|
_array__erase((Array *)(self), array_elem_size(self), _index)
|
||||||
|
|
||||||
/// Pop the last element off the array, returning the element by value.
|
/// Pop the last element off the array, returning the element by value.
|
||||||
#define array_pop(self) ((self)->contents[--(self)->size])
|
#define array_pop(self) ((self)->contents[--(self)->size])
|
||||||
|
|
||||||
/// Assign the contents of one array to another, reallocating if necessary.
|
/// Assign the contents of one array to another, reallocating if necessary.
|
||||||
#define array_assign(self, other) \
|
#define array_assign(self, other) \
|
||||||
_array__assign((Array*)(self), (const Array*)(other), array_elem_size(self))
|
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
|
||||||
|
|
||||||
/// Swap one array with another
|
/// Swap one array with another
|
||||||
#define array_swap(self, other) \
|
#define array_swap(self, other) \
|
||||||
_array__swap((Array*)(self), (Array*)(other))
|
_array__swap((Array *)(self), (Array *)(other))
|
||||||
|
|
||||||
/// Get the size of the array contents
|
/// Get the size of the array contents
|
||||||
#define array_elem_size(self) (sizeof *(self)->contents)
|
#define array_elem_size(self) (sizeof *(self)->contents)
|
||||||
|
|
@ -125,176 +126,153 @@ extern "C" {
|
||||||
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
||||||
/// is set to false.
|
/// is set to false.
|
||||||
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
||||||
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
||||||
|
|
||||||
/// Search a sorted array for a given `needle` value, using integer comparisons
|
/// Search a sorted array for a given `needle` value, using integer comparisons
|
||||||
/// of a given struct field (specified with a leading dot) to determine the order.
|
/// of a given struct field (specified with a leading dot) to determine the order.
|
||||||
///
|
///
|
||||||
/// See also `array_search_sorted_with`.
|
/// See also `array_search_sorted_with`.
|
||||||
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
||||||
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
||||||
|
|
||||||
/// Insert a given `value` into a sorted array, using the given `compare`
|
/// Insert a given `value` into a sorted array, using the given `compare`
|
||||||
/// callback to determine the order.
|
/// callback to determine the order.
|
||||||
#define array_insert_sorted_with(self, compare, value) \
|
#define array_insert_sorted_with(self, compare, value) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
unsigned _index, _exists; \
|
||||||
unsigned _index, _exists; \
|
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
||||||
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
if (!_exists) array_insert(self, _index, value); \
|
||||||
if (!_exists) \
|
} while (0)
|
||||||
array_insert(self, _index, value); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Insert a given `value` into a sorted array, using integer comparisons of
|
/// Insert a given `value` into a sorted array, using integer comparisons of
|
||||||
/// a given struct field (specified with a leading dot) to determine the order.
|
/// a given struct field (specified with a leading dot) to determine the order.
|
||||||
///
|
///
|
||||||
/// See also `array_search_sorted_by`.
|
/// See also `array_search_sorted_by`.
|
||||||
#define array_insert_sorted_by(self, field, value) \
|
#define array_insert_sorted_by(self, field, value) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
unsigned _index, _exists; \
|
||||||
unsigned _index, _exists; \
|
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
|
||||||
array_search_sorted_by(self, field, (value)field, &_index, &_exists); \
|
if (!_exists) array_insert(self, _index, value); \
|
||||||
if (!_exists) \
|
} while (0)
|
||||||
array_insert(self, _index, value); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
typedef Array(void) Array;
|
typedef Array(void) Array;
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_delete`.
|
/// This is not what you're looking for, see `array_delete`.
|
||||||
static inline void _array__delete(Array* self)
|
static inline void _array__delete(Array *self) {
|
||||||
{
|
if (self->contents) {
|
||||||
if (self->contents)
|
ts_free(self->contents);
|
||||||
{
|
self->contents = NULL;
|
||||||
ts_free(self->contents);
|
self->size = 0;
|
||||||
self->contents = NULL;
|
self->capacity = 0;
|
||||||
self->size = 0;
|
}
|
||||||
self->capacity = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_erase`.
|
/// This is not what you're looking for, see `array_erase`.
|
||||||
static inline void _array__erase(Array* self, size_t element_size, uint32_t index)
|
static inline void _array__erase(Array *self, size_t element_size,
|
||||||
{
|
uint32_t index) {
|
||||||
assert(index < self->size);
|
assert(index < self->size);
|
||||||
char* contents = (char*)self->contents;
|
char *contents = (char *)self->contents;
|
||||||
memmove(contents + index * element_size, contents + (index + 1) * element_size, (self->size - index - 1) * element_size);
|
memmove(contents + index * element_size, contents + (index + 1) * element_size,
|
||||||
self->size--;
|
(self->size - index - 1) * element_size);
|
||||||
|
self->size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_reserve`.
|
/// This is not what you're looking for, see `array_reserve`.
|
||||||
static inline void _array__reserve(Array* self, size_t element_size, uint32_t new_capacity)
|
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
|
||||||
{
|
if (new_capacity > self->capacity) {
|
||||||
if (new_capacity > self->capacity)
|
if (self->contents) {
|
||||||
{
|
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
||||||
if (self->contents)
|
} else {
|
||||||
{
|
self->contents = ts_malloc(new_capacity * element_size);
|
||||||
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
self->contents = ts_malloc(new_capacity * element_size);
|
|
||||||
}
|
|
||||||
self->capacity = new_capacity;
|
|
||||||
}
|
}
|
||||||
|
self->capacity = new_capacity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_assign`.
|
/// This is not what you're looking for, see `array_assign`.
|
||||||
static inline void _array__assign(Array* self, const Array* other, size_t element_size)
|
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
|
||||||
{
|
_array__reserve(self, element_size, other->size);
|
||||||
_array__reserve(self, element_size, other->size);
|
self->size = other->size;
|
||||||
self->size = other->size;
|
memcpy(self->contents, other->contents, self->size * element_size);
|
||||||
memcpy(self->contents, other->contents, self->size * element_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_swap`.
|
/// This is not what you're looking for, see `array_swap`.
|
||||||
static inline void _array__swap(Array* self, Array* other)
|
static inline void _array__swap(Array *self, Array *other) {
|
||||||
{
|
Array swap = *other;
|
||||||
Array swap = *other;
|
*other = *self;
|
||||||
*other = *self;
|
*self = swap;
|
||||||
*self = swap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
||||||
static inline void _array__grow(Array* self, uint32_t count, size_t element_size)
|
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
|
||||||
{
|
uint32_t new_size = self->size + count;
|
||||||
uint32_t new_size = self->size + count;
|
if (new_size > self->capacity) {
|
||||||
if (new_size > self->capacity)
|
uint32_t new_capacity = self->capacity * 2;
|
||||||
{
|
if (new_capacity < 8) new_capacity = 8;
|
||||||
uint32_t new_capacity = self->capacity * 2;
|
if (new_capacity < new_size) new_capacity = new_size;
|
||||||
if (new_capacity < 8)
|
_array__reserve(self, element_size, new_capacity);
|
||||||
new_capacity = 8;
|
}
|
||||||
if (new_capacity < new_size)
|
|
||||||
new_capacity = new_size;
|
|
||||||
_array__reserve(self, element_size, new_capacity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is not what you're looking for, see `array_splice`.
|
/// This is not what you're looking for, see `array_splice`.
|
||||||
static inline void _array__splice(Array* self, size_t element_size, uint32_t index, uint32_t old_count, uint32_t new_count, const void* elements)
|
static inline void _array__splice(Array *self, size_t element_size,
|
||||||
{
|
uint32_t index, uint32_t old_count,
|
||||||
uint32_t new_size = self->size + new_count - old_count;
|
uint32_t new_count, const void *elements) {
|
||||||
uint32_t old_end = index + old_count;
|
uint32_t new_size = self->size + new_count - old_count;
|
||||||
uint32_t new_end = index + new_count;
|
uint32_t old_end = index + old_count;
|
||||||
assert(old_end <= self->size);
|
uint32_t new_end = index + new_count;
|
||||||
|
assert(old_end <= self->size);
|
||||||
|
|
||||||
_array__reserve(self, element_size, new_size);
|
_array__reserve(self, element_size, new_size);
|
||||||
|
|
||||||
char* contents = (char*)self->contents;
|
char *contents = (char *)self->contents;
|
||||||
if (self->size > old_end)
|
if (self->size > old_end) {
|
||||||
{
|
memmove(
|
||||||
memmove(
|
contents + new_end * element_size,
|
||||||
contents + new_end * element_size,
|
contents + old_end * element_size,
|
||||||
contents + old_end * element_size,
|
(self->size - old_end) * element_size
|
||||||
(self->size - old_end) * element_size);
|
);
|
||||||
|
}
|
||||||
|
if (new_count > 0) {
|
||||||
|
if (elements) {
|
||||||
|
memcpy(
|
||||||
|
(contents + index * element_size),
|
||||||
|
elements,
|
||||||
|
new_count * element_size
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
memset(
|
||||||
|
(contents + index * element_size),
|
||||||
|
0,
|
||||||
|
new_count * element_size
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (new_count > 0)
|
}
|
||||||
{
|
self->size += new_count - old_count;
|
||||||
if (elements)
|
|
||||||
{
|
|
||||||
memcpy(
|
|
||||||
(contents + index * element_size),
|
|
||||||
elements,
|
|
||||||
new_count * element_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memset(
|
|
||||||
(contents + index * element_size),
|
|
||||||
0,
|
|
||||||
new_count * element_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self->size += new_count - old_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
||||||
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
||||||
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
||||||
do \
|
do { \
|
||||||
{ \
|
*(_index) = start; \
|
||||||
*(_index) = start; \
|
*(_exists) = false; \
|
||||||
*(_exists) = false; \
|
uint32_t size = (self)->size - *(_index); \
|
||||||
uint32_t size = (self)->size - *(_index); \
|
if (size == 0) break; \
|
||||||
if (size == 0) \
|
int comparison; \
|
||||||
break; \
|
while (size > 1) { \
|
||||||
int comparison; \
|
uint32_t half_size = size / 2; \
|
||||||
while (size > 1) \
|
uint32_t mid_index = *(_index) + half_size; \
|
||||||
{ \
|
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
||||||
uint32_t half_size = size / 2; \
|
if (comparison <= 0) *(_index) = mid_index; \
|
||||||
uint32_t mid_index = *(_index) + half_size; \
|
size -= half_size; \
|
||||||
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
} \
|
||||||
if (comparison <= 0) \
|
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
||||||
*(_index) = mid_index; \
|
if (comparison == 0) *(_exists) = true; \
|
||||||
size -= half_size; \
|
else if (comparison < 0) *(_index) += 1; \
|
||||||
} \
|
} while (0)
|
||||||
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
|
||||||
if (comparison == 0) \
|
|
||||||
*(_exists) = true; \
|
|
||||||
else if (comparison < 0) \
|
|
||||||
*(_index) += 1; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
||||||
/// parameter by reference in order to work with the generic sorting function above.
|
/// parameter by reference in order to work with the generic sorting function above.
|
||||||
|
|
@ -310,4 +288,4 @@ static inline void _array__splice(Array* self, size_t element_size, uint32_t ind
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TREE_SITTER_ARRAY_H_
|
#endif // TREE_SITTER_ARRAY_H_
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ts_builtin_sym_error ((TSSymbol) - 1)
|
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||||
#define ts_builtin_sym_end 0
|
#define ts_builtin_sym_end 0
|
||||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||||
|
|
||||||
|
|
@ -18,176 +18,155 @@ typedef uint16_t TSStateId;
|
||||||
typedef uint16_t TSSymbol;
|
typedef uint16_t TSSymbol;
|
||||||
typedef uint16_t TSFieldId;
|
typedef uint16_t TSFieldId;
|
||||||
typedef struct TSLanguage TSLanguage;
|
typedef struct TSLanguage TSLanguage;
|
||||||
typedef struct TSLanguageMetadata
|
typedef struct TSLanguageMetadata {
|
||||||
{
|
uint8_t major_version;
|
||||||
uint8_t major_version;
|
uint8_t minor_version;
|
||||||
uint8_t minor_version;
|
uint8_t patch_version;
|
||||||
uint8_t patch_version;
|
|
||||||
} TSLanguageMetadata;
|
} TSLanguageMetadata;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
TSFieldId field_id;
|
||||||
TSFieldId field_id;
|
uint8_t child_index;
|
||||||
uint8_t child_index;
|
bool inherited;
|
||||||
bool inherited;
|
|
||||||
} TSFieldMapEntry;
|
} TSFieldMapEntry;
|
||||||
|
|
||||||
// Used to index the field and supertype maps.
|
// Used to index the field and supertype maps.
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t index;
|
||||||
uint16_t index;
|
uint16_t length;
|
||||||
uint16_t length;
|
|
||||||
} TSMapSlice;
|
} TSMapSlice;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
bool visible;
|
||||||
bool visible;
|
bool named;
|
||||||
bool named;
|
bool supertype;
|
||||||
bool supertype;
|
|
||||||
} TSSymbolMetadata;
|
} TSSymbolMetadata;
|
||||||
|
|
||||||
typedef struct TSLexer TSLexer;
|
typedef struct TSLexer TSLexer;
|
||||||
|
|
||||||
struct TSLexer
|
struct TSLexer {
|
||||||
{
|
int32_t lookahead;
|
||||||
int32_t lookahead;
|
TSSymbol result_symbol;
|
||||||
TSSymbol result_symbol;
|
void (*advance)(TSLexer *, bool);
|
||||||
void (*advance)(TSLexer*, bool);
|
void (*mark_end)(TSLexer *);
|
||||||
void (*mark_end)(TSLexer*);
|
uint32_t (*get_column)(TSLexer *);
|
||||||
uint32_t (*get_column)(TSLexer*);
|
bool (*is_at_included_range_start)(const TSLexer *);
|
||||||
bool (*is_at_included_range_start)(const TSLexer*);
|
bool (*eof)(const TSLexer *);
|
||||||
bool (*eof)(const TSLexer*);
|
void (*log)(const TSLexer *, const char *, ...);
|
||||||
void (*log)(const TSLexer*, const char*, ...);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum {
|
||||||
{
|
TSParseActionTypeShift,
|
||||||
TSParseActionTypeShift,
|
TSParseActionTypeReduce,
|
||||||
TSParseActionTypeReduce,
|
TSParseActionTypeAccept,
|
||||||
TSParseActionTypeAccept,
|
TSParseActionTypeRecover,
|
||||||
TSParseActionTypeRecover,
|
|
||||||
} TSParseActionType;
|
} TSParseActionType;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
struct {
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t type;
|
|
||||||
TSStateId state;
|
|
||||||
bool extra;
|
|
||||||
bool repetition;
|
|
||||||
} shift;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
uint8_t type;
|
|
||||||
uint8_t child_count;
|
|
||||||
TSSymbol symbol;
|
|
||||||
int16_t dynamic_precedence;
|
|
||||||
uint16_t production_id;
|
|
||||||
} reduce;
|
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
TSStateId state;
|
||||||
|
bool extra;
|
||||||
|
bool repetition;
|
||||||
|
} shift;
|
||||||
|
struct {
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t child_count;
|
||||||
|
TSSymbol symbol;
|
||||||
|
int16_t dynamic_precedence;
|
||||||
|
uint16_t production_id;
|
||||||
|
} reduce;
|
||||||
|
uint8_t type;
|
||||||
} TSParseAction;
|
} TSParseAction;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t lex_state;
|
||||||
uint16_t lex_state;
|
uint16_t external_lex_state;
|
||||||
uint16_t external_lex_state;
|
|
||||||
} TSLexMode;
|
} TSLexMode;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
uint16_t lex_state;
|
||||||
uint16_t lex_state;
|
uint16_t external_lex_state;
|
||||||
uint16_t external_lex_state;
|
uint16_t reserved_word_set_id;
|
||||||
uint16_t reserved_word_set_id;
|
|
||||||
} TSLexerMode;
|
} TSLexerMode;
|
||||||
|
|
||||||
typedef union
|
typedef union {
|
||||||
{
|
TSParseAction action;
|
||||||
TSParseAction action;
|
struct {
|
||||||
struct
|
uint8_t count;
|
||||||
{
|
bool reusable;
|
||||||
uint8_t count;
|
} entry;
|
||||||
bool reusable;
|
|
||||||
} entry;
|
|
||||||
} TSParseActionEntry;
|
} TSParseActionEntry;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
int32_t start;
|
||||||
int32_t start;
|
int32_t end;
|
||||||
int32_t end;
|
|
||||||
} TSCharacterRange;
|
} TSCharacterRange;
|
||||||
|
|
||||||
struct TSLanguage
|
struct TSLanguage {
|
||||||
{
|
uint32_t abi_version;
|
||||||
uint32_t abi_version;
|
uint32_t symbol_count;
|
||||||
uint32_t symbol_count;
|
uint32_t alias_count;
|
||||||
uint32_t alias_count;
|
uint32_t token_count;
|
||||||
uint32_t token_count;
|
uint32_t external_token_count;
|
||||||
uint32_t external_token_count;
|
uint32_t state_count;
|
||||||
uint32_t state_count;
|
uint32_t large_state_count;
|
||||||
uint32_t large_state_count;
|
uint32_t production_id_count;
|
||||||
uint32_t production_id_count;
|
uint32_t field_count;
|
||||||
uint32_t field_count;
|
uint16_t max_alias_sequence_length;
|
||||||
uint16_t max_alias_sequence_length;
|
const uint16_t *parse_table;
|
||||||
const uint16_t* parse_table;
|
const uint16_t *small_parse_table;
|
||||||
const uint16_t* small_parse_table;
|
const uint32_t *small_parse_table_map;
|
||||||
const uint32_t* small_parse_table_map;
|
const TSParseActionEntry *parse_actions;
|
||||||
const TSParseActionEntry* parse_actions;
|
const char * const *symbol_names;
|
||||||
const char* const* symbol_names;
|
const char * const *field_names;
|
||||||
const char* const* field_names;
|
const TSMapSlice *field_map_slices;
|
||||||
const TSMapSlice* field_map_slices;
|
const TSFieldMapEntry *field_map_entries;
|
||||||
const TSFieldMapEntry* field_map_entries;
|
const TSSymbolMetadata *symbol_metadata;
|
||||||
const TSSymbolMetadata* symbol_metadata;
|
const TSSymbol *public_symbol_map;
|
||||||
const TSSymbol* public_symbol_map;
|
const uint16_t *alias_map;
|
||||||
const uint16_t* alias_map;
|
const TSSymbol *alias_sequences;
|
||||||
const TSSymbol* alias_sequences;
|
const TSLexerMode *lex_modes;
|
||||||
const TSLexerMode* lex_modes;
|
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||||
bool (*lex_fn)(TSLexer*, TSStateId);
|
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||||
bool (*keyword_lex_fn)(TSLexer*, TSStateId);
|
TSSymbol keyword_capture_token;
|
||||||
TSSymbol keyword_capture_token;
|
struct {
|
||||||
struct
|
const bool *states;
|
||||||
{
|
const TSSymbol *symbol_map;
|
||||||
const bool* states;
|
void *(*create)(void);
|
||||||
const TSSymbol* symbol_map;
|
void (*destroy)(void *);
|
||||||
void* (*create)(void);
|
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||||
void (*destroy)(void*);
|
unsigned (*serialize)(void *, char *);
|
||||||
bool (*scan)(void*, TSLexer*, const bool* symbol_whitelist);
|
void (*deserialize)(void *, const char *, unsigned);
|
||||||
unsigned (*serialize)(void*, char*);
|
} external_scanner;
|
||||||
void (*deserialize)(void*, const char*, unsigned);
|
const TSStateId *primary_state_ids;
|
||||||
} external_scanner;
|
const char *name;
|
||||||
const TSStateId* primary_state_ids;
|
const TSSymbol *reserved_words;
|
||||||
const char* name;
|
uint16_t max_reserved_word_set_size;
|
||||||
const TSSymbol* reserved_words;
|
uint32_t supertype_count;
|
||||||
uint16_t max_reserved_word_set_size;
|
const TSSymbol *supertype_symbols;
|
||||||
uint32_t supertype_count;
|
const TSMapSlice *supertype_map_slices;
|
||||||
const TSSymbol* supertype_symbols;
|
const TSSymbol *supertype_map_entries;
|
||||||
const TSMapSlice* supertype_map_slices;
|
TSLanguageMetadata metadata;
|
||||||
const TSSymbol* supertype_map_entries;
|
|
||||||
TSLanguageMetadata metadata;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, int32_t lookahead)
|
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
||||||
{
|
uint32_t index = 0;
|
||||||
uint32_t index = 0;
|
uint32_t size = len - index;
|
||||||
uint32_t size = len - index;
|
while (size > 1) {
|
||||||
while (size > 1)
|
uint32_t half_size = size / 2;
|
||||||
{
|
uint32_t mid_index = index + half_size;
|
||||||
uint32_t half_size = size / 2;
|
const TSCharacterRange *range = &ranges[mid_index];
|
||||||
uint32_t mid_index = index + half_size;
|
if (lookahead >= range->start && lookahead <= range->end) {
|
||||||
const TSCharacterRange* range = &ranges[mid_index];
|
return true;
|
||||||
if (lookahead >= range->start && lookahead <= range->end)
|
} else if (lookahead > range->end) {
|
||||||
{
|
index = mid_index;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (lookahead > range->end)
|
|
||||||
{
|
|
||||||
index = mid_index;
|
|
||||||
}
|
|
||||||
size -= half_size;
|
|
||||||
}
|
}
|
||||||
const TSCharacterRange* range = &ranges[index];
|
size -= half_size;
|
||||||
return (lookahead >= range->start && lookahead <= range->end);
|
}
|
||||||
|
const TSCharacterRange *range = &ranges[index];
|
||||||
|
return (lookahead >= range->start && lookahead <= range->end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -200,49 +179,47 @@ static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, in
|
||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define START_LEXER() \
|
#define START_LEXER() \
|
||||||
bool result = false; \
|
bool result = false; \
|
||||||
bool skip = false; \
|
bool skip = false; \
|
||||||
UNUSED \
|
UNUSED \
|
||||||
bool eof = false; \
|
bool eof = false; \
|
||||||
int32_t lookahead; \
|
int32_t lookahead; \
|
||||||
goto start; \
|
goto start; \
|
||||||
next_state: \
|
next_state: \
|
||||||
lexer->advance(lexer, skip); \
|
lexer->advance(lexer, skip); \
|
||||||
start: \
|
start: \
|
||||||
skip = false; \
|
skip = false; \
|
||||||
lookahead = lexer->lookahead;
|
lookahead = lexer->lookahead;
|
||||||
|
|
||||||
#define ADVANCE(state_value) \
|
#define ADVANCE(state_value) \
|
||||||
{ \
|
{ \
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADVANCE_MAP(...) \
|
#define ADVANCE_MAP(...) \
|
||||||
{ \
|
{ \
|
||||||
static const uint16_t map[] = { __VA_ARGS__ }; \
|
static const uint16_t map[] = { __VA_ARGS__ }; \
|
||||||
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) \
|
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
||||||
{ \
|
if (map[i] == lookahead) { \
|
||||||
if (map[i] == lookahead) \
|
state = map[i + 1]; \
|
||||||
{ \
|
goto next_state; \
|
||||||
state = map[i + 1]; \
|
} \
|
||||||
goto next_state; \
|
} \
|
||||||
} \
|
}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SKIP(state_value) \
|
#define SKIP(state_value) \
|
||||||
{ \
|
{ \
|
||||||
skip = true; \
|
skip = true; \
|
||||||
state = state_value; \
|
state = state_value; \
|
||||||
goto next_state; \
|
goto next_state; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ACCEPT_TOKEN(symbol_value) \
|
#define ACCEPT_TOKEN(symbol_value) \
|
||||||
result = true; \
|
result = true; \
|
||||||
lexer->result_symbol = symbol_value; \
|
lexer->result_symbol = symbol_value; \
|
||||||
lexer->mark_end(lexer);
|
lexer->mark_end(lexer);
|
||||||
|
|
||||||
#define END_STATE() return result;
|
#define END_STATE() return result;
|
||||||
|
|
||||||
|
|
@ -256,66 +233,54 @@ static inline bool set_contains(const TSCharacterRange* ranges, uint32_t len, in
|
||||||
|
|
||||||
#define ACTIONS(id) id
|
#define ACTIONS(id) id
|
||||||
|
|
||||||
#define SHIFT(state_value) \
|
#define SHIFT(state_value) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.state = (state_value) \
|
||||||
.state = (state_value) \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SHIFT_REPEAT(state_value) \
|
#define SHIFT_REPEAT(state_value) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.state = (state_value), \
|
||||||
.state = (state_value), \
|
.repetition = true \
|
||||||
.repetition = true \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SHIFT_EXTRA() \
|
#define SHIFT_EXTRA() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.shift = { \
|
||||||
.shift = { \
|
.type = TSParseActionTypeShift, \
|
||||||
.type = TSParseActionTypeShift, \
|
.extra = true \
|
||||||
.extra = true \
|
} \
|
||||||
} \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
#define REDUCE(symbol_name, children, precedence, prod_id) \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.reduce = { \
|
||||||
.reduce = { \
|
.type = TSParseActionTypeReduce, \
|
||||||
.type = TSParseActionTypeReduce, \
|
.symbol = symbol_name, \
|
||||||
.symbol = symbol_name, \
|
.child_count = children, \
|
||||||
.child_count = children, \
|
.dynamic_precedence = precedence, \
|
||||||
.dynamic_precedence = precedence, \
|
.production_id = prod_id \
|
||||||
.production_id = prod_id \
|
}, \
|
||||||
}, \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RECOVER() \
|
#define RECOVER() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.type = TSParseActionTypeRecover \
|
||||||
.type = TSParseActionTypeRecover \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ACCEPT_INPUT() \
|
#define ACCEPT_INPUT() \
|
||||||
{ \
|
{{ \
|
||||||
{ \
|
.type = TSParseActionTypeAccept \
|
||||||
.type = TSParseActionTypeAccept \
|
}}
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TREE_SITTER_PARSER_H_
|
#endif // TREE_SITTER_PARSER_H_
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue