Permalink
Browse files

Add new parser implementation

  • Loading branch information...
0xfeedface committed Nov 9, 2013
1 parent 535d192 commit f1e1a0273ce544e868fc71f5c6b7fff3d1527c8b
Showing with 1,140 additions and 1,469 deletions.
  1. +3 −0 .lldbinit
  2. +30 −14 binding.gyp
  3. +55 −28 index.js
  4. +7 −10 src/bindings.cc
  5. +52 −0 src/message.cc
  6. +37 −0 src/message.h
  7. +36 −0 src/namespace.h
  8. +50 −505 src/parser.cc
  9. +61 −55 src/parser.h
  10. +249 −0 src/parser_wrapper.cc
  11. +42 −0 src/parser_wrapper.h
  12. +0 −366 src/serializer.cc
  13. +0 −66 src/serializer.h
  14. +149 −306 src/statement.cc
  15. +55 −15 src/statement.h
  16. +130 −0 src/statement_wrapper.cc
  17. +37 −0 src/statement_wrapper.h
  18. +0 −51 src/statics.h
  19. +26 −0 src/uri.cc
  20. +35 −0 src/uri.h
  21. +50 −0 src/world.cc
  22. +36 −0 src/world.h
  23. +0 −53 src/wscript
View
@@ -0,0 +1,3 @@
target create node
breakpoint set --file parser_wrapper.h --line 35
process launch examples/stream.js
View
@@ -1,20 +1,36 @@
{ "targets": [ {
"target_name": "bindings",
"variables": {
"target_name": "bindings",
"variables": {
"raptor_prefix": "/usr/local"
},
"include_dirs": [
},
"include_dirs": [
"<(raptor_prefix)/include/raptor2"
],
"sources": [
],
"sources": [
"src/bindings.cc",
"src/parser.cc",
"src/serializer.cc",
"src/statement.cc"
],
"link_settings": {
"src/parser_wrapper.cc",
"src/statement.cc",
"src/statement_wrapper.cc",
"src/uri.cc",
"src/world.cc",
"src/message.cc"
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-std=c++11", "-fno-exceptions" ],
"link_settings": {
"libraries": [ "-lraptor2" ]
}
}
]
}
},
"conditions": [ [
"OS=='mac'", {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"OTHER_CPLUSPLUSFLAGS": [
"-std=c++11",
"-stdlib=libc++",
"-mmacosx-version-min=10.7"
]
}
}
] ]
} ] }
View
@@ -1,37 +1,64 @@
var events = require('events'),
util = require('util'),
bindings = require(__dirname + '/build/Release/bindings');
var stream = require('stream'),
bindings;
function inherits(target, source) {
for (var key in source.prototype) {
target[key] = source.prototype[key];
}
}
bindings = require(__dirname + '/build/Release/bindings');
// bindings = require(__dirname + '/build/Debug/bindings');
exports.newParser = function (mimeType, cb) {
if (undefined === cb) {
var parser = bindings.newParser(mimeType);
inherits(parser, events.EventEmitter);
return parser;
} else {
var res = bindings.newParser(mimeType, function (parser) {
inherits(parser, events.EventEmitter);
cb(parser);
});
}
exports.createParser = function (syntax) {
syntax = syntax || 'guess';
var parser = new bindings.Parser(syntax);
return new StreamParser(parser);
};
function StreamParser(parser) {
stream.Transform.call(this);
this._parser = parser;
this._started = false;
var self = this;
this._parser.setStatementHandler(function (statement) {
self.emit('statement', statement);
});
this._parser.setNamespaceHandler(function (namespaceURI, prefix) {
self.emit('namespace', namespaceURI, prefix);
});
this._parser.setMessageHandler(function (type, message) {
self.emit('message', {
type: type,
text: message
});
});
}
StreamParser.prototype = Object.create(stream.Transform.prototype);
exports.newSerializer = function (mimeType) {
var serializer = null;
StreamParser.prototype.setBaseURI = function (baseURI) {
this._baseURI = baseURI;
return this;
};
if (undefined === mimeType) {
serializer = bindings.newSerializer();
} else {
serializer = bindings.newSerializer(mimeType);
StreamParser.prototype._transform = function (chunk, encoding, cb) {
try {
if (!this._started) {
if (!this._baseURI) {
throw RangeError('base URI not set');
}
this._parser.parseStart(this._baseURI);
this._started = true;
}
this._parser.parseBuffer(chunk);
} catch (e) {
this.emit('error', e);
}
cb();
};
inherits(serializer, events.EventEmitter);
return serializer;
StreamParser.prototype._flush = function (cb) {
try {
this._parser.parseEnd();
} catch (e) {
this.emit('error', e);
}
this.emit('end');
cb();
};
View
@@ -1,5 +1,5 @@
/*
* Copyright 2010 Norman Heino <norman.heino@gmail.com>
* Copyright 2010–2013 Norman Heino <norman.heino@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,17 +14,14 @@
* limitations under the License.
*/
#include <v8.h>
#include <node.h>
#include "parser.h"
#include "serializer.h"
#include "parser_wrapper.h"
using namespace v8;
using namespace node;
void Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "newParser", Parser::Initialize);
NODE_SET_METHOD(target, "newSerializer", Serializer::Initialize);
// Node module initializer
void InitModule(v8::Handle<v8::Object> exports) {
ParserWrapper::Initialize(exports);
}
NODE_MODULE(bindings, Initialize);
NODE_MODULE(bindings, InitModule)
View
@@ -0,0 +1,52 @@
/*
* Copyright 2010–2013 Norman Heino <norman.heino@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sstream>
#include "message.h"
std::string Message::kMessageTypeNone = "";
std::string Message::kMessageTypeDebug = "debug";
std::string Message::kMessageTypeInfo = "info";
std::string Message::kMessageTypeWarning = "warning";
std::string Message::kMessageTypeError = "error";
std::string Message::kMessageTypeFatal = "fatal";
Message::Message(raptor_log_message const* message)
: type_(kMessageTypeNone)
{
switch (message->level) {
case RAPTOR_LOG_LEVEL_NONE:
// already set to none
break;
case RAPTOR_LOG_LEVEL_DEBUG:
type_ = kMessageTypeDebug;
break;
case RAPTOR_LOG_LEVEL_INFO:
type_ = kMessageTypeInfo;
break;
case RAPTOR_LOG_LEVEL_WARN:
type_ = kMessageTypeWarning;
break;
case RAPTOR_LOG_LEVEL_ERROR:
type_ = kMessageTypeError;
break;
case RAPTOR_LOG_LEVEL_FATAL:
type_ = kMessageTypeFatal;
break;
}
text_ = std::string(message->text);
}
View
@@ -0,0 +1,37 @@
/*
* Copyright 2010–2013 Norman Heino <norman.heino@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <raptor.h>
class Message {
public:
explicit Message(raptor_log_message const* message);
std::string const& type() const { return type_; }
std::string const& text() const { return text_; }
private:
static std::string kMessageTypeNone;
static std::string kMessageTypeDebug;
static std::string kMessageTypeInfo;
static std::string kMessageTypeWarning;
static std::string kMessageTypeError;
static std::string kMessageTypeFatal;
std::string& type_;
std::string text_;
};
View
@@ -0,0 +1,36 @@
/*
* Copyright 2010–2013 Norman Heino <norman.heino@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <raptor.h>
#include "uri.h"
class Namespace {
public:
explicit Namespace(raptor_namespace const* ns)
: URI_(raptor_namespace_get_uri(ns)),
prefix_(reinterpret_cast<const char*>(raptor_namespace_get_prefix(ns))) {}
std::string URI() const {
return URI_;
}
std::string const& prefix() const {
return prefix_;
}
private:
class URI URI_;
std::string prefix_;
};
Oops, something went wrong.

0 comments on commit f1e1a02

Please sign in to comment.