diff --git a/docs/index.js b/docs/index.js
index e4eba47..9a02dc7 100644
--- a/docs/index.js
+++ b/docs/index.js
@@ -26,7 +26,10 @@ const codeAst = setupInfoArea("code-ast");
const codeAstOptimized = setupInfoArea("code-ast-optimized");
const profile = setupInfoArea("profile");
-$('#opt_mode').val(localStorage.getItem('optimazationMode') || 'all');
+$('#opt-mode').val(localStorage.getItem('optimazationMode') || 'all');
+$('#packrat').prop('checked', localStorage.getItem('packrat') === 'true');
+$('#auto-refresh').prop('checked', localStorage.getItem('autoRefresh') === 'true');
+$('#parse').prop('disabled', $('#auto-refresh').prop('checked'));
// Parse
function escapeHtml(unsafe) {
@@ -50,6 +53,14 @@ function generateErrorListHTML(errors) {
return html;
}
+function updateLocalStorage() {
+ localStorage.setItem('grammarText', grammar.getValue());
+ localStorage.setItem('codeText', code.getValue());
+ localStorage.setItem('optimazationMode', $('#opt-mode').val());
+ localStorage.setItem('packrat', $('#packrat').prop('checked'));
+ localStorage.setItem('autoRefresh', $('#auto-refresh').prop('checked'));
+}
+
function parse() {
const $grammarValidation = $('#grammar-validation');
const $grammarInfo = $('#grammar-info');
@@ -59,11 +70,9 @@ function parse() {
const $codeInfo = $('#code-info');
const codeText = code.getValue();
- const optimazationMode = $('#opt_mode').val();
-
- localStorage.setItem('grammarText', grammarText);
- localStorage.setItem('codeText', codeText);
- localStorage.setItem('optimazationMode', optimazationMode);
+ const optimazationMode = $('#opt-mode').val();
+ const packrat = $('#packrat').prop('checked');
+ const autoRefresh = $('#auto-refresh').prop('checked');
$grammarInfo.html('');
$grammarValidation.hide();
@@ -78,7 +87,8 @@ function parse() {
}
const mode = optimazationMode == 'all';
- const data = JSON.parse(Module.lint(grammarText, codeText, mode));
+ console.log({packrat});
+ const data = JSON.parse(Module.lint(grammarText, codeText, mode, packrat));
if (data.grammar_valid) {
$grammarValidation.removeClass('editor-validation-invalid').text('Valid').show();
@@ -111,7 +121,12 @@ function parse() {
let timer;
function setupTimer() {
clearTimeout(timer);
- timer = setTimeout(parse, 750);
+ timer = setTimeout(() => {
+ updateLocalStorage();
+ if ($('#auto-refresh').prop('checked')) {
+ parse();
+ }
+ }, 750);
};
grammar.getSession().on('change', setupTimer);
code.getSession().on('change', setupTimer);
@@ -129,7 +144,14 @@ $('#grammar-info').on('click', 'li', makeOnClickInInfo(grammar));
$('#code-info').on('click', 'li', makeOnClickInInfo(code));
// Event handing in the AST optimazation
-$('#opt_mode').on('change', setupTimer);
+$('#opt-mode').on('change', setupTimer);
+$('#packrat').on('change', setupTimer);
+$('#auto-refresh').on('change', () => {
+ updateLocalStorage();
+ $('#parse').prop('disabled', $('#auto-refresh').prop('checked'));
+ setupTimer();
+});
+$('#parse').on('click', parse);
// Show page
$('#main').css({
diff --git a/docs/native.cpp b/docs/native.cpp
index 04d4f1b..1774f51 100644
--- a/docs/native.cpp
+++ b/docs/native.cpp
@@ -54,7 +54,7 @@ bool parse_code(const std::string &text, peg::parser &peg, std::string &json,
return ret;
}
-std::string lint(const std::string &grammarText, const std::string &codeText, bool opt_mode) {
+std::string lint(const std::string &grammarText, const std::string &codeText, bool opt_mode, bool packrat) {
std::string grammarResult;
std::string codeResult;
std::string astResult;
@@ -69,6 +69,10 @@ std::string lint(const std::string &grammarText, const std::string &codeText, bo
std::stringstream ss;
peg::enable_profiling(peg, ss);
+ if (packrat) {
+ peg.enable_packrat_parsing();
+ }
+
std::shared_ptr
ast;
is_source_valid = parse_code(codeText, peg, codeResult, ast);
diff --git a/docs/native.wasm b/docs/native.wasm
index b85a586..dab6b6e 100755
Binary files a/docs/native.wasm and b/docs/native.wasm differ
diff --git a/docs/style.css b/docs/style.css
index c4e3a6b..0509dea 100644
--- a/docs/style.css
+++ b/docs/style.css
@@ -29,9 +29,6 @@ body {
height: 48px;
padding: 4px 8px;
}
-.editor-header > li:last-child {
- margin-left: auto;
-}
.editor-header > li > span {
height: 38px;
line-height: 38px;
@@ -42,6 +39,9 @@ body {
padding: .3em .5em;
border: 1px solid red;
}
+.editor-header > li.validation-indicator {
+ margin-left: auto;
+}
.editor-validation {
padding: 9px 11px;
color: green;
@@ -72,3 +72,13 @@ body {
.editor-sub-header {
padding: 4px 8px;
}
+.option {
+ margin-right: 12px;
+}
+.option > span > * {
+ margin-right: 8px;
+}
+.option .parse {
+ cursor: pointer;
+ padding: 9px 11px;
+}