forked from wcandillon/xqlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
119 lines (116 loc) · 4.06 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
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 FormData = require('form-data');
var path = require('path');
var Q = require('q');
var done = this.async();
var promises = [];
this.data.grammars.forEach(function(parser){
var deferred = Q.defer();
var grammar = fs.readFileSync(parser.source);
var form = new FormData();
form.append('tz', parser.tz, { knownLength: new Buffer(parser.tz).length, contentType: 'text/plain' });
form.append('command', parser.command, { knownLength: new Buffer(parser.command).length, contentType: 'text/plain' });
form.append('input', grammar, { knownLength : new Buffer(grammar).length, contentType: 'text/plain', filename: path.basename(parser.source) });
var length = form.getLengthSync();
var r = request.post('http://www.bottlecaps.de/rex/', function(err, res, body) {
if(err) {
deferred.reject(err);
} else {
fs.writeFileSync(parser.destination, body);
deferred.resolve();
}
});
r._form = form;
r.setHeader('content-length', length);
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',
tz: '-60',
},
{
source: 'lib/parsers/JSONiqParser.ebnf',
destination: 'lib/parsers/JSONiqParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '-60',
}
]
},
lexers: {
grammars: [
{
source: 'lib/lexers/XQueryTokenizer.ebnf',
destination: 'lib/lexers/XQueryTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '-60'
},
{
source: 'lib/lexers/JSONiqTokenizer.ebnf',
destination: 'lib/lexers/JSONiqTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '-60'
}
]
}
},
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']);
};