Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
535d192
commit f1e1a02
Showing
23 changed files
with
1,140 additions
and
1,469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
target create node | |||
breakpoint set --file parser_wrapper.h --line 35 | |||
process launch examples/stream.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,20 +1,36 @@ | |||
{ "targets": [ { | { "targets": [ { | ||
"target_name": "bindings", | "target_name": "bindings", | ||
"variables": { | "variables": { | ||
"raptor_prefix": "/usr/local" | "raptor_prefix": "/usr/local" | ||
}, | }, | ||
"include_dirs": [ | "include_dirs": [ | ||
"<(raptor_prefix)/include/raptor2" | "<(raptor_prefix)/include/raptor2" | ||
], | ], | ||
"sources": [ | "sources": [ | ||
"src/bindings.cc", | "src/bindings.cc", | ||
"src/parser.cc", | "src/parser.cc", | ||
"src/serializer.cc", | "src/parser_wrapper.cc", | ||
"src/statement.cc" | "src/statement.cc", | ||
], | "src/statement_wrapper.cc", | ||
"link_settings": { | "src/uri.cc", | ||
"src/world.cc", | |||
"src/message.cc" | |||
], | |||
"cflags!": [ "-fno-exceptions" ], | |||
"cflags_cc!": [ "-std=c++11", "-fno-exceptions" ], | |||
"link_settings": { | |||
"libraries": [ "-lraptor2" ] | "libraries": [ "-lraptor2" ] | ||
} | }, | ||
} | "conditions": [ [ | ||
] | "OS=='mac'", { | ||
} | "xcode_settings": { | ||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES", | |||
"OTHER_CPLUSPLUSFLAGS": [ | |||
"-std=c++11", | |||
"-stdlib=libc++", | |||
"-mmacosx-version-min=10.7" | |||
] | |||
} | |||
} | |||
] ] | |||
} ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,37 +1,64 @@ | |||
var events = require('events'), | var stream = require('stream'), | ||
util = require('util'), | bindings; | ||
bindings = require(__dirname + '/build/Release/bindings'); | |||
|
|
||
function inherits(target, source) { | bindings = require(__dirname + '/build/Release/bindings'); | ||
for (var key in source.prototype) { | // bindings = require(__dirname + '/build/Debug/bindings'); | ||
target[key] = source.prototype[key]; | |||
} | |||
} | |||
|
|
||
exports.newParser = function (mimeType, cb) { | exports.createParser = function (syntax) { | ||
if (undefined === cb) { | syntax = syntax || 'guess'; | ||
var parser = bindings.newParser(mimeType); | var parser = new bindings.Parser(syntax); | ||
inherits(parser, events.EventEmitter); | return new StreamParser(parser); | ||
return parser; | |||
} else { | |||
var res = bindings.newParser(mimeType, function (parser) { | |||
inherits(parser, events.EventEmitter); | |||
cb(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) { | StreamParser.prototype.setBaseURI = function (baseURI) { | ||
var serializer = null; | this._baseURI = baseURI; | ||
return this; | |||
}; | |||
|
|
||
if (undefined === mimeType) { | StreamParser.prototype._transform = function (chunk, encoding, cb) { | ||
serializer = bindings.newSerializer(); | try { | ||
} else { | if (!this._started) { | ||
serializer = bindings.newSerializer(mimeType); | 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); | StreamParser.prototype._flush = function (cb) { | ||
|
try { | ||
return serializer; | this._parser.parseEnd(); | ||
} catch (e) { | |||
this.emit('error', e); | |||
} | |||
this.emit('end'); | |||
cb(); | |||
}; | }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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_; | |||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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.