@matdata/yasqe 4.6.1 → 4.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -121
- package/build/yasqe.html +107 -107
- package/build/yasqe.min.css.map +1 -1
- package/build/yasqe.min.js.map +1 -1
- package/grammar/README.md +12 -12
- package/grammar/_tokenizer-table.js +4776 -4776
- package/grammar/build.sh +2 -2
- package/grammar/sparql11-grammar.pl +834 -834
- package/grammar/sparqljs-browser-min.js +4535 -4535
- package/grammar/tokenizer.ts +729 -729
- package/grammar/util/gen_ll1.pl +37 -37
- package/grammar/util/gen_sparql11.pl +11 -11
- package/grammar/util/ll1.pl +175 -175
- package/grammar/util/output_to_javascript.pl +75 -75
- package/grammar/util/prune.pl +49 -49
- package/grammar/util/rewrite.pl +104 -104
- package/package.json +40 -40
- package/src/CodeMirror.ts +54 -54
- package/src/autocompleters/classes.ts +32 -32
- package/src/autocompleters/index.ts +346 -346
- package/src/autocompleters/prefixes.ts +130 -130
- package/src/autocompleters/properties.ts +28 -28
- package/src/autocompleters/show-hint.scss +38 -38
- package/src/autocompleters/variables.ts +52 -52
- package/src/prefixFold.ts +93 -93
- package/src/prefixUtils.ts +65 -65
- package/src/scss/codemirrorMods.scss +36 -36
- package/src/scss/yasqe.scss +89 -89
- package/src/sparql.ts +215 -215
- package/src/tokenUtils.ts +121 -121
- package/src/tooltip.ts +31 -31
- package/src/trie.ts +238 -238
package/src/tokenUtils.ts
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { default as Yasqe, Token, Position } from "./";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* When typing a query, this query is sometimes syntactically invalid, causing
|
|
5
|
-
* the current tokens to be incorrect This causes problem for autocompletion.
|
|
6
|
-
* http://bla might result in two tokens: http:// and bla. We'll want to combine
|
|
7
|
-
* these
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export function getCompleteToken(yasqe: Yasqe, token?: Token, cur?: Position): Token {
|
|
11
|
-
if (!cur) {
|
|
12
|
-
cur = yasqe.getDoc().getCursor() as Position;
|
|
13
|
-
}
|
|
14
|
-
if (!token) {
|
|
15
|
-
token = yasqe.getTokenAt(cur) as Token;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return expandTokenToEnd(yasqe, expandTokenToStart(yasqe, token, cur), cur);
|
|
19
|
-
}
|
|
20
|
-
function expandTokenToStart(yasqe: Yasqe, token: Token, cur: Position): Token {
|
|
21
|
-
var prevToken: Token = yasqe.getTokenAt({
|
|
22
|
-
line: cur.line,
|
|
23
|
-
ch: token.start,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if ((token.type === "punc" || token.type === "error") && !token.state.possibleFullIri && !token.state.inPrefixDecl) {
|
|
27
|
-
token.state.possibleCurrent = token.state.possibleNext;
|
|
28
|
-
return token;
|
|
29
|
-
}
|
|
30
|
-
if (prevToken.type === "punc" && !prevToken.state.possibleFullIri && !prevToken.state.inPrefixDecl) {
|
|
31
|
-
//assuming this is a path expression. Should not expand the token anymore
|
|
32
|
-
//Also checking whether current token isnt an error, to avoid stopping on iri path delimiters
|
|
33
|
-
return token;
|
|
34
|
-
}
|
|
35
|
-
// not start of line, and not whitespace
|
|
36
|
-
if (prevToken.type != null && prevToken.type != "ws" && token.type != null && token.type != "ws") {
|
|
37
|
-
token.start = prevToken.start;
|
|
38
|
-
token.string = prevToken.string + token.string;
|
|
39
|
-
return expandTokenToStart(yasqe, token, {
|
|
40
|
-
line: cur.line,
|
|
41
|
-
ch: prevToken.start,
|
|
42
|
-
}); // recursively, might have multiple tokens which it should include
|
|
43
|
-
} else if (token.type != null && token.type == "ws") {
|
|
44
|
-
//always keep 1 char of whitespace between tokens. Otherwise, autocompletions might end up next to the previous node, without whitespace between them
|
|
45
|
-
token.start = token.start + 1;
|
|
46
|
-
token.string = token.string.substring(1);
|
|
47
|
-
return token;
|
|
48
|
-
} else {
|
|
49
|
-
return token;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function expandTokenToEnd(yasqe: Yasqe, token: Token, cur: Position): Token {
|
|
54
|
-
if (token.string.indexOf(" ") >= 0) {
|
|
55
|
-
/**
|
|
56
|
-
* This is most likely a query ending with `<http://www.opengis.net/ont/geosparql# ?a`
|
|
57
|
-
* ^ cursor
|
|
58
|
-
* In this case, separate by whitespace, and assume we're finished
|
|
59
|
-
*/
|
|
60
|
-
const whitespaceIndex = token.string.indexOf(" ");
|
|
61
|
-
token.string = token.string.substr(0, whitespaceIndex);
|
|
62
|
-
token.end = token.start + token.string.length;
|
|
63
|
-
return token;
|
|
64
|
-
}
|
|
65
|
-
if (!token.type) return token;
|
|
66
|
-
|
|
67
|
-
var nextToken: Token = yasqe.getTokenAt({
|
|
68
|
-
line: cur.line,
|
|
69
|
-
ch: token.end + 1,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
// not end of line
|
|
74
|
-
nextToken.type !== "ws" &&
|
|
75
|
-
//not a punctuation (for eg '?subject}', we dont want to include '}')
|
|
76
|
-
token.state.possibleFullIri &&
|
|
77
|
-
//not whitespace
|
|
78
|
-
token.type !== null &&
|
|
79
|
-
token.type !== "ws" &&
|
|
80
|
-
// Avoid infinite loops as CM will give back the last token of in a line when requesting something larger then the lines length
|
|
81
|
-
nextToken.end !== token.end
|
|
82
|
-
) {
|
|
83
|
-
token.end = nextToken.end;
|
|
84
|
-
token.string = token.string + nextToken.string;
|
|
85
|
-
return expandTokenToEnd(yasqe, token, {
|
|
86
|
-
line: cur.line,
|
|
87
|
-
ch: nextToken.end,
|
|
88
|
-
}); // recursively, might have multiple tokens which it should include
|
|
89
|
-
} else if (token.type === "ws") {
|
|
90
|
-
//always keep 1 char of whitespace between tokens. Otherwise, autocompletions might end up next to the previous node, without whitespace between them
|
|
91
|
-
token.end = token.end + 1;
|
|
92
|
-
token.string = token.string.substring(token.string.length - 1);
|
|
93
|
-
return token;
|
|
94
|
-
} else {
|
|
95
|
-
return token;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export function getPreviousNonWsToken(yasqe: Yasqe, line: number, token: Token): Token {
|
|
99
|
-
var previousToken = yasqe.getTokenAt({
|
|
100
|
-
line: line,
|
|
101
|
-
ch: token.start,
|
|
102
|
-
});
|
|
103
|
-
if (previousToken != null && previousToken.type == "ws") {
|
|
104
|
-
previousToken = getPreviousNonWsToken(yasqe, line, previousToken);
|
|
105
|
-
}
|
|
106
|
-
return previousToken;
|
|
107
|
-
}
|
|
108
|
-
export function getNextNonWsToken(yasqe: Yasqe, lineNumber: number, charNumber?: number): Token | undefined {
|
|
109
|
-
if (charNumber == undefined) charNumber = 1;
|
|
110
|
-
var token = yasqe.getTokenAt({
|
|
111
|
-
line: lineNumber,
|
|
112
|
-
ch: charNumber,
|
|
113
|
-
});
|
|
114
|
-
if (token == null || token == undefined || token.end < charNumber) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
if (token.type == "ws") {
|
|
118
|
-
return getNextNonWsToken(yasqe, lineNumber, token.end + 1);
|
|
119
|
-
}
|
|
120
|
-
return token;
|
|
121
|
-
}
|
|
1
|
+
import { default as Yasqe, Token, Position } from "./";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When typing a query, this query is sometimes syntactically invalid, causing
|
|
5
|
+
* the current tokens to be incorrect This causes problem for autocompletion.
|
|
6
|
+
* http://bla might result in two tokens: http:// and bla. We'll want to combine
|
|
7
|
+
* these
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function getCompleteToken(yasqe: Yasqe, token?: Token, cur?: Position): Token {
|
|
11
|
+
if (!cur) {
|
|
12
|
+
cur = yasqe.getDoc().getCursor() as Position;
|
|
13
|
+
}
|
|
14
|
+
if (!token) {
|
|
15
|
+
token = yasqe.getTokenAt(cur) as Token;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return expandTokenToEnd(yasqe, expandTokenToStart(yasqe, token, cur), cur);
|
|
19
|
+
}
|
|
20
|
+
function expandTokenToStart(yasqe: Yasqe, token: Token, cur: Position): Token {
|
|
21
|
+
var prevToken: Token = yasqe.getTokenAt({
|
|
22
|
+
line: cur.line,
|
|
23
|
+
ch: token.start,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if ((token.type === "punc" || token.type === "error") && !token.state.possibleFullIri && !token.state.inPrefixDecl) {
|
|
27
|
+
token.state.possibleCurrent = token.state.possibleNext;
|
|
28
|
+
return token;
|
|
29
|
+
}
|
|
30
|
+
if (prevToken.type === "punc" && !prevToken.state.possibleFullIri && !prevToken.state.inPrefixDecl) {
|
|
31
|
+
//assuming this is a path expression. Should not expand the token anymore
|
|
32
|
+
//Also checking whether current token isnt an error, to avoid stopping on iri path delimiters
|
|
33
|
+
return token;
|
|
34
|
+
}
|
|
35
|
+
// not start of line, and not whitespace
|
|
36
|
+
if (prevToken.type != null && prevToken.type != "ws" && token.type != null && token.type != "ws") {
|
|
37
|
+
token.start = prevToken.start;
|
|
38
|
+
token.string = prevToken.string + token.string;
|
|
39
|
+
return expandTokenToStart(yasqe, token, {
|
|
40
|
+
line: cur.line,
|
|
41
|
+
ch: prevToken.start,
|
|
42
|
+
}); // recursively, might have multiple tokens which it should include
|
|
43
|
+
} else if (token.type != null && token.type == "ws") {
|
|
44
|
+
//always keep 1 char of whitespace between tokens. Otherwise, autocompletions might end up next to the previous node, without whitespace between them
|
|
45
|
+
token.start = token.start + 1;
|
|
46
|
+
token.string = token.string.substring(1);
|
|
47
|
+
return token;
|
|
48
|
+
} else {
|
|
49
|
+
return token;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function expandTokenToEnd(yasqe: Yasqe, token: Token, cur: Position): Token {
|
|
54
|
+
if (token.string.indexOf(" ") >= 0) {
|
|
55
|
+
/**
|
|
56
|
+
* This is most likely a query ending with `<http://www.opengis.net/ont/geosparql# ?a`
|
|
57
|
+
* ^ cursor
|
|
58
|
+
* In this case, separate by whitespace, and assume we're finished
|
|
59
|
+
*/
|
|
60
|
+
const whitespaceIndex = token.string.indexOf(" ");
|
|
61
|
+
token.string = token.string.substr(0, whitespaceIndex);
|
|
62
|
+
token.end = token.start + token.string.length;
|
|
63
|
+
return token;
|
|
64
|
+
}
|
|
65
|
+
if (!token.type) return token;
|
|
66
|
+
|
|
67
|
+
var nextToken: Token = yasqe.getTokenAt({
|
|
68
|
+
line: cur.line,
|
|
69
|
+
ch: token.end + 1,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
// not end of line
|
|
74
|
+
nextToken.type !== "ws" &&
|
|
75
|
+
//not a punctuation (for eg '?subject}', we dont want to include '}')
|
|
76
|
+
token.state.possibleFullIri &&
|
|
77
|
+
//not whitespace
|
|
78
|
+
token.type !== null &&
|
|
79
|
+
token.type !== "ws" &&
|
|
80
|
+
// Avoid infinite loops as CM will give back the last token of in a line when requesting something larger then the lines length
|
|
81
|
+
nextToken.end !== token.end
|
|
82
|
+
) {
|
|
83
|
+
token.end = nextToken.end;
|
|
84
|
+
token.string = token.string + nextToken.string;
|
|
85
|
+
return expandTokenToEnd(yasqe, token, {
|
|
86
|
+
line: cur.line,
|
|
87
|
+
ch: nextToken.end,
|
|
88
|
+
}); // recursively, might have multiple tokens which it should include
|
|
89
|
+
} else if (token.type === "ws") {
|
|
90
|
+
//always keep 1 char of whitespace between tokens. Otherwise, autocompletions might end up next to the previous node, without whitespace between them
|
|
91
|
+
token.end = token.end + 1;
|
|
92
|
+
token.string = token.string.substring(token.string.length - 1);
|
|
93
|
+
return token;
|
|
94
|
+
} else {
|
|
95
|
+
return token;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export function getPreviousNonWsToken(yasqe: Yasqe, line: number, token: Token): Token {
|
|
99
|
+
var previousToken = yasqe.getTokenAt({
|
|
100
|
+
line: line,
|
|
101
|
+
ch: token.start,
|
|
102
|
+
});
|
|
103
|
+
if (previousToken != null && previousToken.type == "ws") {
|
|
104
|
+
previousToken = getPreviousNonWsToken(yasqe, line, previousToken);
|
|
105
|
+
}
|
|
106
|
+
return previousToken;
|
|
107
|
+
}
|
|
108
|
+
export function getNextNonWsToken(yasqe: Yasqe, lineNumber: number, charNumber?: number): Token | undefined {
|
|
109
|
+
if (charNumber == undefined) charNumber = 1;
|
|
110
|
+
var token = yasqe.getTokenAt({
|
|
111
|
+
line: lineNumber,
|
|
112
|
+
ch: charNumber,
|
|
113
|
+
});
|
|
114
|
+
if (token == null || token == undefined || token.end < charNumber) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
if (token.type == "ws") {
|
|
118
|
+
return getNextNonWsToken(yasqe, lineNumber, token.end + 1);
|
|
119
|
+
}
|
|
120
|
+
return token;
|
|
121
|
+
}
|
package/src/tooltip.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Write our own tooltip, to avoid loading another library for just this functionality. For now, we only use tooltip for showing parse errors, so this is quite a tailored solution
|
|
3
|
-
* Requirements:
|
|
4
|
-
* position tooltip within codemirror frame as much as possible, to avoid z-index issues with external things on page
|
|
5
|
-
* use html as content
|
|
6
|
-
*/
|
|
7
|
-
import Yasqe from "./";
|
|
8
|
-
|
|
9
|
-
export default function tooltip(_yasqe: Yasqe, parent: HTMLDivElement, html: string) {
|
|
10
|
-
var tooltip: HTMLDivElement;
|
|
11
|
-
parent.onmouseover = function () {
|
|
12
|
-
if (!tooltip) {
|
|
13
|
-
tooltip = document.createElement("div");
|
|
14
|
-
tooltip.className = "yasqe_tooltip";
|
|
15
|
-
}
|
|
16
|
-
// if ($(yasqe.getWrapperElement()).offset().top >= tooltip.offset().top) {
|
|
17
|
-
//shit, move the tooltip down. The tooltip now hovers over the top edge of the yasqe instance
|
|
18
|
-
// tooltip.css("bottom", "auto");
|
|
19
|
-
// tooltip.css("top", "26px");
|
|
20
|
-
// }
|
|
21
|
-
tooltip.style.display = "block";
|
|
22
|
-
tooltip.innerHTML = html;
|
|
23
|
-
parent.appendChild(tooltip);
|
|
24
|
-
};
|
|
25
|
-
parent.onmouseout = function () {
|
|
26
|
-
if (tooltip) {
|
|
27
|
-
tooltip.style.display = "none";
|
|
28
|
-
}
|
|
29
|
-
tooltip.innerHTML = html;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Write our own tooltip, to avoid loading another library for just this functionality. For now, we only use tooltip for showing parse errors, so this is quite a tailored solution
|
|
3
|
+
* Requirements:
|
|
4
|
+
* position tooltip within codemirror frame as much as possible, to avoid z-index issues with external things on page
|
|
5
|
+
* use html as content
|
|
6
|
+
*/
|
|
7
|
+
import Yasqe from "./";
|
|
8
|
+
|
|
9
|
+
export default function tooltip(_yasqe: Yasqe, parent: HTMLDivElement, html: string) {
|
|
10
|
+
var tooltip: HTMLDivElement;
|
|
11
|
+
parent.onmouseover = function () {
|
|
12
|
+
if (!tooltip) {
|
|
13
|
+
tooltip = document.createElement("div");
|
|
14
|
+
tooltip.className = "yasqe_tooltip";
|
|
15
|
+
}
|
|
16
|
+
// if ($(yasqe.getWrapperElement()).offset().top >= tooltip.offset().top) {
|
|
17
|
+
//shit, move the tooltip down. The tooltip now hovers over the top edge of the yasqe instance
|
|
18
|
+
// tooltip.css("bottom", "auto");
|
|
19
|
+
// tooltip.css("top", "26px");
|
|
20
|
+
// }
|
|
21
|
+
tooltip.style.display = "block";
|
|
22
|
+
tooltip.innerHTML = html;
|
|
23
|
+
parent.appendChild(tooltip);
|
|
24
|
+
};
|
|
25
|
+
parent.onmouseout = function () {
|
|
26
|
+
if (tooltip) {
|
|
27
|
+
tooltip.style.display = "none";
|
|
28
|
+
}
|
|
29
|
+
tooltip.innerHTML = html;
|
|
30
|
+
};
|
|
31
|
+
}
|