@matdata/yasqe 4.6.1
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 -0
- package/build/ts/grammar/tokenizer.d.ts +37 -0
- package/build/ts/src/CodeMirror.d.ts +21 -0
- package/build/ts/src/autocompleters/classes.d.ts +3 -0
- package/build/ts/src/autocompleters/index.d.ts +39 -0
- package/build/ts/src/autocompleters/prefixes.d.ts +3 -0
- package/build/ts/src/autocompleters/properties.d.ts +3 -0
- package/build/ts/src/autocompleters/variables.d.ts +3 -0
- package/build/ts/src/defaults.d.ts +75 -0
- package/build/ts/src/imgs.d.ts +7 -0
- package/build/ts/src/index.d.ts +303 -0
- package/build/ts/src/prefixFold.d.ts +8 -0
- package/build/ts/src/prefixUtils.d.ts +9 -0
- package/build/ts/src/sparql.d.ts +20 -0
- package/build/ts/src/tokenUtils.d.ts +4 -0
- package/build/ts/src/tooltip.d.ts +2 -0
- package/build/ts/src/trie.d.ts +13 -0
- package/build/yasqe.html +108 -0
- package/build/yasqe.min.css +2 -0
- package/build/yasqe.min.css.map +1 -0
- package/build/yasqe.min.js +3 -0
- package/build/yasqe.min.js.LICENSE.txt +3 -0
- package/build/yasqe.min.js.map +1 -0
- package/grammar/README.md +12 -0
- package/grammar/_tokenizer-table.js +4776 -0
- package/grammar/build.sh +2 -0
- package/grammar/sparql11-grammar.pl +834 -0
- package/grammar/sparqljs-browser-min.js +4535 -0
- package/grammar/tokenizer.ts +729 -0
- package/grammar/util/gen_ll1.pl +37 -0
- package/grammar/util/gen_sparql11.pl +11 -0
- package/grammar/util/ll1.pl +175 -0
- package/grammar/util/output_to_javascript.pl +75 -0
- package/grammar/util/prune.pl +49 -0
- package/grammar/util/rewrite.pl +104 -0
- package/package.json +40 -0
- package/src/CodeMirror.ts +54 -0
- package/src/autocompleters/classes.ts +32 -0
- package/src/autocompleters/index.ts +346 -0
- package/src/autocompleters/prefixes.ts +130 -0
- package/src/autocompleters/properties.ts +28 -0
- package/src/autocompleters/show-hint.scss +38 -0
- package/src/autocompleters/variables.ts +52 -0
- package/src/defaults.ts +149 -0
- package/src/imgs.ts +14 -0
- package/src/index.ts +1089 -0
- package/src/prefixFold.ts +93 -0
- package/src/prefixUtils.ts +65 -0
- package/src/scss/buttons.scss +275 -0
- package/src/scss/codemirrorMods.scss +36 -0
- package/src/scss/yasqe.scss +89 -0
- package/src/sparql.ts +215 -0
- package/src/tokenUtils.ts +121 -0
- package/src/tooltip.ts +31 -0
- package/src/trie.ts +238 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
:-dynamic fo/2.
|
|
2
|
+
:-dynamic fi/2.
|
|
3
|
+
:-dynamic cf/2.
|
|
4
|
+
:-dynamic change/0.
|
|
5
|
+
:-dynamic m/3.
|
|
6
|
+
:-dynamic tm/1.
|
|
7
|
+
:-dynamic '==>'/2.
|
|
8
|
+
:-dynamic '=>'/2.
|
|
9
|
+
:-op(550,xfy,===>). % Rewrite rules on EBNF expressions
|
|
10
|
+
:-op(500,xfy,==>). % EBNF grammar productions
|
|
11
|
+
:-op(500,xfy,=>). % BNF grammar productions
|
|
12
|
+
:-op(490,xfy,or).
|
|
13
|
+
:-op(480,fy,*).
|
|
14
|
+
:-op(470,xfy,\).
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
:-reconsult('rewrite.pl').
|
|
18
|
+
:-reconsult('ll1.pl').
|
|
19
|
+
:-reconsult('prune').
|
|
20
|
+
:-reconsult('output_to_javascript.pl').
|
|
21
|
+
|
|
22
|
+
go:-
|
|
23
|
+
ebnf_to_bnf,
|
|
24
|
+
prune_for_top_symbol,
|
|
25
|
+
ll1_tables,
|
|
26
|
+
ll1_check,
|
|
27
|
+
output_file(Out),
|
|
28
|
+
write('Writing to '),write(Out),nl,
|
|
29
|
+
tell(Out),
|
|
30
|
+
output_table_js,
|
|
31
|
+
output_keywords_js,
|
|
32
|
+
output_punct_js,
|
|
33
|
+
js_vars(Vars),
|
|
34
|
+
output_vars_js(Vars),
|
|
35
|
+
write('}'),
|
|
36
|
+
told.
|
|
37
|
+
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
|
|
4
|
+
Compute LL1 parse tables.
|
|
5
|
+
|
|
6
|
+
fi(NT,T) means that T can be the first terminal in NT. The special
|
|
7
|
+
token epsilon means that NT may rewrite to nothing
|
|
8
|
+
(NT is "nullable").
|
|
9
|
+
|
|
10
|
+
fo(NT,T) means that nonterminal NT can be followed by terminal T.
|
|
11
|
+
- the final argument is for debugging only, and records
|
|
12
|
+
the nonterminal from which the follower T was copied.
|
|
13
|
+
|
|
14
|
+
stephen.cresswell@tso.co.uk
|
|
15
|
+
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
ll1_tables:-
|
|
20
|
+
retractall(cf(_,_)),
|
|
21
|
+
retractall(nt(_)),
|
|
22
|
+
retractall(fi(_,_)),
|
|
23
|
+
retractall(fo(_,_)),
|
|
24
|
+
retractall(m(_,_,_)),
|
|
25
|
+
|
|
26
|
+
validate_rules,
|
|
27
|
+
remember1(change),
|
|
28
|
+
iterate_first,
|
|
29
|
+
remember1(change),
|
|
30
|
+
iterate_follow,
|
|
31
|
+
iterate_matrix.
|
|
32
|
+
|
|
33
|
+
validate_rules:-
|
|
34
|
+
NT=>_,
|
|
35
|
+
\+ (_=>RHS, memberchk(NT,RHS) ),
|
|
36
|
+
format("Warning: unused non-terminal: ~w~n",[NT]),
|
|
37
|
+
fail.
|
|
38
|
+
validate_rules:-
|
|
39
|
+
% (Check the untranslated rules)
|
|
40
|
+
LHS ==> RHS,
|
|
41
|
+
\+RHS=[],
|
|
42
|
+
\+RHS=[_|_],
|
|
43
|
+
format("Warning: atomic RHS: ~w~n",[LHS=>RHS]),
|
|
44
|
+
fail.
|
|
45
|
+
validate_rules:-
|
|
46
|
+
_ => RHS,
|
|
47
|
+
member(T,RHS),
|
|
48
|
+
\+ T => _,
|
|
49
|
+
remember(tm(T)),
|
|
50
|
+
fail.
|
|
51
|
+
validate_rules:-
|
|
52
|
+
tm(T),
|
|
53
|
+
\+declared_terminal(T),
|
|
54
|
+
format("Warning: undeclared terminal: ~w~n",[T]),
|
|
55
|
+
fail.
|
|
56
|
+
validate_rules:-
|
|
57
|
+
declared_terminal(T),
|
|
58
|
+
\+tm(T),
|
|
59
|
+
format("Declared terminal not found in grammar: ~w~n",[T]),
|
|
60
|
+
fail.
|
|
61
|
+
validate_rules.
|
|
62
|
+
|
|
63
|
+
declared_terminal(T):-
|
|
64
|
+
tm_keywords(Ts),
|
|
65
|
+
member(T,Ts).
|
|
66
|
+
declared_terminal(T):-
|
|
67
|
+
tm_regex(Ts),
|
|
68
|
+
member(T,Ts).
|
|
69
|
+
declared_terminal(T):-
|
|
70
|
+
tm_punct(Ts),
|
|
71
|
+
member(T=_,Ts).
|
|
72
|
+
|
|
73
|
+
% Repeated until no change
|
|
74
|
+
iterate_first:-
|
|
75
|
+
change,
|
|
76
|
+
!,
|
|
77
|
+
retractall(change),
|
|
78
|
+
iterate,
|
|
79
|
+
iterate_first.
|
|
80
|
+
iterate_first.
|
|
81
|
+
|
|
82
|
+
% All possibilities
|
|
83
|
+
iterate:-
|
|
84
|
+
first(A,W),
|
|
85
|
+
remember(fi(A,W)),
|
|
86
|
+
fail.
|
|
87
|
+
iterate.
|
|
88
|
+
|
|
89
|
+
assert_terminals:-
|
|
90
|
+
tm(Tm),
|
|
91
|
+
assertz(fi(Tm,Tm)),
|
|
92
|
+
fail.
|
|
93
|
+
assert_terminals.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
first(Tm,Tm):-
|
|
97
|
+
tm(Tm).
|
|
98
|
+
first(Nonterm,F):-
|
|
99
|
+
Nonterm=>RHS,
|
|
100
|
+
first_list(RHS,F).
|
|
101
|
+
|
|
102
|
+
first_list([],epsilon).
|
|
103
|
+
first_list([W|RHS],F):-
|
|
104
|
+
fi(W,epsilon),
|
|
105
|
+
first_list(RHS,F).
|
|
106
|
+
first_list([W|_],F):-
|
|
107
|
+
fi(W,F),
|
|
108
|
+
F \== epsilon.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
iterate_follow:-
|
|
112
|
+
change,
|
|
113
|
+
!,
|
|
114
|
+
retractall(change),
|
|
115
|
+
iterate_f,
|
|
116
|
+
iterate_follow.
|
|
117
|
+
iterate_follow.
|
|
118
|
+
|
|
119
|
+
iterate_f:-
|
|
120
|
+
follow,
|
|
121
|
+
fail.
|
|
122
|
+
iterate_f.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
follow:-
|
|
126
|
+
B => RHS,
|
|
127
|
+
follow_list(RHS,B).
|
|
128
|
+
|
|
129
|
+
follow_list([X],B):-
|
|
130
|
+
!,
|
|
131
|
+
copy_follow(B,X).
|
|
132
|
+
follow_list([A|RHS],B):-
|
|
133
|
+
tm(A),!,
|
|
134
|
+
follow_list(RHS,B).
|
|
135
|
+
follow_list([A,X2|RHS],B):-
|
|
136
|
+
first_list([X2|RHS],F),
|
|
137
|
+
(F=epsilon ->
|
|
138
|
+
copy_follow(B,A)
|
|
139
|
+
;
|
|
140
|
+
remember(fo(A,F))
|
|
141
|
+
),
|
|
142
|
+
follow_list([X2|RHS],B).
|
|
143
|
+
|
|
144
|
+
% Whatever can follow B, can follow A
|
|
145
|
+
% (applied when A can be final constituent of B)
|
|
146
|
+
copy_follow(B,A):-
|
|
147
|
+
\+tm(A),
|
|
148
|
+
remember1(cf(B,A)),
|
|
149
|
+
fo(B,Fo),
|
|
150
|
+
remember(fo(A,Fo)),
|
|
151
|
+
fail.
|
|
152
|
+
copy_follow(_,_).
|
|
153
|
+
|
|
154
|
+
iterate_matrix:-
|
|
155
|
+
A => RHS,
|
|
156
|
+
first_list(RHS,F),
|
|
157
|
+
F \== epsilon,
|
|
158
|
+
remember1(m(A,F,A=>RHS)),
|
|
159
|
+
fail.
|
|
160
|
+
iterate_matrix:-
|
|
161
|
+
A => RHS,
|
|
162
|
+
first_list(RHS,epsilon),
|
|
163
|
+
fo(A,F),
|
|
164
|
+
remember1(m(A,F,A=>RHS)),
|
|
165
|
+
fail.
|
|
166
|
+
iterate_matrix.
|
|
167
|
+
|
|
168
|
+
ll1_check:-
|
|
169
|
+
m(NT,T,R1),
|
|
170
|
+
m(NT,T,R2),
|
|
171
|
+
R1@<R2,
|
|
172
|
+
format('LL(1) clash - ~w, ~w,~n R1=~w~n R2=~w~n',[NT,T,R1,R2]),
|
|
173
|
+
fail.
|
|
174
|
+
ll1_check:-
|
|
175
|
+
write('LL(1) check complete.'),nl.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* Convert computed LL(1) table into javascript source
|
|
2
|
+
*/
|
|
3
|
+
|
|
4
|
+
output_table_js:-
|
|
5
|
+
write('module.exports = {table:'),nl,
|
|
6
|
+
setof(LHS, RHS^(LHS=>RHS), NTs),
|
|
7
|
+
form_table(NTs,'{'),
|
|
8
|
+
nl,write('},').
|
|
9
|
+
|
|
10
|
+
output_terminals_js:-
|
|
11
|
+
nl,nl,write('var terminal=['),nl,
|
|
12
|
+
tm_regex(Ks),
|
|
13
|
+
member(TM,Ks),
|
|
14
|
+
format(' { name: "~w", regex:new RegExp("^"+~w) }, ~n',[TM,TM]),
|
|
15
|
+
fail.
|
|
16
|
+
output_terminals_js:-
|
|
17
|
+
write('];'),nl,nl.
|
|
18
|
+
output_keywords_js:-
|
|
19
|
+
tm_keywords(Ps),
|
|
20
|
+
findall(Reg,member(Reg,Ps),Regs),
|
|
21
|
+
nl,nl,write('keywords:/^('),
|
|
22
|
+
output_as_regex_disj(Regs,''),
|
|
23
|
+
write(')/i ,'),nl.
|
|
24
|
+
output_punct_js:-
|
|
25
|
+
tm_punct(Ps),
|
|
26
|
+
findall(Reg,member(_=Reg,Ps),Regs),
|
|
27
|
+
nl,write('punct:/^('),
|
|
28
|
+
output_as_regex_disj(Regs,''),
|
|
29
|
+
write(')/ ,'),nl,nl.
|
|
30
|
+
output_top_symbol_js:-
|
|
31
|
+
start_symbol(TS),
|
|
32
|
+
format('startSymbol:"~w";~n',[TS]).
|
|
33
|
+
output_default_query_type_js:-
|
|
34
|
+
default_query_type(QT),
|
|
35
|
+
format('defaultQueryType:~w;~n',[QT]).
|
|
36
|
+
output_lex_version_js:-
|
|
37
|
+
lex_version(LV),
|
|
38
|
+
format('lexVersion:"~w";~n',[LV]).
|
|
39
|
+
output_accept_empty_js:-
|
|
40
|
+
accept_empty(AE),
|
|
41
|
+
format('acceptEmpty:"~w";~n',[AE]).
|
|
42
|
+
|
|
43
|
+
output_vars_js([]).
|
|
44
|
+
output_vars_js([Var=Val|Pairs]):-
|
|
45
|
+
format('~w:~w,~n',[Var,Val]),
|
|
46
|
+
output_vars_js(Pairs).
|
|
47
|
+
|
|
48
|
+
output_as_regex_disj([],_).
|
|
49
|
+
output_as_regex_disj([T|Ts],Prefix):-
|
|
50
|
+
format('~w~w',[Prefix,T]),
|
|
51
|
+
output_as_regex_disj(Ts,'|').
|
|
52
|
+
|
|
53
|
+
form_table([],_).
|
|
54
|
+
form_table([NT|NTs],Punc):-
|
|
55
|
+
format('~w~n "~w" : ',[Punc,NT]),
|
|
56
|
+
findall(First-RHS,m(NT,First,_=>RHS),Pairs),
|
|
57
|
+
output_pairs(Pairs,'{'),
|
|
58
|
+
write('}'),
|
|
59
|
+
form_table(NTs,', ').
|
|
60
|
+
|
|
61
|
+
output_pairs([],_).
|
|
62
|
+
output_pairs([First-RHS|Pairs],Punc):-
|
|
63
|
+
format('~w~n "~w": ',[Punc,First]),
|
|
64
|
+
write_list_strings(RHS),
|
|
65
|
+
output_pairs(Pairs, ', ').
|
|
66
|
+
|
|
67
|
+
write_list_strings(Xs):-
|
|
68
|
+
write('['),
|
|
69
|
+
write_list_strings1(Xs,''),
|
|
70
|
+
write(']').
|
|
71
|
+
|
|
72
|
+
write_list_strings1([],_).
|
|
73
|
+
write_list_strings1([X|Xs],Punc):-
|
|
74
|
+
format('~w"~w"',[Punc,X]),
|
|
75
|
+
write_list_strings1(Xs,',').
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
%
|
|
2
|
+
% Find and remove inaccessible non-terminals
|
|
3
|
+
%
|
|
4
|
+
% The is used because we have SPARQL1.1 query / update
|
|
5
|
+
% grammars together, but it helps (e.g. to keep autocompletion clean)
|
|
6
|
+
% for the grammars to be separated. This is done on the basis
|
|
7
|
+
% of reachability from the top symbol.
|
|
8
|
+
%
|
|
9
|
+
% stephen.cresswell@tso.co.uk
|
|
10
|
+
|
|
11
|
+
prune_for_top_symbol:-
|
|
12
|
+
top_symbol(Top),
|
|
13
|
+
reachable_syms(Top,NTs,_Ts),
|
|
14
|
+
findall(NT,(NT=>_RHS,\+memberchk(NT,NTs)),UnreachableNTs0),
|
|
15
|
+
sort(UnreachableNTs0,UnreachableNTs),
|
|
16
|
+
delete_NTs(UnreachableNTs).
|
|
17
|
+
|
|
18
|
+
delete_NTs([]).
|
|
19
|
+
delete_NTs([NT|NTs]):-
|
|
20
|
+
format('Removing unreachable nonterminal ~w~n',[NT]),
|
|
21
|
+
retractall(NT=>_),
|
|
22
|
+
delete_NTs(NTs).
|
|
23
|
+
|
|
24
|
+
reachable_syms(Top,NTs,Ts):-
|
|
25
|
+
NTs=[Top|_],
|
|
26
|
+
reachable(NTs,NTs,Ts),
|
|
27
|
+
once(append(NTs,[],NTs)),
|
|
28
|
+
once(append(Ts,[],Ts)).
|
|
29
|
+
|
|
30
|
+
reachable([],_,_):-!.
|
|
31
|
+
reachable([NT|NTs1],NTs0,Ts):-
|
|
32
|
+
once(findall(A,(NT=>RHS,member(A,RHS)),As)),
|
|
33
|
+
includes_rhs(As,NTs0,Ts),
|
|
34
|
+
reachable(NTs1,NTs0,Ts).
|
|
35
|
+
|
|
36
|
+
includes_rhs([],_,_).
|
|
37
|
+
includes_rhs([A|As],NTs0,Ts):-
|
|
38
|
+
A=>_,!,
|
|
39
|
+
% Non-terminal
|
|
40
|
+
memberchk(A,NTs0),
|
|
41
|
+
includes_rhs(As,NTs0,Ts).
|
|
42
|
+
includes_rhs([A|As],NTs0,Ts):-
|
|
43
|
+
memberchk(A,Ts),
|
|
44
|
+
includes_rhs(As,NTs0,Ts).
|
|
45
|
+
|
|
46
|
+
write_list([]).
|
|
47
|
+
write_list([H|T]):-
|
|
48
|
+
write(H),nl,
|
|
49
|
+
write_list(T).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
Compile EBNF rules (==>) to BNF rules (=>).
|
|
4
|
+
- i.e. expanding out *, +, ?, 'or'
|
|
5
|
+
|
|
6
|
+
stephen.cresswell@tso.co.uk
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
ebnf_to_bnf:-
|
|
11
|
+
retractall(_=>_),
|
|
12
|
+
remember(change),
|
|
13
|
+
rewrite_until_stable.
|
|
14
|
+
|
|
15
|
+
rewrite_until_stable:-
|
|
16
|
+
change,
|
|
17
|
+
!,
|
|
18
|
+
retractall(change),
|
|
19
|
+
rewrite_any,
|
|
20
|
+
rewrite_until_stable.
|
|
21
|
+
rewrite_until_stable.
|
|
22
|
+
|
|
23
|
+
rewrite_any:-
|
|
24
|
+
LHS==>RHS0,
|
|
25
|
+
rewrite(RHS0,RHS1),
|
|
26
|
+
remember(LHS=>RHS1),
|
|
27
|
+
fail.
|
|
28
|
+
rewrite_any.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
*(A) ===> A_star :-
|
|
32
|
+
atom(A),
|
|
33
|
+
format(atom(A_star),"*~w",[A]),
|
|
34
|
+
remember(A_star=>[]),
|
|
35
|
+
remember(A_star=>[A,A_star]).
|
|
36
|
+
|
|
37
|
+
+(A) ===> A_plus :-
|
|
38
|
+
atom(A),
|
|
39
|
+
format(atom(A_plus),"+~w",[A]),
|
|
40
|
+
remember(A_plus==>[A,*(A)]). % Assert as EBNF - requires further wrangling
|
|
41
|
+
|
|
42
|
+
?(A) ===> A_qm :-
|
|
43
|
+
atom(A),
|
|
44
|
+
format(atom(A_qm),"?~w",[A]),
|
|
45
|
+
remember(A_qm=>[]),
|
|
46
|
+
remember(A_qm=>[A]).
|
|
47
|
+
|
|
48
|
+
+A \ B ===> A_or_B :-
|
|
49
|
+
format(atom(A_or_B),"(~w or ~w)",[A,B]),
|
|
50
|
+
remember(A_or_B=>[A]),
|
|
51
|
+
remember(A_or_B=>[B]).
|
|
52
|
+
|
|
53
|
+
List ===> ListAtom :-
|
|
54
|
+
List = [_|_],
|
|
55
|
+
format(atom(ListAtom),"~w",[List]),
|
|
56
|
+
remember(ListAtom=>List).
|
|
57
|
+
|
|
58
|
+
OrExpr ===> ListAtom :-
|
|
59
|
+
OrExpr =.. [or|Args],
|
|
60
|
+
format(atom(ListAtom),"or(~w)",[Args]),
|
|
61
|
+
map_disjuncts(Args,ListAtom).
|
|
62
|
+
|
|
63
|
+
map_disjuncts([],_).
|
|
64
|
+
map_disjuncts([D|Ds],Head):-
|
|
65
|
+
remember(Head=>[D]),
|
|
66
|
+
map_disjuncts(Ds,Head).
|
|
67
|
+
|
|
68
|
+
% Apply rewrite rules starting from inside outwards
|
|
69
|
+
rewrite([],[]).
|
|
70
|
+
rewrite([T0|Ts0],[T2|Ts1]):-
|
|
71
|
+
\+(T0 = [_|_]),
|
|
72
|
+
T0 =.. [F|Args0],
|
|
73
|
+
!,
|
|
74
|
+
rewrite(Args0,Args1),
|
|
75
|
+
T1 =.. [F|Args1],
|
|
76
|
+
rewrite_if_poss(T1,T2),
|
|
77
|
+
rewrite(Ts0,Ts1).
|
|
78
|
+
rewrite([T0|Ts0],[T2|Ts1]):-
|
|
79
|
+
% A raw list (that is a sequence rather than an argument list)
|
|
80
|
+
T0 = [_|_],
|
|
81
|
+
rewrite(T0,T1),
|
|
82
|
+
rewrite_if_poss(T1,T2),
|
|
83
|
+
rewrite(Ts0,Ts1).
|
|
84
|
+
|
|
85
|
+
rewrite_if_poss(T0,T1):-
|
|
86
|
+
T0 ===> T1,
|
|
87
|
+
!.
|
|
88
|
+
rewrite_if_poss(T,T).
|
|
89
|
+
|
|
90
|
+
remember(X):-
|
|
91
|
+
call(X),
|
|
92
|
+
!.
|
|
93
|
+
remember(X):-
|
|
94
|
+
%write(X),nl,
|
|
95
|
+
assertz(change),
|
|
96
|
+
assertz(X).
|
|
97
|
+
|
|
98
|
+
% Do avoid duplication, but don't assert change
|
|
99
|
+
remember1(X):-
|
|
100
|
+
call(X),
|
|
101
|
+
!.
|
|
102
|
+
remember1(X):-
|
|
103
|
+
%write(X),nl,
|
|
104
|
+
assertz(X).
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matdata/yasqe",
|
|
3
|
+
"description": "Yet Another SPARQL Query Editor",
|
|
4
|
+
"version": "4.6.1",
|
|
5
|
+
"main": "build/yasqe.min.js",
|
|
6
|
+
"types": "build/ts/src/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "Triply <info@triply.cc>",
|
|
9
|
+
"homepage": "https://github.com/Matdata-eu/Yasgui",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">= 8"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"JavaScript",
|
|
15
|
+
"SPARQL",
|
|
16
|
+
"Editor",
|
|
17
|
+
"Semantic Web",
|
|
18
|
+
"Linked Data"
|
|
19
|
+
],
|
|
20
|
+
"bugs": "https://github.com/Matdata-eu/Yasgui/issues/",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/Matdata-eu/Yasgui.git",
|
|
24
|
+
"directory": "packages/yasqe"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@matdata/yasgui-utils": "^4.6.1",
|
|
28
|
+
"codemirror": "^5.51.0",
|
|
29
|
+
"lodash-es": "^4.17.15",
|
|
30
|
+
"query-string": "^6.10.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/codemirror": "0.0.100",
|
|
34
|
+
"@types/lodash-es": "^4.17.3",
|
|
35
|
+
"@types/node": "^22.5.4"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//Do not want to import this using typescript. Somehow, we get a tangled mess when transpiling to es6 with ts,
|
|
2
|
+
//and applying babel.
|
|
3
|
+
import {
|
|
4
|
+
Editor as CmEditor,
|
|
5
|
+
Doc as CmDoc,
|
|
6
|
+
Token as CmToken,
|
|
7
|
+
Position as CmPosition,
|
|
8
|
+
EditorConfiguration as CmEditorConfiguration,
|
|
9
|
+
} from "codemirror";
|
|
10
|
+
|
|
11
|
+
const _CodeMirror = require("codemirror");
|
|
12
|
+
|
|
13
|
+
import * as sparql11Mode from "../grammar/tokenizer";
|
|
14
|
+
import { default as prefixFold } from "./prefixFold";
|
|
15
|
+
import { TokenizerState } from "./index";
|
|
16
|
+
|
|
17
|
+
require("codemirror/addon/fold/foldcode.js");
|
|
18
|
+
require("codemirror/addon/fold/foldgutter.js");
|
|
19
|
+
require("codemirror/addon/fold/xml-fold.js");
|
|
20
|
+
require("codemirror/addon/fold/brace-fold.js");
|
|
21
|
+
require("codemirror/addon/hint/show-hint.js");
|
|
22
|
+
require("codemirror/addon/search/searchcursor.js");
|
|
23
|
+
require("codemirror/addon/search/match-highlighter.js");
|
|
24
|
+
require("codemirror/addon/edit/matchbrackets.js");
|
|
25
|
+
require("codemirror/addon/runmode/runmode.js");
|
|
26
|
+
require("codemirror/lib/codemirror.css");
|
|
27
|
+
require("codemirror/addon/fold/foldgutter.css");
|
|
28
|
+
require("./scss/codemirrorMods.scss");
|
|
29
|
+
|
|
30
|
+
_CodeMirror.registerHelper("fold", "prefix", prefixFold);
|
|
31
|
+
_CodeMirror.defineMode("sparql11", sparql11Mode.default);
|
|
32
|
+
|
|
33
|
+
namespace CodeMirror {
|
|
34
|
+
export type Doc = CmDoc;
|
|
35
|
+
export type Position = CmPosition;
|
|
36
|
+
export type EditorConfiguration = CmEditorConfiguration;
|
|
37
|
+
export interface Token extends CmToken {
|
|
38
|
+
state: sparql11Mode.State;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
interface CodeMirror extends Omit<CmEditor, "getOption" | "setOption" | "on" | "off"> {
|
|
42
|
+
/**
|
|
43
|
+
* Added some more specific typings for `getOption`
|
|
44
|
+
* For some functions (called from keyboard combinations like ctrl-enter) we cannot use member props of our object
|
|
45
|
+
* as these are lost when we are receiving the native CM object as argument
|
|
46
|
+
* Only way to persistently store these options is by using getOption and setOption
|
|
47
|
+
*/
|
|
48
|
+
getOption(opt: "queryType"): TokenizerState["queryType"];
|
|
49
|
+
setOption(opt: "queryType", val: TokenizerState["queryType"]): void;
|
|
50
|
+
|
|
51
|
+
foldCode(firstPrefixLine: number, prefix: string, collapse: "fold" | "unfold"): void;
|
|
52
|
+
}
|
|
53
|
+
const CodeMirror: { new (): CodeMirror; signal: (target: any, name: string, ...args: any[]) => void } = _CodeMirror;
|
|
54
|
+
export default CodeMirror;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Autocompleter from "./";
|
|
2
|
+
|
|
3
|
+
var conf: Autocompleter.CompleterConfig = {
|
|
4
|
+
onInitialize: function (_yasqe) {
|
|
5
|
+
// validPosition: yasqe.autocompleters.notifications.show,
|
|
6
|
+
// invalidPosition: yasqe.autocompleters.notifications.hide
|
|
7
|
+
},
|
|
8
|
+
get: function (yasqe, token) {
|
|
9
|
+
return Autocompleter.fetchFromLov(yasqe, "class", token);
|
|
10
|
+
},
|
|
11
|
+
isValidCompletionPosition: function (yasqe) {
|
|
12
|
+
const token = yasqe.getCompleteToken();
|
|
13
|
+
if (token.string[0] === "?" || token.string[0] === "$") return false;
|
|
14
|
+
const cur = yasqe.getDoc().getCursor();
|
|
15
|
+
const previousToken = yasqe.getPreviousNonWsToken(cur.line, token);
|
|
16
|
+
if (previousToken.state.lastProperty === "a") return true;
|
|
17
|
+
if (previousToken.state.lastProperty === "rdf:type") return true;
|
|
18
|
+
if (previousToken.state.lastProperty === "rdfs:domain") return true;
|
|
19
|
+
if (previousToken.state.lastProperty === "rdfs:range") return true;
|
|
20
|
+
return false;
|
|
21
|
+
},
|
|
22
|
+
preProcessToken: function (yasqe, token) {
|
|
23
|
+
return Autocompleter.preprocessIriForCompletion(yasqe, token);
|
|
24
|
+
},
|
|
25
|
+
postProcessSuggestion: function (yasqe, token, suggestedString) {
|
|
26
|
+
return Autocompleter.postprocessIriCompletion(yasqe, token, suggestedString);
|
|
27
|
+
},
|
|
28
|
+
bulk: false,
|
|
29
|
+
name: "class",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default conf;
|