feat: add Honey syntax highlighting
This commit is contained in:
Generated
+9
@@ -1806,6 +1806,14 @@ dependencies = [
|
||||
"tree-sitter-language",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-honey"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"tree-sitter-language",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-html"
|
||||
version = "0.23.2"
|
||||
@@ -2008,6 +2016,7 @@ dependencies = [
|
||||
"tree-sitter-cpp",
|
||||
"tree-sitter-css",
|
||||
"tree-sitter-go",
|
||||
"tree-sitter-honey",
|
||||
"tree-sitter-html",
|
||||
"tree-sitter-javascript",
|
||||
"tree-sitter-json",
|
||||
|
||||
@@ -18,6 +18,7 @@ tree-sitter-cpp = "0.23.4"
|
||||
tree-sitter-css = "0.25.0"
|
||||
tree-sitter-go = "0.25.0"
|
||||
tree-sitter-html = "0.23.2"
|
||||
tree-sitter-honey = { path = "vendor/tree-sitter-honey" }
|
||||
tree-sitter-javascript = "0.25.0"
|
||||
tree-sitter-json = "0.24.8"
|
||||
tree-sitter-make = "1.1.1"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
- [x] syntax highlighting for Honey (honeylang)
|
||||
- honeylang treesitter project located at `/Users/valdemar/Developer/Personal/Languages/tree-sitter-honey`.
|
||||
- [ ] diff view: GitHub code review integration after the local review UX is usable.
|
||||
- publish local reviews explicitly: general PR comments, inline line/range comments, review summaries, approval, and requests for changes.
|
||||
- preserve explicit PR identity and reviewed commit IDs; validate anchors against GitHub's PR diff and recheck the PR head before submission.
|
||||
|
||||
@@ -21,6 +21,8 @@ rubocop
|
||||
|
||||
The default workspace member is the editor. `vendor/crossterm` is included to test its minimal DEC 2031 notification decoder patch; the rest of its source retains upstream formatting. The decoder checks cover fragmented reports and keyboard recovery, and its doctests verify the added event does not break upstream examples.
|
||||
|
||||
`vendor/tree-sitter-honey` contains a minimal Rust binding plus the unchanged generated parser, parser header, and highlight query from [`valdemar/tree-sitter-honey`](https://github.com/valdemar/tree-sitter-honey), revision `10f1ff746fe57736ae7d7c8c402f7b265680b26c` (MIT). Builds do not depend on a sibling checkout or an installed Tree-sitter CLI. To update, copy `src/parser.c`, `src/tree_sitter/parser.h`, and `queries/highlights.scm` from the same grammar revision, update the revision recorded here, and run `cargo test --lib syntax::tests`.
|
||||
|
||||
## Ruby types
|
||||
|
||||
Use YARD `@param`, `@return`, and `@yieldparam` annotations for Ruby APIs, and `@type` for locals where inference needs help. Examples annotate DSL block parameters before the call, without adding runtime assignments or dependencies. `Vamp::Action` / `Vamp::Mode` field types and the dynamically defined mode methods use Solargraph-supported directives.
|
||||
|
||||
+3
-1
@@ -588,10 +588,12 @@ config.bind "leader f", config.core.follow_link
|
||||
|
||||
## Syntax highlighting
|
||||
|
||||
Buffers highlight automatically using [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and compiled-in grammar/query packages. The selected language set is Rust, Ruby, Python, JSON, Bash, Makefile, Markdown, JavaScript/JSX, TypeScript/TSX, HTML, CSS, YAML, TOML, C, C++, Go, and Zig (`.zig`). Detection uses filename/extension or the in-memory first-line shebang, including common special filenames such as Makefile, Gemfile, and Cargo.lock; no file reread occurs. Unsupported formats use the normal foreground. The detected language appears in status, and save-as redetects it.
|
||||
Buffers highlight automatically using [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and compiled-in grammar/query packages. The selected language set is Rust, Ruby, Python, JSON, Bash, Makefile, Markdown, JavaScript/JSX, TypeScript/TSX, HTML, CSS, YAML, TOML, C, C++, Go, Zig (`.zig`), and Honey (`.hon`). Detection uses filename/extension or the in-memory first-line shebang, including common special filenames such as Makefile, Gemfile, and Cargo.lock; no file reread occurs. Unsupported formats use the normal foreground. The detected language appears in status, and save-as redetects it.
|
||||
|
||||
Colors retain the terminal palette: comments dark gray, strings green, keywords magenta, numbers yellow, types/markup cyan, and functions light blue. Grammar queries handle multiline/nested constructs, even when their opening is above the viewport. Markdown uses its inline grammar and named fenced-code injections; HTML script/style content uses JavaScript/CSS. Known tagged-template and raw-string injections use the same selected grammar registry; unknown injected languages retain host highlighting or plain text. Highlighting styles whole graphemes and expanded tab cells; partially clipped wide placeholders remain unchanged. Search, Visual selections, and secondary carets retain foreground/background precedence.
|
||||
|
||||
Honey uses its bundled grammar and highlight queries, including declarations, primitive types, literals, and comments. Markdown fences accept `honey`, `honeylang`, or `hon`; the language ID is `honey`.
|
||||
|
||||
Markdown heading markers (`#` through `######`, or Setext underlines) share the heading text's markup color. List markers (`-`, `+`, `*`, and ordered prefixes such as `1.` or `1)`) also use cyan markup, including nested and blockquoted lists. Plain-text hashes and other punctuation keep their existing styling.
|
||||
|
||||
An enabled supporting LSP server supplies semantic tokens automatically, overriding syntax colors only on recognized spans. Semantic colors also use the terminal palette: namespaces neutral gray, types cyan, variables/parameters light cyan, and properties blue. Readonly variables/parameters/properties keep those role colors and add italics; declarations/definitions are bold, documentation comments italic, and deprecated symbols struck through. Italic emphasis depends on terminal support. Edits retain semantic colors outside the changed range and shift them with the text until updated tokens arrive, avoiding whole-buffer flashes. Tree-sitter fills gaps, including edited ranges whose semantic tokens were discarded. Search, Visual selections, diagnostics, and carets keep their existing precedence. See [native LSP configuration](configuration.md#native-lsp) for provider support and server-stack routing.
|
||||
|
||||
+12
-1
@@ -118,7 +118,7 @@ fn spec(
|
||||
}
|
||||
}
|
||||
|
||||
static LANGUAGES: LazyLock<[LanguageSpec; 19]> = LazyLock::new(|| {
|
||||
static LANGUAGES: LazyLock<[LanguageSpec; 20]> = LazyLock::new(|| {
|
||||
[
|
||||
spec(
|
||||
super::RUST_ID,
|
||||
@@ -272,6 +272,14 @@ static LANGUAGES: LazyLock<[LanguageSpec; 19]> = LazyLock::new(|| {
|
||||
tree_sitter_zig::INJECTIONS_QUERY,
|
||||
"",
|
||||
),
|
||||
spec(
|
||||
"honey",
|
||||
"Honey",
|
||||
tree_sitter_honey::LANGUAGE.into(),
|
||||
tree_sitter_honey::HIGHLIGHTS_QUERY,
|
||||
"",
|
||||
"",
|
||||
),
|
||||
]
|
||||
});
|
||||
|
||||
@@ -310,6 +318,8 @@ pub(super) fn by_name(name: &str) -> Option<&'static LanguageSpec> {
|
||||
("cpp", "C++"),
|
||||
("cxx", "C++"),
|
||||
("golang", "Go"),
|
||||
("hon", "Honey"),
|
||||
("honeylang", "Honey"),
|
||||
];
|
||||
let name = ALIASES
|
||||
.iter()
|
||||
@@ -365,6 +375,7 @@ fn detect_path(path: &Path) -> Option<&'static LanguageSpec> {
|
||||
| "tpp" => "C++",
|
||||
"go" => "Go",
|
||||
"zig" => "Zig",
|
||||
"hon" => "Honey",
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,6 +607,47 @@ pub fn main() void {
|
||||
assert_eq!(kind_at(&cache, 3, local), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn honey_highlights_declarations_literals_edits_and_markdown_fences() {
|
||||
let source = "Point :: struct { x f64 }\n\
|
||||
add proc(a, b i32) i32 {\n\
|
||||
text := \"hello é\"\n\
|
||||
enabled := true\n\
|
||||
value := 42\n\
|
||||
# note\n\
|
||||
return a + b\n\
|
||||
}";
|
||||
let mut cache = self::cache(source, "main.hon");
|
||||
assert_eq!(cache.language(), Some("Honey"));
|
||||
assert!(!cache.tree.as_ref().unwrap().root_node().has_error());
|
||||
for (row, token, kind) in [
|
||||
(0, "Point", SyntaxKind::Type),
|
||||
(0, "struct", SyntaxKind::Keyword),
|
||||
(0, "f64", SyntaxKind::Type),
|
||||
(1, "add", SyntaxKind::Function),
|
||||
(1, "proc", SyntaxKind::Keyword),
|
||||
(1, "i32", SyntaxKind::Type),
|
||||
(2, "hello é", SyntaxKind::String),
|
||||
(3, "true", SyntaxKind::Keyword),
|
||||
(4, "42", SyntaxKind::Number),
|
||||
(5, "note", SyntaxKind::Comment),
|
||||
(6, "return", SyntaxKind::Keyword),
|
||||
] {
|
||||
assert_token(&cache, source, row, token, kind);
|
||||
}
|
||||
assert_eq!(kind_at(&cache, 6, 7), None);
|
||||
let changed = source.replace("\"hello é\"", "7");
|
||||
cache.update(&lines(&changed), Some(Path::new("main.hon")), 1);
|
||||
assert_token(&cache, &changed, 2, "7", SyntaxKind::Number);
|
||||
assert_fresh(&cache, &changed, "main.hon");
|
||||
for tag in ["honey", "honeylang", "hon"] {
|
||||
let markdown = format!("```{tag}\n{source}\n```");
|
||||
let injected = self::cache(&markdown, "README.md");
|
||||
assert_token(&injected, &markdown, 2, "add", SyntaxKind::Function);
|
||||
assert_token(&injected, &markdown, 3, "hello é", SyntaxKind::String);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filenames_shebang_save_as_and_tsx_use_actual_grammar_identity() {
|
||||
let source = lines("\u{feff}#!/usr/bin/env python3\nreturn 42");
|
||||
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "tree-sitter-honey"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
description = "Tree-sitter grammar for the Honey programming language"
|
||||
repository = "https://github.com/valdemar/tree-sitter-honey"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter-language = "0.1"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1"
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=src/parser.c");
|
||||
println!("cargo:rerun-if-changed=src/tree_sitter/parser.h");
|
||||
cc::Build::new()
|
||||
.include("src")
|
||||
.file("src/parser.c")
|
||||
.std("c11")
|
||||
.warnings(false)
|
||||
.compile("tree-sitter-honey");
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
; Broad defaults; specific contexts below override them.
|
||||
(identifier) @variable
|
||||
|
||||
; Comments and literals
|
||||
(comment) @comment
|
||||
(string_literal) @string
|
||||
(multiline_string_literal) @string
|
||||
(character_literal) @string.special
|
||||
(integer_literal) @number
|
||||
(float_literal) @number
|
||||
(boolean_literal) @boolean
|
||||
(null_literal) @constant.builtin
|
||||
(undefined_literal) @constant.builtin
|
||||
(unreachable_literal) @keyword
|
||||
|
||||
; Declarations
|
||||
(function_declaration name: (identifier) @function)
|
||||
(test_declaration name: (identifier) @function)
|
||||
(record_declaration name: (identifier) @type)
|
||||
(enum_declaration name: (identifier) @type)
|
||||
(opaque_declaration name: (identifier) @type)
|
||||
(distinct_declaration name: (identifier) @type)
|
||||
(alias_declaration name: (identifier) @type)
|
||||
(binding_declaration name: (identifier) @variable)
|
||||
(binding_declaration name: (identifier) @constant operator: "::")
|
||||
(parameter_group name: (identifier) @variable.parameter)
|
||||
(parameter_group "$" . name: (identifier) @constant)
|
||||
(parameter_group "$" @attribute)
|
||||
(comptime_block "$" @attribute)
|
||||
(conditional_capture name: (identifier) @variable.parameter)
|
||||
(loop_capture item: (identifier) @variable.parameter)
|
||||
(loop_capture index: (identifier) @variable.parameter)
|
||||
(match_capture name: (identifier) @variable.parameter)
|
||||
(inline_match_capture value: (identifier) @variable.parameter)
|
||||
(inline_match_capture tag: (identifier) @variable.parameter)
|
||||
(capture_list (identifier) @variable.parameter)
|
||||
(record_field name: (member_name) @property)
|
||||
(enum_member name: (member_name) @constant)
|
||||
(import_declaration alias: (identifier) @constant @module)
|
||||
|
||||
; Types
|
||||
(primitive_type) @type.builtin
|
||||
(type_identifier) @type
|
||||
(type_identifier (identifier) @type)
|
||||
(type_call function: (type_identifier) @type)
|
||||
(array_type length: (identifier) @constant)
|
||||
((type_call
|
||||
arguments: (argument_list
|
||||
(identifier) @type))
|
||||
(#match? @type "^[A-Z][A-Za-z0-9_]*$"))
|
||||
|
||||
; Expressions
|
||||
(call_expression function: (identifier) @function)
|
||||
(field_expression field: (member_name) @property)
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (member_name) @function))
|
||||
(field_expression field: (integer_literal) @property)
|
||||
(record_initializer name: (member_name) @property)
|
||||
(enum_literal name: (member_name) @constructor)
|
||||
|
||||
; Keywords
|
||||
[
|
||||
"test"
|
||||
"proc"
|
||||
"func"
|
||||
"c_func"
|
||||
"struct"
|
||||
"c_struct"
|
||||
"opaque"
|
||||
"union"
|
||||
"enum"
|
||||
"distinct"
|
||||
"alias"
|
||||
"import"
|
||||
"return"
|
||||
"try"
|
||||
"catch"
|
||||
"mut"
|
||||
"orelse"
|
||||
"and"
|
||||
"or"
|
||||
"xor"
|
||||
"if"
|
||||
"while"
|
||||
"for"
|
||||
"inline"
|
||||
"break"
|
||||
"continue"
|
||||
"defer"
|
||||
"errdefer"
|
||||
"yield"
|
||||
"match"
|
||||
"else"
|
||||
] @keyword
|
||||
|
||||
(visibility_modifier ["hide" "file" "package"] @attribute)
|
||||
|
||||
; Operators
|
||||
[
|
||||
"::"
|
||||
":="
|
||||
"="
|
||||
"+="
|
||||
"-="
|
||||
"*="
|
||||
"/="
|
||||
"&="
|
||||
"|="
|
||||
"xor="
|
||||
"<<="
|
||||
">>="
|
||||
"<<|="
|
||||
"+"
|
||||
"-"
|
||||
"*"
|
||||
"/"
|
||||
"=="
|
||||
"!="
|
||||
"<"
|
||||
"<="
|
||||
">"
|
||||
">="
|
||||
"&"
|
||||
"|"
|
||||
"<<"
|
||||
">>"
|
||||
"<<|"
|
||||
".."
|
||||
"..="
|
||||
"!"
|
||||
"~"
|
||||
"?"
|
||||
"^"
|
||||
"@"
|
||||
] @operator
|
||||
(visibility_modifier "@" @attribute)
|
||||
|
||||
; Punctuation
|
||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||
["," ":" ";" "."] @punctuation.delimiter
|
||||
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
use tree_sitter_language::LanguageFn;
|
||||
|
||||
unsafe extern "C" {
|
||||
fn tree_sitter_honey() -> *const ();
|
||||
}
|
||||
|
||||
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_honey) };
|
||||
pub const HIGHLIGHTS_QUERY: &str = include_str!("../queries/highlights.scm");
|
||||
+1525077
File diff suppressed because it is too large
Load Diff
+286
@@ -0,0 +1,286 @@
|
||||
#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
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSStateId;
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
typedef struct TSLanguageMetadata {
|
||||
uint8_t major_version;
|
||||
uint8_t minor_version;
|
||||
uint8_t patch_version;
|
||||
} TSLanguageMetadata;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
// Used to index the field and supertype maps.
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSMapSlice;
|
||||
|
||||
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 *);
|
||||
void (*log)(const TSLexer *, const char *, ...);
|
||||
};
|
||||
|
||||
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 struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
uint16_t reserved_word_set_id;
|
||||
} TSLexerMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
typedef struct {
|
||||
int32_t start;
|
||||
int32_t end;
|
||||
} TSCharacterRange;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t abi_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 TSMapSlice *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 TSLexerMode *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;
|
||||
const char *name;
|
||||
const TSSymbol *reserved_words;
|
||||
uint16_t max_reserved_word_set_size;
|
||||
uint32_t supertype_count;
|
||||
const TSSymbol *supertype_symbols;
|
||||
const TSMapSlice *supertype_map_slices;
|
||||
const TSSymbol *supertype_map_entries;
|
||||
TSLanguageMetadata metadata;
|
||||
};
|
||||
|
||||
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
|
||||
uint32_t index = 0;
|
||||
uint32_t size = len - index;
|
||||
while (size > 1) {
|
||||
uint32_t half_size = size / 2;
|
||||
uint32_t mid_index = index + half_size;
|
||||
const TSCharacterRange *range = &ranges[mid_index];
|
||||
if (lookahead >= range->start && lookahead <= range->end) {
|
||||
return true;
|
||||
} else if (lookahead > range->end) {
|
||||
index = mid_index;
|
||||
}
|
||||
size -= half_size;
|
||||
}
|
||||
const TSCharacterRange *range = &ranges[index];
|
||||
return (lookahead >= range->start && lookahead <= range->end);
|
||||
}
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define UNUSED __pragma(warning(suppress : 4101))
|
||||
#else
|
||||
#define UNUSED __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
UNUSED \
|
||||
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 ADVANCE_MAP(...) \
|
||||
{ \
|
||||
static const uint16_t map[] = { __VA_ARGS__ }; \
|
||||
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
|
||||
if (map[i] == lookahead) { \
|
||||
state = map[i + 1]; \
|
||||
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_name, children, precedence, prod_id) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_name, \
|
||||
.child_count = children, \
|
||||
.dynamic_precedence = precedence, \
|
||||
.production_id = prod_id \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
Reference in New Issue
Block a user