-
Notifications
You must be signed in to change notification settings - Fork 22
/
Gruntfile.js
120 lines (117 loc) · 3.75 KB
/
Gruntfile.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module.exports = function(grunt) {
'use strict';
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
require('time-grunt')(grunt);
grunt.registerMultiTask('rex', 'Generate Parsers', function(){
var fs = require('fs');
var request = require('request');
var Q = require('q');
var done = this.async();
var promises = [];
this.data.grammars.forEach(function(parser){
var deferred = Q.defer();
request(
{
method: 'POST',
url: 'https://bottlecaps.de/rex',
headers: {
'Content-Type': 'multipart/form-data'
},
formData : {
'input': fs.createReadStream(parser.source),
'command': parser.command,
'tz': new Date().getTimezoneOffset()
}
},
function(err, res, body) {
if(err) {
deferred.reject(err);
}
else {
fs.writeFileSync(parser.destination, body);
deferred.resolve();
}
}
);
promises.push(deferred.promise);
});
Q.all(promises)
.then(function(){
done();
})
.catch(function(error){
grunt.fail.fatal(error);
});
});
grunt.initConfig({
rex: {
parsers: {
grammars: [
{
source: 'lib/parsers/XQueryParser.ebnf',
destination: 'lib/parsers/XQueryParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint'
},
{
source: 'lib/parsers/JSONiqParser.ebnf',
destination: 'lib/parsers/JSONiqParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint'
}
]
},
lexers: {
grammars: [
{
source: 'lib/lexers/XQueryTokenizer.ebnf',
destination: 'lib/lexers/XQueryTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint'
},
{
source: 'lib/lexers/JSONiqTokenizer.ebnf',
destination: 'lib/lexers/JSONiqTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint'
}
]
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'lib/**/*.js',
'test/**/*.js'
]
},
vows: {
all: {
options: {
verbose: true,
colors: true,
coverage: 'json'
},
// String or array of strings
// determining which files to include.
// This option is grunt's "full" file format.
src: ['test/*.js', 'spec/*']
}
},
browserify: {
browser_build: {
files: {
'build/xqlint.js': ['lib/xqlint.js'],
'build/xquery_lexer.js': ['lib/lexers/xquery_lexer.js'],
'build/jsoniq_lexer.js': ['lib/lexers/jsoniq_lexer.js']
},
options: {
standalone: ''
}
}
}
});
grunt.registerTask('browser_build', ['browserify:browser_build']);
grunt.registerTask('lexers', ['rex:lexers']);
grunt.registerTask('parsers', ['rex:parsers']);
grunt.registerTask('default', ['jshint', 'vows']);
};