Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/static/js/qleverUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ $(document).ready(function () {
// Attach format funtion to formatButton.
const formatButton = $("#formatButton");
formatButton.click(function() {
console.log("Formatting query");
const parseTree = parse(editor.getValue());
console.log("Parse tree: ", parseTree);
editor.setValue(format(editor.getValue()));
})

Expand Down
3 changes: 2 additions & 1 deletion backend/templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@

<!-- WASM formatter -->
<script type="module">
import { format, determineOperationType } from "{% static '/wasm/formatter/index.js' %}";
import { format, determineOperationType, parse } from "{% static '/wasm/formatter/index.js' %}";
window.format = format;
window.determineOperationType = determineOperationType;
window.parse = parse;
</script>

<!-- Our own JavaScript code for this demo -->
Expand Down
32 changes: 23 additions & 9 deletions formatter/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import init, { format_raw, determine_operation_type } from 'qlue-ls';
import wasmModule from 'qlue-ls/qlue_ls_bg.wasm'
// QLUE-LS
import init1, { format_raw, determine_operation_type } from 'qlue-ls';
import wasmModule1 from 'qlue-ls/qlue_ls_bg.wasm'

console.info("Loading WebAssembly module...")
wasmModule().then((mod) => {
console.info("Initializing WebAssembly module...")
init(mod).then(() => console.log("WebAssembly module ready!"))
wasmModule1().then((mod) => {
console.debug("Initializing WebAssembly module...")
init1({"module_or_path": mod})
});

function format(text) {
return format_raw(text);
return format_raw(text);
}

function determineOperationType(text) {
return determine_operation_type(text);
return determine_operation_type(text);
}

export { format, determineOperationType }

// LL-SPARQL-PARSER
import init2, { get_parse_tree } from 'll-sparql-parser';
import wasmModule2 from 'll-sparql-parser/ll_sparql_parser_bg.wasm'

wasmModule2().then((mod) => {
console.debug("Initializing WebAssembly module...")
init2({"module_or_path": mod})
});

function parse(text) {
return get_parse_tree(text);
}

export { format, determineOperationType, parse };
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-wasm": "^6.2.2",
"ll-sparql-parser": "^0.7.0",
"qlue-ls": "npm:qlue-ls-web@~0.5.3",
"rollup": "^4.26.0"
}
Expand Down