Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e088085

Browse files
committedSep 26, 2017
upgrade pegjs to 0.10.0, jasmine to 2.8.0, use umd
1 parent d1c58fb commit e088085

File tree

8 files changed

+688
-571
lines changed

8 files changed

+688
-571
lines changed
 

‎examples/browser/index.html‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!-- Load RequireJS -->
5-
<script type="text/javascript" src="../../vendor/require.js"></script>
4+
<!-- Load lucenequeryparser -->
5+
<script type="text/javascript" src="../../lib/lucene-query-parser.js"></script>
66
</head>
77
<body>
88
<h3>Query Text</h3>
@@ -23,22 +23,18 @@ <h3>Parser Output</h3>
2323

2424
<script type="text/javascript">
2525
function parse_query() {
26+
// get query text
27+
var query_text = document.getElementById('query_text').value;
2628

27-
require(['../../lib/lucene-query-parser.js'], function(parser) {
29+
// parse query
30+
var results = lucenequeryparser.parse(query_text);
2831

29-
// get query text
30-
var query_text = document.getElementById('query_text').value;
32+
// convert to pretty-printed JSON
33+
results = JSON.stringify(results, undefined, 2);
34+
results = results.replace(/\n/g, "<br>").replace(/[ ]/g, "&nbsp;");
3135

32-
// parse query
33-
var results = parser.parse(query_text);
34-
35-
// convert to pretty-printed JSON
36-
results = JSON.stringify(results, undefined, 2);
37-
results = results.replace(/\n/g, "<br>").replace(/[ ]/g, "&nbsp;");
38-
39-
// display results
40-
document.getElementById('parser_output').innerHTML = results
41-
});
36+
// display results
37+
document.getElementById('parser_output').innerHTML = results
4238
}
4339

4440
parse_query();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!-- Load RequireJS -->
5+
<script type="text/javascript" src="../../vendor/require.js"></script>
6+
</head>
7+
<body>
8+
<h3>Query Text</h3>
9+
<textarea
10+
id="query_text"
11+
placeholder="Enter query text here..."
12+
rows="4"
13+
cols="120"
14+
onkeyup="parse_query()"
15+
>title:"The Right Way" AND text:go</textarea>
16+
17+
<h3>Parser Output</h3>
18+
<hr />
19+
<p>
20+
<code id="parser_output">
21+
</code>
22+
</p>
23+
24+
<script type="text/javascript">
25+
function parse_query() {
26+
27+
require(['../../lib/lucene-query-parser.js'], function(lucenequeryparser) {
28+
29+
// get query text
30+
var query_text = document.getElementById('query_text').value;
31+
32+
// parse query
33+
var results = lucenequeryparser.parse(query_text);
34+
35+
// convert to pretty-printed JSON
36+
results = JSON.stringify(results, undefined, 2);
37+
results = results.replace(/\n/g, "<br>").replace(/[ ]/g, "&nbsp;");
38+
39+
// display results
40+
document.getElementById('parser_output').innerHTML = results
41+
});
42+
}
43+
44+
parse_query();
45+
</script>
46+
</body>
47+
</html>

‎lib/lucene-query-parser.js‎

Lines changed: 608 additions & 525 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/lucene-query.grammar‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ unquoted_term
227227
if (/^(?:AND|OR|NOT|\|\||&&)$/.test(res)) {
228228
var e = new Error('Term can not be AND, OR, NOT, ||, &&')
229229
e.name = 'SyntaxError'
230-
e.column = offset
230+
e.column = location
231231
throw e
232232
}
233233
return res

‎package.json‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Lucene Query Parser for JavaScript created using PEG.js",
55
"main": "lib/lucene-query-parser.js",
66
"scripts": {
7-
"build": "PEG_OUT=`cat lib/lucene-query.grammar | node_modules/pegjs/bin/pegjs` && printf \"if (typeof define !== 'function') { var define = require('amdefine')(module) };\n\ndefine([], function() { \nvar module = {};\n%s\nreturn module.exports;\n});\n\" \"$PEG_OUT\" > ./lib/lucene-query-parser.js",
8-
"test": "./node_modules/.bin/jasmine-node ./spec/ --verbose",
7+
"build": "node_modules/pegjs/bin/pegjs --format umd --export-var lucenequeryparser -o lib/lucene-query-parser.js lib/lucene-query.grammar",
8+
"test": "jasmine spec/lucene-query-parser.spec.js",
99
"prepublish": "npm run-script build && npm test"
1010
},
1111
"repository": {
@@ -36,11 +36,10 @@
3636
"bugs": {
3737
"url": "https://github.com/thoward/lucene-query-parser.js/issues"
3838
},
39-
"dependencies": {
40-
"amdefine": ">=0.0.2"
41-
},
4239
"devDependencies": {
43-
"jasmine-node": "1.10.x",
44-
"pegjs": "0.8.x"
40+
"amdefine": ">=0.0.2",
41+
"jasmine": "~2.8.0",
42+
"jasmine-core": "~2.8.0",
43+
"pegjs": "0.10.x"
4544
}
4645
}

‎spec/SpecRunner.html‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,14 @@
44
<title>Jasmine Test Runner</title>
55

66
<!-- Jasmine -->
7-
<link rel="stylesheet" type="text/css" href="../node_modules/jasmine-node/node_modules/jasmine-reporters/ext/jasmine.css"/>
8-
<script type="text/javascript" src="../node_modules/jasmine-node/node_modules/jasmine-reporters/ext/jasmine.js"></script>
9-
<script type="text/javascript" src="../node_modules/jasmine-node/node_modules/jasmine-reporters/ext/jasmine-html.js"></script>
7+
<link rel="stylesheet" type="text/css" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"/>
8+
<script type="text/javascript" src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
9+
<script type="text/javascript" src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
10+
<script type="text/javascript" src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
1011

1112
<!-- RequireJS -->
12-
<script type="text/javascript" src="../vendor/require.js"></script>
13-
13+
<script data-main="specRunner.js" src="../vendor/require.js"></script>
1414
</head>
15-
1615
<body>
17-
<script type="text/javascript">
18-
require.config({
19-
baseUrl: './'
20-
});
21-
22-
require([
23-
'../spec/lucene-query-parser.spec.js'
24-
], function() {
25-
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
26-
jasmine.getEnv().execute();
27-
});
28-
</script>
2916
</body>
3017
</html>

‎spec/lucene-query-parser.spec.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ define(["../lib/lucene-query-parser.js"], function(lucenequeryparser) {
3030
expect(results['left']['term']).toBe('Foo');
3131
});
3232

33-
function isEmpty(arr)
34-
{
35-
for(var i in arr)
36-
{
33+
function isEmpty(arr) {
34+
for(var i in arr) {
3735
return false;
3836
}
3937
return true;
@@ -77,7 +75,7 @@ describe("lucenequeryparser: term parsing", function() {
7775
it("handles empty term with operator", function() {
7876
expect(function () {
7977
lucenequeryparser.parse('device_model: AND x:y');
80-
}).toThrow('Term can not be AND, OR, NOT, ||, &&');
78+
}).toThrow(new SyntaxError('Term can not be AND, OR, NOT, ||, &&'));
8179
});
8280

8381
it("parses terms with +", function() {

‎spec/specRunner.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require.config({
2+
paths: {
3+
'jasmine': '../node_modules/jasmine/lib/jasmine',
4+
},
5+
});
6+
7+
require(['./lucene-query-parser.spec.js']);

0 commit comments

Comments
 (0)
Please sign in to comment.