diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
| commit | 5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch) | |
| tree | b148c450939688caaaeb4adac6f2faa1eaffe649 /vendor/github.com/mitjafelicijan/go-tree-sitter/lua | |
| download | qwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz | |
Engage!
Diffstat (limited to 'vendor/github.com/mitjafelicijan/go-tree-sitter/lua')
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/lua/binding.go | 15 | ||||
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.c | bin | 0 -> 2060205 bytes | |||
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.h | 224 | ||||
| -rw-r--r-- | vendor/github.com/mitjafelicijan/go-tree-sitter/lua/scanner.c | 229 |
4 files changed, 468 insertions, 0 deletions
diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/binding.go b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/binding.go new file mode 100644 index 0000000..a85df82 --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/binding.go @@ -0,0 +1,15 @@ +package lua + +//#include "parser.h" +//TSLanguage *tree_sitter_lua(); +import "C" +import ( + "unsafe" + + sitter "github.com/mitjafelicijan/go-tree-sitter" +) + +func GetLanguage() *sitter.Language { + ptr := unsafe.Pointer(C.tree_sitter_lua()) + return sitter.NewLanguage(ptr) +} diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.c b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.c Binary files differnew file mode 100644 index 0000000..da6339c --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.c diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.h b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.h new file mode 100644 index 0000000..2b14ac1 --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/parser.h @@ -0,0 +1,224 @@ +#ifndef TREE_SITTER_PARSER_H_ +#define TREE_SITTER_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#define ts_builtin_sym_error ((TSSymbol)-1) +#define ts_builtin_sym_end 0 +#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 + +typedef uint16_t TSStateId; + +#ifndef TREE_SITTER_API_H_ +typedef uint16_t TSSymbol; +typedef uint16_t TSFieldId; +typedef struct TSLanguage TSLanguage; +#endif + +typedef struct { + TSFieldId field_id; + uint8_t child_index; + bool inherited; +} TSFieldMapEntry; + +typedef struct { + uint16_t index; + uint16_t length; +} TSFieldMapSlice; + +typedef struct { + bool visible; + bool named; + bool supertype; +} TSSymbolMetadata; + +typedef struct TSLexer TSLexer; + +struct TSLexer { + int32_t lookahead; + TSSymbol result_symbol; + void (*advance)(TSLexer *, bool); + void (*mark_end)(TSLexer *); + uint32_t (*get_column)(TSLexer *); + bool (*is_at_included_range_start)(const TSLexer *); + bool (*eof)(const TSLexer *); +}; + +typedef enum { + TSParseActionTypeShift, + TSParseActionTypeReduce, + TSParseActionTypeAccept, + TSParseActionTypeRecover, +} TSParseActionType; + +typedef union { + 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; +} TSParseAction; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; + +typedef union { + TSParseAction action; + struct { + uint8_t count; + bool reusable; + } entry; +} TSParseActionEntry; + +struct TSLanguage { + uint32_t version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + uint32_t state_count; + uint32_t large_state_count; + uint32_t production_id_count; + uint32_t field_count; + uint16_t max_alias_sequence_length; + const uint16_t *parse_table; + const uint16_t *small_parse_table; + const uint32_t *small_parse_table_map; + const TSParseActionEntry *parse_actions; + const char * const *symbol_names; + const char * const *field_names; + const TSFieldMapSlice *field_map_slices; + const TSFieldMapEntry *field_map_entries; + const TSSymbolMetadata *symbol_metadata; + const TSSymbol *public_symbol_map; + const uint16_t *alias_map; + const TSSymbol *alias_sequences; + const TSLexMode *lex_modes; + bool (*lex_fn)(TSLexer *, TSStateId); + bool (*keyword_lex_fn)(TSLexer *, TSStateId); + TSSymbol keyword_capture_token; + struct { + const bool *states; + const TSSymbol *symbol_map; + void *(*create)(void); + void (*destroy)(void *); + bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + unsigned (*serialize)(void *, char *); + void (*deserialize)(void *, const char *, unsigned); + } external_scanner; + const TSStateId *primary_state_ids; +}; + +/* + * Lexer Macros + */ + +#define START_LEXER() \ + bool result = false; \ + bool skip = false; \ + bool eof = false; \ + int32_t lookahead; \ + goto start; \ + next_state: \ + lexer->advance(lexer, skip); \ + start: \ + skip = false; \ + lookahead = lexer->lookahead; + +#define ADVANCE(state_value) \ + { \ + state = state_value; \ + goto next_state; \ + } + +#define SKIP(state_value) \ + { \ + skip = true; \ + state = state_value; \ + goto next_state; \ + } + +#define ACCEPT_TOKEN(symbol_value) \ + result = true; \ + lexer->result_symbol = symbol_value; \ + lexer->mark_end(lexer); + +#define END_STATE() return result; + +/* + * Parse Table Macros + */ + +#define SMALL_STATE(id) id - LARGE_STATE_COUNT + +#define STATE(id) id + +#define ACTIONS(id) id + +#define SHIFT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = state_value \ + } \ + }} + +#define SHIFT_REPEAT(state_value) \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .state = state_value, \ + .repetition = true \ + } \ + }} + +#define SHIFT_EXTRA() \ + {{ \ + .shift = { \ + .type = TSParseActionTypeShift, \ + .extra = true \ + } \ + }} + +#define REDUCE(symbol_val, child_count_val, ...) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_val, \ + .child_count = child_count_val, \ + __VA_ARGS__ \ + }, \ + }} + +#define RECOVER() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} + +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_ diff --git a/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/scanner.c b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/scanner.c new file mode 100644 index 0000000..516cbd4 --- /dev/null +++ b/vendor/github.com/mitjafelicijan/go-tree-sitter/lua/scanner.c @@ -0,0 +1,229 @@ +#include "parser.h" +#include <wctype.h> +#include <stdio.h> + +enum TokenType { + BLOCK_COMMENT_START, + BLOCK_COMMENT_CONTENT, + BLOCK_COMMENT_END, + + STRING_START, + STRING_CONTENT, + STRING_END, +}; + +static inline void consume(TSLexer *lexer) { lexer->advance(lexer, false); } +static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); } + +static inline bool consume_char(char c, TSLexer *lexer) { + if (lexer->lookahead != c) { + return false; + } + + consume(lexer); + return true; +} + +static inline uint8_t consume_and_count_char(char c, TSLexer *lexer) { + uint8_t count = 0; + while (lexer->lookahead == c) { + ++count; + consume(lexer); + } + return count; +} + +static inline void skip_whitespaces(TSLexer *lexer) { + while (iswspace(lexer->lookahead)) { + skip(lexer); + } +} + +void *tree_sitter_lua_external_scanner_create() { return NULL; } +void tree_sitter_lua_external_scanner_destroy(void *payload) {} + +char ending_char = 0; +uint8_t level_count = 0; + +static inline void reset_state() { + ending_char = 0; + level_count = 0; +} + +unsigned tree_sitter_lua_external_scanner_serialize(void *payload, char *buffer) { + buffer[0] = ending_char; + buffer[1] = level_count; + return 2; +} + +void tree_sitter_lua_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { + if (length == 0) return; + ending_char = buffer[0]; + if (length == 1) return; + level_count = buffer[1]; +} + +static bool scan_block_start(TSLexer *lexer) { + if (consume_char('[', lexer)) { + uint8_t level = consume_and_count_char('=', lexer); + + if (consume_char('[', lexer)) { + level_count = level; + return true; + } + } + + return false; +} + +static bool scan_block_end(TSLexer *lexer) { + if (consume_char(']', lexer)) { + uint8_t level = consume_and_count_char('=', lexer); + + if (level_count == level && consume_char(']', lexer)) { + return true; + } + } + + return false; +} + +static bool scan_block_content(TSLexer *lexer) { + while (lexer->lookahead != 0) { + if (lexer->lookahead == ']') { + lexer->mark_end(lexer); + + if (scan_block_end(lexer)) { + return true; + } + } else { + consume(lexer); + } + } + + return false; +} + +static bool scan_comment_start(TSLexer *lexer) { + if (consume_char('-', lexer) && consume_char('-', lexer)) { + lexer->mark_end(lexer); + + if (scan_block_start(lexer)) { + lexer->mark_end(lexer); + lexer->result_symbol = BLOCK_COMMENT_START; + return true; + } + } + + return false; +} + +static bool scan_comment_content(TSLexer *lexer) { + if (ending_char == 0) { // block comment + if (scan_block_content(lexer)) { + lexer->result_symbol = BLOCK_COMMENT_CONTENT; + return true; + } + + return false; + } + + while (lexer->lookahead != 0) { + if (lexer->lookahead == ending_char) { + reset_state(); + lexer->result_symbol = BLOCK_COMMENT_CONTENT; + return true; + } + + consume(lexer); + } + + return false; +} + +static bool scan_string_start(TSLexer *lexer) { + if (lexer->lookahead == '"' || lexer->lookahead == '\'') { + ending_char = lexer->lookahead; + consume(lexer); + return true; + } + + if (scan_block_start(lexer)) { + return true; + } + + return false; +} + +static bool scan_string_end(TSLexer *lexer) { + if (ending_char == 0) { // block string + return scan_block_end(lexer); + } + + if (consume_char(ending_char, lexer)) { + return true; + } + + return false; +} + +static bool scan_string_content(TSLexer *lexer) { + if (ending_char == 0) { // block string + return scan_block_content(lexer); + } + + while (lexer->lookahead != '\n' && lexer->lookahead != 0 && lexer->lookahead != ending_char) { + if (consume_char('\\', lexer) && consume_char('z', lexer)) { + while (iswspace(lexer->lookahead)) { + consume(lexer); + } + continue; + }; + + if (lexer->lookahead == 0) { + return true; + } + + consume(lexer); + } + + return true; +} + +bool tree_sitter_lua_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { + if (valid_symbols[STRING_END] && scan_string_end(lexer)) { + reset_state(); + lexer->result_symbol = STRING_END; + return true; + } + + if (valid_symbols[STRING_CONTENT] && scan_string_content(lexer)) { + lexer->result_symbol = STRING_CONTENT; + return true; + } + + if (valid_symbols[BLOCK_COMMENT_END] && ending_char == 0 && scan_block_end(lexer)) { + reset_state(); + lexer->result_symbol = BLOCK_COMMENT_END; + return true; + } + + if (valid_symbols[BLOCK_COMMENT_CONTENT] && scan_comment_content(lexer)) { + return true; + } + + skip_whitespaces(lexer); + + if (valid_symbols[STRING_START] && scan_string_start(lexer)) { + lexer->result_symbol = STRING_START; + return true; + } + + if (valid_symbols[BLOCK_COMMENT_START]) { + if (scan_comment_start(lexer)) { + return true; + } + } + + return false; +} |
