Module: BioSyntax::Native

Defined in:
ext/biosyntax/biosyntax_ext.c

Defined Under Namespace

Classes: State

Class Method Summary collapse

Class Method Details

.abi_versionObject



283
284
285
286
# File 'ext/biosyntax/biosyntax_ext.c', line 283

static VALUE native_abi_version(VALUE self) {
    (void)self;
    return UINT2NUM(biosyn_abi_version());
}

.format_id_from_name(name_value) ⇒ Object



288
289
290
291
292
293
294
295
# File 'ext/biosyntax/biosyntax_ext.c', line 288

static VALUE native_format_id_from_name(VALUE self, VALUE name_value) {
    VALUE name = StringValue(name_value);
    biosyn_format_t format_id;
    (void)self;

    format_id = biosyn_format_from_name(StringValueCStr(name));
    return UINT2NUM(format_id);
}

.formats_rawObject

Format and kind metadata are generated from libbiosyntax at load time, so the Ruby layer does not need to maintain parallel tables.



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'ext/biosyntax/biosyntax_ext.c', line 311

static VALUE native_formats_raw(VALUE self) {
    VALUE ary = rb_ary_new();
    uint32_t count = biosyn_format_count();
    uint32_t i;
    (void)self;

    for (i = 0; i < count; i++) {
        biosyn_format_info_t info;
        if (biosyn_format_info((biosyn_format_t)i, &info)) {
            VALUE h = rb_hash_new();
            rb_hash_aset(h, ID2SYM(rb_intern("id")), UINT2NUM(i));
            rb_hash_aset(h, ID2SYM(rb_intern("name")), str_or_nil(info.name));
            rb_hash_aset(h, ID2SYM(rb_intern("description")), str_or_nil(info.description));
            rb_hash_aset(h, ID2SYM(rb_intern("stateful")), info.stateful ? Qtrue : Qfalse);
            rb_ary_push(ary, rb_obj_freeze(h));
        }
    }

    return rb_obj_freeze(ary);
}

.guess_format_id(path_value) ⇒ Object



297
298
299
300
301
302
303
304
# File 'ext/biosyntax/biosyntax_ext.c', line 297

static VALUE native_guess_format_id(VALUE self, VALUE path_value) {
    VALUE path = StringValue(path_value);
    biosyn_format_t format_id;
    (void)self;

    format_id = biosyn_guess_format_from_path(StringValueCStr(path));
    return UINT2NUM(format_id);
}

.kinds_rawObject

Return raw token kind metadata for Ruby-side value objects.



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'ext/biosyntax/biosyntax_ext.c', line 333

static VALUE native_kinds_raw(VALUE self) {
    VALUE ary = rb_ary_new();
    uint32_t count = biosyn_class_count();
    uint32_t i;
    (void)self;

    for (i = 0; i < count; i++) {
        biosyn_class_info_t info;
        if (biosyn_class_info((biosyn_class_t)i, &info)) {
            VALUE h = rb_hash_new();
            rb_hash_aset(h, ID2SYM(rb_intern("id")), UINT2NUM(i));
            rb_hash_aset(h, ID2SYM(rb_intern("name")), str_or_nil(info.name));
            rb_hash_aset(h, ID2SYM(rb_intern("scope")), str_or_nil(info.scope));
            rb_hash_aset(h, ID2SYM(rb_intern("foreground")), str_or_nil(info.foreground));
            rb_hash_aset(h, ID2SYM(rb_intern("background")), str_or_nil(info.background));
            rb_hash_aset(h, ID2SYM(rb_intern("font_style")), str_or_nil(info.font_style));
            rb_hash_aset(h, ID2SYM(rb_intern("ansi_sgr")), str_or_nil(info.ansi_sgr));
            rb_ary_push(ary, rb_obj_freeze(h));
        }
    }

    return rb_obj_freeze(ary);
}

.libbiosyntax_versionObject



278
279
280
281
# File 'ext/biosyntax/biosyntax_ext.c', line 278

static VALUE native_libbiosyntax_version(VALUE self) {
    (void)self;
    return rb_str_new_cstr(biosyn_version());
}