Add custom JSON serializers for tokens that include a type attribute

This commit is contained in:
Gabriel Wicke 2012-02-03 13:09:01 +00:00
parent 61dae35ebc
commit 26f2026cff
Notes: Gabriel Wicke 2012-02-27 16:40:01 +00:00

View file

@ -8,26 +8,63 @@ function TagTk( name, attribs ) {
this.attribs = attribs || []; this.attribs = attribs || [];
} }
TagTk.prototype.toJSON = function () {
return {
type: 'TagTk',
name: this.name,
attribs: this.attribs
};
};
function EndTagTk( name, attribs ) { function EndTagTk( name, attribs ) {
//this.type = 'ENDTAG'; //this.type = 'ENDTAG';
this.name = name; this.name = name;
this.attribs = attribs || []; this.attribs = attribs || [];
} }
EndTagTk.prototype.toJSON = function () {
return {
type: 'EndTagTk',
name: this.name,
attribs: this.attribs
};
};
function SelfclosingTagTk( name, attribs ) { function SelfclosingTagTk( name, attribs ) {
//this.type = 'SELFCLOSINGTAG'; //this.type = 'SELFCLOSINGTAG';
this.name = name; this.name = name;
this.attribs = attribs || []; this.attribs = attribs || [];
} }
SelfclosingTagTk.prototype.toJSON = function () {
return {
type: 'SelfclosingTagTk',
name: this.name,
attribs: this.attribs
};
};
function NlTk( ) { function NlTk( ) {
//this.type = 'NEWLINE'; //this.type = 'NEWLINE';
} }
NlTk.prototype.toJSON = function () {
return { type: 'NlTk' };
};
function CommentTk( value ) { function CommentTk( value ) {
this.type = 'COMMENT'; this.type = 'COMMENT';
this.value = value; this.value = value;
} }
CommentTk.prototype.toJSON = function () {
return {
type: 'COMMENT',
value: this.value
};
};
function EOFTk( ) { function EOFTk( ) {
this.type = 'END'; this.type = 'END';
} }
EOFTk.prototype.toJSON = function () {
return { type: 'EOFTk' };
};
// A key-value pair // A key-value pair
function KV ( k, v ) { function KV ( k, v ) {