Sha256: 7085c6b4b78ea152771b00a60d8a59e7b706260eb83030ce8a05f5905cbdae41

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

#include <ruby.h>

extern char* parse(const char*);
extern char* format_error(const char*, const char*);

VALUE parse_internal(VALUE _instance, VALUE rb_code_string) {
  Check_Type(rb_code_string, T_STRING);
  char* code_string = StringValueCStr(rb_code_string);
  return rb_str_new2(parse(code_string));
}

VALUE format_error_internal(VALUE _instance, VALUE rb_filename, VALUE rb_error) {
  Check_Type(rb_filename, T_STRING);
  Check_Type(rb_error, T_STRING);

  char* filename = StringValueCStr(rb_filename);
  char* error = StringValueCStr(rb_error);

  return rb_str_new2(format_error(filename, error));
}

void Init_lit_parser(void) {
  VALUE root_module = rb_const_get(rb_cObject, rb_intern("LIT"));
  VALUE parser_module = rb_const_get(root_module, rb_intern("Parser"));

  rb_define_singleton_method(parser_module, "__parse_internal", parse_internal, 1);
  rb_define_singleton_method(parser_module, "__format_error_internal", format_error_internal, 2);
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
litl-parser-0.1.1 ext/lit/parser/lit_parser.c
litl-parser-0.1.0 ext/lit/parser/lit_parser.c