-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (30 loc) · 788 Bytes
/
index.js
File metadata and controls
34 lines (30 loc) · 788 Bytes
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 PEG = require('pegjs');
var fs = require('fs');
var path = require('path');
var comments = [];
function prepareForParse(str) {
return str.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/gm, function(match) {
comments.push(match);
return new Array(match.length + 1).join(' ');
});
}
var parser;
try {
parser = PEG.buildParser(fs.readFileSync(path.join(__dirname, 'nid.peg'), 'utf8'));
} catch(err) {
console.log(err);
process.exit(1);
}
module.exports = {
parse: function(input, options) {
options = options || {};
global.forNidParser = {
typeString: require('./typeString')
};
var out = parser.parse(prepareForParse(input));
if(options.includeComments)
out.comments = comments;
return out;
},
typeString: require('./typeString')
};