···4040 <div id="full-editor"></div>
4141 </div>
4242 <div class="right-box">
4343+ <ProgressSpinner v-show="isLoading"></ProgressSpinner>
4344 <Result />
4445 </div>
4546 </div>
4647 </div>
4748 <Dialog v-model:visible="helpVisible" modal header="Help" class="help-dialog">
4849 <p>
4949- With the two dropdowns visible in the bar,
5050- you may load any of the builtin examples.
5151- Each example is available only for the chosen
5252- lexer listed as "mode". The "basic" lexer is
5353- a crude mode for accepting input as a space-separated
5454- list of terminal symbol names. The "advanced" lexer
5555- permits regexps and strings, so that the grammar
5656- is in so-called "scannerless mode".
5050+ With the two dropdowns in the top bar, you can load any of the
5151+ built-in examples. Each example is available only for the lexer
5252+ selected as <i>mode</i>. The <i>basic</i> lexer accepts input as a
5353+ space-separated list of terminal symbol names. The <i>advanced</i>
5454+ lexer supports regular expressions and strings, allowing the grammar
5555+ to run in scannerless mode.
5756 </p>
5757+5858 <p>
5959- The purpose of limiting lines is to avoid having too many components
6060- to process and display for huge inputs. The default limit is 10000 lines.
5959+ Line limits are used to prevent excessive processing and rendering
6060+ for very large inputs. The default limit is 10,000 lines.
6161 </p>
6262+6263 <p>
6363- To the left, you can see an editor. This editor provides the string
6464- to parse within the HTML-like "input" tag
6565- (keep in mind - it does not trim whitespace).
6666- Likewise, the grammar is provided within the "grammar" tag.
6767- Check out our examples for more.
6464+ On the left, you’ll see an editor. This editor provides the string
6565+ to be parsed inside the HTML-like input tag (note that whitespace is
6666+ not trimmed). Similarly, the grammar is defined inside the grammar
6767+ tag. See the examples for more details.
6868 </p>
6969+6970 <p>
7070- To the right, you have a number of tabs to choose from.
7171- Each tab is named after a grammar transformation or parsing step.
7272- It shows all the information logged by that step.
7373- That way, you can see the inner workings of gearley.
7171+ On the right, several tabs are available. Each tab corresponds to a
7272+ grammar transformation or parsing step and displays the information
7373+ logged at that stage. This makes it possible to explore the internal
7474+ workings of Gearley.
7475 </p>
7676+7577 <p>
7676- In the top bar, you may also click on the links to visit our github repositories.
7878+ Finally, the top bar also contains links to our GitHub repositories.
7779 </p>
7880 </Dialog>
7981</template>
···8284import Result from './Result.vue'
8385import Dialog from 'primevue/dialog'
8486import Button from 'primevue/button'
8787+import ProgressSpinner from 'primevue/progressspinner'
8588import '@/assets/ace-builds'
8689import { ref, computed, onMounted, watch } from 'vue'
8787-import { getGrammars, getExamples, parse } from "@/assets/pkg/gearley_wasm.js";
9090+import { getGrammars, getExamples } from "@/assets/pkg/gearley_wasm.js";
8891import { useParse } from '@/stores/parse'
9292+import Worker from '@/worker/parse?worker'
89939094const parseStore = useParse()
9595+const ParseWorker = new Worker()
9196ace.config.set('basePath', 'ace-builds/src-noconflict/')
92979398let editor = null
9499const selectedMode = ref('advanced')
95100const typingTimer = ref(null)
96101const typing = ref(false)
102102+const isLoading = ref(false)
97103const loadModes = [
98104 'advanced',
99105 'basic',
···158164 return
159165 }
160166161161- function parseWithWasm(input, grammar, mode) {
162162- if (loadModes.find((m) => m === mode)) {
163163- return parse(input, grammar, mode)
164164- } else {
165165- return 'Unknown mode'
166166- }
167167- }
167167+ isLoading.value = true
168168+ ParseWorker.postMessage([matchedInput[1], matchedGrammar[1], selectedMode.value])
169169+}
168170169169- let result = ''
170170- try {
171171- result = parseWithWasm(matchedInput[1], matchedGrammar[1], selectedMode.value);
172172- } catch (e) {
173173- console.error(e)
174174- result = "Caught\n" + e.message;
175175- }
176176- parseStore.setResult(result)
171171+ParseWorker.onmessage = (event) => {
172172+ isLoading.value = false
173173+ parseStore.setResult(event.data)
177174}
178175179176watch(selectedExample, () => {
+37
gearley-wasm/vite/src/worker/parse.js
···11+import init, { parse } from "@/assets/pkg/gearley_wasm.js";
22+33+const loadModes = [
44+ 'advanced',
55+ 'basic',
66+ 'c-lexer'
77+]
88+99+function parseWithWasm(input, grammar, mode) {
1010+ if (loadModes.find((m) => m === mode)) {
1111+ return parse(input, grammar, mode)
1212+ } else {
1313+ return 'Unknown mode'
1414+ }
1515+}
1616+1717+async function init_wasm_in_worker() {
1818+ console.log('Initializing worker');
1919+2020+ // Load the wasm file by awaiting the Promise returned by `wasm_bindgen`.
2121+ await init();
2222+ console.log('Worker intialized');
2323+2424+ // Set callback to handle messages passed to the worker.
2525+ self.onmessage = async ({ data }) => {
2626+ let result = ''
2727+ try {
2828+ result = parseWithWasm(data[0], data[1], data[2]);
2929+ } catch (e) {
3030+ console.error(e)
3131+ result = "Caught\n" + e.message;
3232+ }
3333+ postMessage(result)
3434+}
3535+};
3636+3737+init_wasm_in_worker();