Sha256: b656b3fc35c1ea251b0a222bb03b122a1cf1bd5c85c754300f8ff2f4a66c145a

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

#ifndef _IV_PHONIC_RPARSER_H_
#define _IV_PHONIC_RPARSER_H_
#include <cstdlib>
#include <cstring>
#include <tr1/type_traits>
#include <ruby.h>
#include <ruby/encoding.h>
#include <ruby/intern.h>
#include <iv/parser.h>
#include "encoding.h"
#include "factory.h"
#include "parser.h"
#include "creator.h"
#include "source.h"
namespace iv {
namespace phonic {

static VALUE cParseError;

class RParser {
 public:
  static VALUE Parse(VALUE self, VALUE rb_str) {
    AstFactory factory;
    Check_Type(rb_str, T_STRING);
    VALUE encoded_rb_str = rb_str_encode(rb_str,
                                         Encoding::UTF16Encoding(),
                                         0,
                                         Qnil);
    const char* str = StringValuePtr(encoded_rb_str);
    std::size_t len = RSTRING_LEN(encoded_rb_str);
    UTF16Source source(str, len);
    Parser parser(&source, &factory);
    FunctionLiteral* global = parser.ParseProgram();
    if (!global) {
      rb_raise(cParseError, "%s", parser.error().c_str());
    } else {
      Creator creator;
      return creator.Result(global);
    }
  }

  static void Init(VALUE mIVPhonic) {
    cParseError = rb_define_class_under(mIVPhonic, "ParseError", rb_eStandardError);
  }
};

} }  // namespace iv::phonic
#endif  // _IV_PHONIC_RPARSER_H_

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
iv-phonic-0.0.3 ext/iv/phonic/rparser.h
iv-phonic-0.0.2 ext/iv/phonic/rparser.h
iv-phonic-0.0.1 ext/iv/phonic/rparser.h