From 4b1f69142d2c75354eb7012908418ec5e3260586 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Apr 2017 09:46:01 -0400 Subject: [PATCH 1/2] Define a symbol type enum. --- include/tree_sitter/runtime.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index cc551ebb..37f99e54 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -20,6 +20,12 @@ typedef enum { TSInputEncodingUTF16, } TSInputEncoding; +typedef enum { + TSSymbolTypeRegular, + TSSymbolTypeAnonymous, + TSSymbolTypeAuxiliary, +} TSSymbolType; + typedef struct { void *payload; const char *(*read)(void *payload, uint32_t *bytes_read); From 3a888b16233e00be445fbf5e994a92a103e324df Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Apr 2017 09:47:51 -0400 Subject: [PATCH 2/2] Define a function providing the type of a given symbol. --- include/tree_sitter/runtime.h | 1 + src/runtime/language.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/tree_sitter/runtime.h b/include/tree_sitter/runtime.h index 37f99e54..6f37c9a3 100644 --- a/include/tree_sitter/runtime.h +++ b/include/tree_sitter/runtime.h @@ -123,6 +123,7 @@ uint32_t ts_document_parse_count(const TSDocument *); uint32_t ts_language_symbol_count(const TSLanguage *); const char *ts_language_symbol_name(const TSLanguage *, TSSymbol); +TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol); uint32_t ts_language_version(const TSLanguage *); #ifdef __cplusplus diff --git a/src/runtime/language.c b/src/runtime/language.c index 05361a81..8ca4de50 100644 --- a/src/runtime/language.c +++ b/src/runtime/language.c @@ -54,3 +54,14 @@ const char *ts_language_symbol_name(const TSLanguage *language, TSSymbol symbol) else return language->symbol_names[symbol]; } + +TSSymbolType ts_language_symbol_type(const TSLanguage *language, TSSymbol symbol) { + TSSymbolMetadata metadata = ts_language_symbol_metadata(language, symbol); + if (metadata.named) { + return TSSymbolTypeRegular; + } else if (metadata.visible) { + return TSSymbolTypeAnonymous; + } else { + return TSSymbolTypeAuxiliary; + } +}