tree_sitter

Constant PARSER_HEADER

Source
pub const PARSER_HEADER: &str = "#ifndef TREE_SITTER_PARSER_H_\n#define TREE_SITTER_PARSER_H_\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <stdlib.h>\n\n#define ts_builtin_sym_error ((TSSymbol)-1)\n#define ts_builtin_sym_end 0\n#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024\n\n#ifndef TREE_SITTER_API_H_\ntypedef uint16_t TSStateId;\ntypedef uint16_t TSSymbol;\ntypedef uint16_t TSFieldId;\ntypedef struct TSLanguage TSLanguage;\n#endif\n\ntypedef struct {\n  TSFieldId field_id;\n  uint8_t child_index;\n  bool inherited;\n} TSFieldMapEntry;\n\ntypedef struct {\n  uint16_t index;\n  uint16_t length;\n} TSFieldMapSlice;\n\ntypedef struct {\n  bool visible;\n  bool named;\n  bool supertype;\n} TSSymbolMetadata;\n\ntypedef struct TSLexer TSLexer;\n\nstruct TSLexer {\n  int32_t lookahead;\n  TSSymbol result_symbol;\n  void (*advance)(TSLexer *, bool);\n  void (*mark_end)(TSLexer *);\n  uint32_t (*get_column)(TSLexer *);\n  bool (*is_at_included_range_start)(const TSLexer *);\n  bool (*eof)(const TSLexer *);\n  void (*log)(const TSLexer *, const char *, ...);\n};\n\ntypedef enum {\n  TSParseActionTypeShift,\n  TSParseActionTypeReduce,\n  TSParseActionTypeAccept,\n  TSParseActionTypeRecover,\n} TSParseActionType;\n\ntypedef union {\n  struct {\n    uint8_t type;\n    TSStateId state;\n    bool extra;\n    bool repetition;\n  } shift;\n  struct {\n    uint8_t type;\n    uint8_t child_count;\n    TSSymbol symbol;\n    int16_t dynamic_precedence;\n    uint16_t production_id;\n  } reduce;\n  uint8_t type;\n} TSParseAction;\n\ntypedef struct {\n  uint16_t lex_state;\n  uint16_t external_lex_state;\n} TSLexMode;\n\ntypedef union {\n  TSParseAction action;\n  struct {\n    uint8_t count;\n    bool reusable;\n  } entry;\n} TSParseActionEntry;\n\ntypedef struct {\n  int32_t start;\n  int32_t end;\n} TSCharacterRange;\n\nstruct TSLanguage {\n  uint32_t version;\n  uint32_t symbol_count;\n  uint32_t alias_count;\n  uint32_t token_count;\n  uint32_t external_token_count;\n  uint32_t state_count;\n  uint32_t large_state_count;\n  uint32_t production_id_count;\n  uint32_t field_count;\n  uint16_t max_alias_sequence_length;\n  const uint16_t *parse_table;\n  const uint16_t *small_parse_table;\n  const uint32_t *small_parse_table_map;\n  const TSParseActionEntry *parse_actions;\n  const char * const *symbol_names;\n  const char * const *field_names;\n  const TSFieldMapSlice *field_map_slices;\n  const TSFieldMapEntry *field_map_entries;\n  const TSSymbolMetadata *symbol_metadata;\n  const TSSymbol *public_symbol_map;\n  const uint16_t *alias_map;\n  const TSSymbol *alias_sequences;\n  const TSLexMode *lex_modes;\n  bool (*lex_fn)(TSLexer *, TSStateId);\n  bool (*keyword_lex_fn)(TSLexer *, TSStateId);\n  TSSymbol keyword_capture_token;\n  struct {\n    const bool *states;\n    const TSSymbol *symbol_map;\n    void *(*create)(void);\n    void (*destroy)(void *);\n    bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);\n    unsigned (*serialize)(void *, char *);\n    void (*deserialize)(void *, const char *, unsigned);\n  } external_scanner;\n  const TSStateId *primary_state_ids;\n};\n\nstatic inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {\n  uint32_t index = 0;\n  uint32_t size = len - index;\n  while (size > 1) {\n    uint32_t half_size = size / 2;\n    uint32_t mid_index = index + half_size;\n    TSCharacterRange *range = &ranges[mid_index];\n    if (lookahead >= range->start && lookahead <= range->end) {\n      return true;\n    } else if (lookahead > range->end) {\n      index = mid_index;\n    }\n    size -= half_size;\n  }\n  TSCharacterRange *range = &ranges[index];\n  return (lookahead >= range->start && lookahead <= range->end);\n}\n\n/*\n *  Lexer Macros\n */\n\n#ifdef _MSC_VER\n#define UNUSED __pragma(warning(suppress : 4101))\n#else\n#define UNUSED __attribute__((unused))\n#endif\n\n#define START_LEXER()           \\\n  bool result = false;          \\\n  bool skip = false;            \\\n  UNUSED                        \\\n  bool eof = false;             \\\n  int32_t lookahead;            \\\n  goto start;                   \\\n  next_state:                   \\\n  lexer->advance(lexer, skip);  \\\n  start:                        \\\n  skip = false;                 \\\n  lookahead = lexer->lookahead;\n\n#define ADVANCE(state_value) \\\n  {                          \\\n    state = state_value;     \\\n    goto next_state;         \\\n  }\n\n#define ADVANCE_MAP(...)                                              \\\n  {                                                                   \\\n    static const uint16_t map[] = { __VA_ARGS__ };                    \\\n    for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) {  \\\n      if (map[i] == lookahead) {                                      \\\n        state = map[i + 1];                                           \\\n        goto next_state;                                              \\\n      }                                                               \\\n    }                                                                 \\\n  }\n\n#define SKIP(state_value) \\\n  {                       \\\n    skip = true;          \\\n    state = state_value;  \\\n    goto next_state;      \\\n  }\n\n#define ACCEPT_TOKEN(symbol_value)     \\\n  result = true;                       \\\n  lexer->result_symbol = symbol_value; \\\n  lexer->mark_end(lexer);\n\n#define END_STATE() return result;\n\n/*\n *  Parse Table Macros\n */\n\n#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)\n\n#define STATE(id) id\n\n#define ACTIONS(id) id\n\n#define SHIFT(state_value)            \\\n  {{                                  \\\n    .shift = {                        \\\n      .type = TSParseActionTypeShift, \\\n      .state = (state_value)          \\\n    }                                 \\\n  }}\n\n#define SHIFT_REPEAT(state_value)     \\\n  {{                                  \\\n    .shift = {                        \\\n      .type = TSParseActionTypeShift, \\\n      .state = (state_value),         \\\n      .repetition = true              \\\n    }                                 \\\n  }}\n\n#define SHIFT_EXTRA()                 \\\n  {{                                  \\\n    .shift = {                        \\\n      .type = TSParseActionTypeShift, \\\n      .extra = true                   \\\n    }                                 \\\n  }}\n\n#define REDUCE(symbol_name, children, precedence, prod_id) \\\n  {{                                                       \\\n    .reduce = {                                            \\\n      .type = TSParseActionTypeReduce,                     \\\n      .symbol = symbol_name,                               \\\n      .child_count = children,                             \\\n      .dynamic_precedence = precedence,                    \\\n      .production_id = prod_id                             \\\n    },                                                     \\\n  }}\n\n#define RECOVER()                    \\\n  {{                                 \\\n    .type = TSParseActionTypeRecover \\\n  }}\n\n#define ACCEPT_INPUT()              \\\n  {{                                \\\n    .type = TSParseActionTypeAccept \\\n  }}\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif  // TREE_SITTER_PARSER_H_\n";