-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
153 lines (145 loc) · 5.57 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*jshint esversion: 9 */
const { XQLint } = require('./lib/xqlint');
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 axios = require('axios');
var FormData = require('form-data');
var path = require('path');
/* return promise to make REx call and save result to file using parser obj properties */
async function rex(parser) {
var grammar = fs.readFileSync(parser.source);
var form = new FormData();
form.append('tz', parser.tz, { knownLength: Buffer.from(parser.tz).length, contentType: 'text/plain' });
form.append('command', parser.command, { knownLength: Buffer.from(parser.command).length, contentType: 'text/plain' });
form.append('input', grammar, { knownLength: Buffer.from(grammar).length, contentType: 'text/plain', filename: path.basename(parser.source) });
// Prepare additional headers for Axios, which include FormData's headers and the Content-Length
const headers = {
...form.getHeaders(),
'Content-Length': form.getLengthSync()
};
return new Promise(function (resolve, reject) {
var p = axios.post('https://www.bottlecaps.de/rex/', form, { headers });
p.then(function (response) {
fs.writeFileSync(parser.destination, response.data);
resolve("saved: " + parser.destination);
})
.catch(function (error) {
reject(error);
});
});
}
var promises = [];
this.data.grammars.forEach(function (parser) {
promises.push( rex(parser));
});
Promise.all(promises).then(function (r){
console.log("dONE",r);
});
console.log("SS");
});
grunt.registerMultiTask('index', 'Generate index xqdoc', function () {
var fs = require('fs');
grunt.file.expand(this.data.src).forEach(function (filename) {
var source = fs.readFileSync(filename, 'utf8');
console.log(filename);
var linter = new XQLint(source, { fileName: filename, styleCheck: false });
var xqdoc = linter.getXQDoc();
// Display the file content
console.log(xqdoc);
});
//console.log(this.target,this.data)
});
grunt.initConfig({
rex: {
parsers: {
grammars: [
{
source: 'lib/parsers/XQueryParser.ebnf',
destination: 'lib/parsers/XQueryParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '0',
}
]
},
lexers: {
grammars: [
{
source: 'lib/lexers/XQueryTokenizer.ebnf',
destination: 'lib/lexers/XQueryTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '0'
}
]
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'lib/**/*.js',
'test/**/*.js'
]
},
vows: {
all: {
//
options: {
verbose: true,
colors: true,
coverage: 'json',
reporter: 'dot-matrix',
},
// String or array of strings
// determining which files to include.
// This option is grunt's "full" file format.
src: ['test/*.js']
},
one: {
options: {
verbose: true,
colors: false,
coverage: 'json'
},
// String or array of strings
// determining which files to include.
// This option is grunt's "full" file format.
src: ['test/module_resolver_test.js']
//src: ['test/issue_test.js']
//src: ['test/stylecheck_test.js']
//src: ['test/function_test.js']
//src: ['test/variable_test.js']
//src: ['test/parser_test.js'] //26 fail
//src: ['test/completion_test.js'] //3 fail
//src: ['test/parser_test.js'] //26 fail
//src: ['test/issue_test.js'] //26 fail
},
},
browserify: {
browser_build: {
files: {
'build/xqlint.js': ['lib/xqlint.js'],
'build/xquery_lexer.js': ['lib/lexers/xquery_lexer.js']
},
options: {
standalone: ''
}
}
},
index: {
main: {
src: ['specs/xquery.lib/basex.org/*.xq?'],
dest: 'apb/index.js',
}
}
});
grunt.registerTask('browser_build', ['browserify:browser_build']);
grunt.registerTask('lexers', ['rex:lexers']);
grunt.registerTask('parsers', ['rex:parsers']);
grunt.registerTask('default', ['jshint', 'vows']);
};