/
CustomListener.js
34 lines (29 loc) · 1.01 KB
/
CustomListener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var JSONListener = require('./JSONListener').JSONListener,
_ = require("underscore");
Listener = function () {
JSONListener.call(this); // inherit default listener
return this;
};
//you could use this.output to build up a new JSON object
this.output = "";
// inherit default listener
Listener.prototype = Object.create(JSONListener.prototype);
Listener.prototype.constructor = Listener;
function funkyThingWithAtSymbol(str) {
if (str.charAt(0) === str.charAt(0).toUpperCase()) {
str = str.replace('"',''); //str has quotes lets remove em first
return '"@' + str + '"';
}
return str;
}
Listener.prototype.exitPair = function (ctx) {
//see JSON.g4 a pair has a string and a value
//console.log(ctx.STRING().getText());
//console.log(ctx.value().getText());
//just a simple example
this.output = `${ctx.STRING().getText()}:${ctx.value().getText()}`
};
Listener.prototype.exitJson = function (ctx) {
//console.log(ctx.object().getText());
};
module.exports = Listener;