unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 4d274218ca995ff78c58042460cca0c2dd6c1aea 2146 bytes (raw)
name: src/tree-sitter-lang.in 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
#include <string.h>
#include <tree_sitter/parser.h>
#include "emacs-module.h"

int plugin_is_GPL_compatible;

extern TSLanguage *tree_sitter_LANG_C(void);

/* REF: http://diobla.info/blog-archive/modules-tut.html  */

/* Return a USER_PTR to the language definition.  */
static emacs_value
Ftree_sitter_language
(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
{
  TSLanguage *language = tree_sitter_LANG_C();
  return env->make_user_ptr (env, NULL, language);
}

/* Use this command to "dump" the file:
   xxd -i < grammar.js > parser.c.dump
 */
static emacs_value
Ftree_sitter_grammar
(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
{
  char grammar[] = {
#include "grammar.js.dump"
    , '\0' };
  return env->make_string (env, grammar, strlen(grammar));
}

/* Bind NAME to FUN.  */
static void
bind_function (emacs_env *env, const char *name, emacs_value Sfun)
{
  /* Set the function cell of the symbol named NAME to SFUN using
     the 'fset' function.  */

  /* Convert the strings to symbols by interning them.  */
  emacs_value Qfset = env->intern (env, "fset");
  emacs_value Qsym = env->intern (env, name);

  emacs_value args[] = { Qsym, Sfun };
  env->funcall (env, Qfset, 2, args);
}

/* Provide FEATURE to Emacs.  */
static void
provide (emacs_env *env, const char *feature)
{
  /* Call 'provide' with FEATURE converted to a symbol.  */
  emacs_value Qfeat = env->intern (env, feature);
  emacs_value Qprovide = env->intern (env, "provide");
  emacs_value args[] = { Qfeat };

  env->funcall (env, Qprovide, 1, args);
}

int
emacs_module_init (struct emacs_runtime *ert)
{
  emacs_env *env = ert->get_environment (ert);

  emacs_value lang = env->make_function
    (env, 0, 0, &Ftree_sitter_language,
     "Return a language object.", NULL);

    emacs_value grammar = env->make_function
      (env, 0, 0, &Ftree_sitter_grammar,
       "Return a language definition.", NULL);

  bind_function (env, "tree-sitter-LANG", lang);
  bind_function (env, "tree-sitter-LANG-grammar", grammar);
  provide (env, "tree-sitter-LANG");

  /* Return 0 to indicate module loaded successfully.  */
  return 0;
}

debug log:

solving 4d27421 ...
found 4d27421 in https://yhetil.org/guix-devel/87sfhvm927.fsf@encom.net/

applying [1/1] https://yhetil.org/guix-devel/87sfhvm927.fsf@encom.net/
diff --git a/src/tree-sitter-lang.in b/src/tree-sitter-lang.in
new file mode 100644
index 0000000..4d27421

Checking patch src/tree-sitter-lang.in...
Applied patch src/tree-sitter-lang.in cleanly.

index at:
100644 4d274218ca995ff78c58042460cca0c2dd6c1aea	src/tree-sitter-lang.in

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).