Sha256: 2cde46dd68bb95ac52be374a2783368a8d45dc1018a01122e31e57de0306d1ca

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

#include "fancy_parser.h"
#include "ruby.h"
#include "lexer.h"


static VALUE
parse_string(VALUE self, VALUE code) {
  VALUE lineno = rb_funcall(self, rb_intern("lineno"), 0);
  char *str = StringValueCStr(code);
  YY_BUFFER_STATE buffstate = yy_scan_string(str);
  yy_switch_to_buffer(buffstate);
  yylineno = NUM2INT(lineno);
  yyparse(self);
  yy_delete_buffer(buffstate);
  return self;
}

static VALUE
parse_file(VALUE self) {
  VALUE filename = rb_funcall(self, rb_intern("filename"), 0);
  VALUE lineno = rb_funcall(self, rb_intern("lineno"), 0);
  char *str = StringValueCStr(filename);
  FILE *f = fopen(str, "r");
  if(!f) {
    rb_funcall(self, rb_intern("file_error"), 2, rb_str_new2("Could not open file"), rb_str_new2(str));
    return Qnil;
  }
  YY_BUFFER_STATE buffstate = yy_create_buffer(f, YY_BUF_SIZE);
  yy_switch_to_buffer(buffstate);
  yylineno = NUM2INT(lineno);
  yyparse(self);
  yy_delete_buffer(buffstate);
  return self;
}

void
Init_fancy_parser() {
  VALUE ext = rb_funcall(rb_cModule, rb_intern("new"), 0);
  rb_define_method(ext, "parse_string", parse_string, 1);
  rb_define_method(ext, "parse_file", parse_file, 0);
  VALUE fancy = rb_const_get(rb_cObject, rb_intern("Fancy"));
  VALUE parser = rb_const_get(fancy, rb_intern("Parser"));
  rb_funcall(parser, rb_intern("include"), 1, ext);
}


Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fancy-0.7.0 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.6.0 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.5.0 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.4.0 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.3.3 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.3.2 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.3.1 boot/rbx-compiler/parser/fancy_parser.c
fancy-0.3.0 boot/rbx-compiler/parser/fancy_parser.c