A parsing engine
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Enable web worker and add spinner

+70 -36
+33 -36
gearley-wasm/vite/src/App.vue
··· 40 40 <div id="full-editor"></div> 41 41 </div> 42 42 <div class="right-box"> 43 + <ProgressSpinner v-show="isLoading"></ProgressSpinner> 43 44 <Result /> 44 45 </div> 45 46 </div> 46 47 </div> 47 48 <Dialog v-model:visible="helpVisible" modal header="Help" class="help-dialog"> 48 49 <p> 49 - With the two dropdowns visible in the bar, 50 - you may load any of the builtin examples. 51 - Each example is available only for the chosen 52 - lexer listed as "mode". The "basic" lexer is 53 - a crude mode for accepting input as a space-separated 54 - list of terminal symbol names. The "advanced" lexer 55 - permits regexps and strings, so that the grammar 56 - is in so-called "scannerless mode". 50 + With the two dropdowns in the top bar, you can load any of the 51 + built-in examples. Each example is available only for the lexer 52 + selected as <i>mode</i>. The <i>basic</i> lexer accepts input as a 53 + space-separated list of terminal symbol names. The <i>advanced</i> 54 + lexer supports regular expressions and strings, allowing the grammar 55 + to run in scannerless mode. 57 56 </p> 57 + 58 58 <p> 59 - The purpose of limiting lines is to avoid having too many components 60 - to process and display for huge inputs. The default limit is 10000 lines. 59 + Line limits are used to prevent excessive processing and rendering 60 + for very large inputs. The default limit is 10,000 lines. 61 61 </p> 62 + 62 63 <p> 63 - To the left, you can see an editor. This editor provides the string 64 - to parse within the HTML-like "input" tag 65 - (keep in mind - it does not trim whitespace). 66 - Likewise, the grammar is provided within the "grammar" tag. 67 - Check out our examples for more. 64 + On the left, you’ll see an editor. This editor provides the string 65 + to be parsed inside the HTML-like input tag (note that whitespace is 66 + not trimmed). Similarly, the grammar is defined inside the grammar 67 + tag. See the examples for more details. 68 68 </p> 69 + 69 70 <p> 70 - To the right, you have a number of tabs to choose from. 71 - Each tab is named after a grammar transformation or parsing step. 72 - It shows all the information logged by that step. 73 - That way, you can see the inner workings of gearley. 71 + On the right, several tabs are available. Each tab corresponds to a 72 + grammar transformation or parsing step and displays the information 73 + logged at that stage. This makes it possible to explore the internal 74 + workings of Gearley. 74 75 </p> 76 + 75 77 <p> 76 - In the top bar, you may also click on the links to visit our github repositories. 78 + Finally, the top bar also contains links to our GitHub repositories. 77 79 </p> 78 80 </Dialog> 79 81 </template> ··· 82 84 import Result from './Result.vue' 83 85 import Dialog from 'primevue/dialog' 84 86 import Button from 'primevue/button' 87 + import ProgressSpinner from 'primevue/progressspinner' 85 88 import '@/assets/ace-builds' 86 89 import { ref, computed, onMounted, watch } from 'vue' 87 - import { getGrammars, getExamples, parse } from "@/assets/pkg/gearley_wasm.js"; 90 + import { getGrammars, getExamples } from "@/assets/pkg/gearley_wasm.js"; 88 91 import { useParse } from '@/stores/parse' 92 + import Worker from '@/worker/parse?worker' 89 93 90 94 const parseStore = useParse() 95 + const ParseWorker = new Worker() 91 96 ace.config.set('basePath', 'ace-builds/src-noconflict/') 92 97 93 98 let editor = null 94 99 const selectedMode = ref('advanced') 95 100 const typingTimer = ref(null) 96 101 const typing = ref(false) 102 + const isLoading = ref(false) 97 103 const loadModes = [ 98 104 'advanced', 99 105 'basic', ··· 158 164 return 159 165 } 160 166 161 - function parseWithWasm(input, grammar, mode) { 162 - if (loadModes.find((m) => m === mode)) { 163 - return parse(input, grammar, mode) 164 - } else { 165 - return 'Unknown mode' 166 - } 167 - } 167 + isLoading.value = true 168 + ParseWorker.postMessage([matchedInput[1], matchedGrammar[1], selectedMode.value]) 169 + } 168 170 169 - let result = '' 170 - try { 171 - result = parseWithWasm(matchedInput[1], matchedGrammar[1], selectedMode.value); 172 - } catch (e) { 173 - console.error(e) 174 - result = "Caught\n" + e.message; 175 - } 176 - parseStore.setResult(result) 171 + ParseWorker.onmessage = (event) => { 172 + isLoading.value = false 173 + parseStore.setResult(event.data) 177 174 } 178 175 179 176 watch(selectedExample, () => {
+37
gearley-wasm/vite/src/worker/parse.js
··· 1 + import init, { parse } from "@/assets/pkg/gearley_wasm.js"; 2 + 3 + const loadModes = [ 4 + 'advanced', 5 + 'basic', 6 + 'c-lexer' 7 + ] 8 + 9 + function parseWithWasm(input, grammar, mode) { 10 + if (loadModes.find((m) => m === mode)) { 11 + return parse(input, grammar, mode) 12 + } else { 13 + return 'Unknown mode' 14 + } 15 + } 16 + 17 + async function init_wasm_in_worker() { 18 + console.log('Initializing worker'); 19 + 20 + // Load the wasm file by awaiting the Promise returned by `wasm_bindgen`. 21 + await init(); 22 + console.log('Worker intialized'); 23 + 24 + // Set callback to handle messages passed to the worker. 25 + self.onmessage = async ({ data }) => { 26 + let result = '' 27 + try { 28 + result = parseWithWasm(data[0], data[1], data[2]); 29 + } catch (e) { 30 + console.error(e) 31 + result = "Caught\n" + e.message; 32 + } 33 + postMessage(result) 34 + } 35 + }; 36 + 37 + init_wasm_in_worker();