2012-02-01 17:03:08 +00:00
|
|
|
/**
|
|
|
|
* Constructors for different token types. Plain text is represented as simple
|
|
|
|
* strings or String objects (if attributes are needed).
|
|
|
|
*/
|
2012-02-13 17:02:23 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
var toString = function() { return JSON.stringify( this ); };
|
2012-02-13 17:02:23 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function TagTk( name, attribs, dataAttribs ) {
|
2012-02-01 18:37:48 +00:00
|
|
|
//this.type = 'TAG';
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
TagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
TagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'TagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
TagTk.prototype.constructor = TagTk;
|
|
|
|
TagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function EndTagTk( name, attribs, dataAttribs ) {
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
EndTagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
EndTagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'EndTagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
EndTagTk.prototype.constructor = EndTagTk;
|
|
|
|
EndTagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-03-13 12:32:31 +00:00
|
|
|
function SelfclosingTagTk( name, attribs, dataAttribs ) {
|
2012-02-01 18:37:48 +00:00
|
|
|
//this.type = 'SELFCLOSINGTAG';
|
2012-02-01 17:03:08 +00:00
|
|
|
this.name = name;
|
|
|
|
this.attribs = attribs || [];
|
2012-03-13 12:32:31 +00:00
|
|
|
this.dataAttribs = dataAttribs || {};
|
2012-02-01 17:03:08 +00:00
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
SelfclosingTagTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
SelfclosingTagTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'SelfclosingTagTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
SelfclosingTagTk.prototype.constructor = SelfclosingTagTk;
|
|
|
|
SelfclosingTagTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
function NlTk( ) {
|
|
|
|
//this.type = 'NEWLINE';
|
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
NlTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
NlTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'NlTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
NlTk.prototype.constructor = NlTk;
|
|
|
|
NlTk.prototype.toString = toString;
|
2012-02-03 13:09:01 +00:00
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
function CommentTk( value ) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
2012-03-13 12:32:31 +00:00
|
|
|
CommentTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
CommentTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'COMMENT' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
CommentTk.prototype.constructor = CommentTk;
|
|
|
|
CommentTk.prototype.toString = toString;
|
|
|
|
|
2012-03-07 20:06:54 +00:00
|
|
|
function EOFTk( ) { }
|
2012-03-13 12:32:31 +00:00
|
|
|
EOFTk.prototype = {};
|
2012-02-03 13:09:01 +00:00
|
|
|
EOFTk.prototype.toJSON = function () {
|
2012-02-06 19:12:29 +00:00
|
|
|
return $.extend( { type: 'EOFTk' }, this );
|
2012-02-03 13:09:01 +00:00
|
|
|
};
|
2012-02-13 17:02:23 +00:00
|
|
|
EOFTk.prototype.constructor = EOFTk;
|
|
|
|
EOFTk.prototype.toString = toString;
|
|
|
|
|
|
|
|
|
2012-02-01 17:03:08 +00:00
|
|
|
|
|
|
|
// A key-value pair
|
|
|
|
function KV ( k, v ) {
|
|
|
|
this.k = k;
|
|
|
|
this.v = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof module == "object") {
|
|
|
|
module.exports = {};
|
|
|
|
global.TagTk = TagTk;
|
|
|
|
global.EndTagTk = EndTagTk;
|
|
|
|
global.SelfclosingTagTk = SelfclosingTagTk;
|
|
|
|
global.NlTk = NlTk;
|
|
|
|
global.CommentTk = CommentTk;
|
|
|
|
global.EOFTk = EOFTk;
|
|
|
|
global.KV = KV;
|
|
|
|
}
|