From 05053f62ea103fc11f55895ea6758487af7bfc9b Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 4 Jun 2022 15:13:13 -0400 Subject: [PATCH] Imporoved playground UI design --- docs/index.html | 28 ++++++++++--------- docs/index.js | 31 +++++++++++++++------ docs/native.wasm | Bin 414699 -> 414604 bytes docs/style.css | 69 ++++++++++++++++++++++++----------------------- peglib.h | 36 +++++++++++++++---------- 5 files changed, 95 insertions(+), 69 deletions(-) diff --git a/docs/index.html b/docs/index.html index 6703ee9..d39e937 100644 --- a/docs/index.html +++ b/docs/index.html @@ -8,33 +8,35 @@
    +
  • Grammar
  • -
  • Valid
{{syntax}}
    +
  • Source Code
  • -
  • Valid
  • +
  • +
      +
    • +
    • +
    • +
    +
{{source}}
-
-
-
-
    -
  • -
  • -
-
AST
+
AST

-    
Optimized AST     +
Optimized AST     mode: 

-    
Profile
-
+
Profile
+
+ +
diff --git a/docs/index.js b/docs/index.js index 9a02dc7..d85b46c 100644 --- a/docs/index.js +++ b/docs/index.js @@ -24,7 +24,7 @@ const code = setupEditorArea("code-editor", "codeText"); const codeAst = setupInfoArea("code-ast"); const codeAstOptimized = setupInfoArea("code-ast-optimized"); -const profile = setupInfoArea("profile"); +const codeProfile = setupInfoArea("code-profile"); $('#opt-mode').val(localStorage.getItem('optimazationMode') || 'all'); $('#packrat').prop('checked', localStorage.getItem('packrat') === 'true'); @@ -80,27 +80,26 @@ function parse() { $codeValidation.hide(); codeAst.setValue(''); codeAstOptimized.setValue(''); - profile.setValue(''); + codeProfile.setValue(''); if (grammarText.length === 0) { return; } const mode = optimazationMode == 'all'; - 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(); + $grammarValidation.removeClass('validation-invalid').show(); codeAst.insert(data.ast); codeAstOptimized.insert(data.astOptimized); - profile.insert(data.profile); + codeProfile.insert(data.profile); if (data.source_valid) { - $codeValidation.removeClass('editor-validation-invalid').text('Valid').show(); + $codeValidation.removeClass('validation-invalid').show(); } else { - $codeValidation.addClass('editor-validation-invalid').text('Invalid').show(); + $codeValidation.addClass('validation-invalid').show(); } if (data.code.length > 0) { @@ -108,7 +107,7 @@ function parse() { $codeInfo.html(html); } } else { - $grammarValidation.addClass('editor-validation-invalid').text('Invalid').show(); + $grammarValidation.addClass('validation-invalid').show(); } if (data.grammar.length > 0) { @@ -153,6 +152,22 @@ $('#auto-refresh').on('change', () => { }); $('#parse').on('click', parse); +// Show windows +function setupToolWindow(lsKeyName, buttonSel, codeSel) { + let show = localStorage.getItem(lsKeyName) === 'true'; + $(buttonSel).prop('checked', show); + $(codeSel).css({ 'display': show ? 'block' : 'none' }); + + $(buttonSel).on('change', () => { + show = !show; + localStorage.setItem(lsKeyName, show); + $(codeSel).css({ 'display': show ? 'block' : 'none' }); + }); +} +setupToolWindow('show-ast', '#show-ast', '#code-ast'); +setupToolWindow('show-ast-optimized', '#show-ast-optimized', '#code-ast-optimized'); +setupToolWindow('show-profile', '#show-profile', '#code-profile'); + // Show page $('#main').css({ 'display': 'flex', diff --git a/docs/native.wasm b/docs/native.wasm index dab6b6e82fa8e1154bc006182301dcbe7869fc57..b87a7ec990f974392c310c4c3b87565bab3cff4d 100755 GIT binary patch delta 3273 zcmaJ@Yjjn`6+U~N&1Zzbq;)A8tS_r6Ev_)5a6)WkUa}%pB^=7T?*?ac$ z+k0lt2Mq%@Gz@6}6>`e}p1cdk^%{ySpd%W(X>wCb?#2Ot?z8v{eNYm5{x-4QzGh#O z?-3Z-=xgw8V)eeHd!u;+jIM%4qrph8H|h*Ky$W_2wMKf4QSC8RMx~Ly)2Q&6a-+;h z-(hT5j9cut5XzHv!K{pZ@Hcpqzrp{?U*|5I;4kqP`78Woev)^%?+2H{@J48aIdkT; z;~j}a`nQ+{Xiz(C-VQOzRpG_h<+>NblR~gb^zH-a-F_LFnfwe_zoU?a3W5R6)||&LqgCJ@o4;63uAHCej=Xz9CR8N%E{}-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2s>xh5(={zh#Un}^Q)$D9af~_K2_;BQgY=FW^zzC`kYLt5XLhd}rC{gmK%#qn~B0f+BIaI{T!(KEd z$fEr}6m_C^yPB)nC+M5PB*Cerb5yb#WEGaU+F&I-5R-&r=h_NLOwxo38mYYo2gL46 zcth^kc!)#{T@}$xi5OD8Kty^l?nK3BPfW?sx}kzAUBKwSMKa z+vHRST*=GZP@`5zS`Mnl{4P!UQX*zo4y^Y@OUBLZn-9cW9p|nRgQRRgc4+{V$@+opdY#^z2Zpj*08c!57dr-?oS4sUAXCnB z+5YRGN{)DdaSK+-drMd^PWZ%3c2}6NbuN3B5f1wUYw9S@yu!lri=}M4PL(&8F$ZCz zeAQzw(3h%QxSl=8sMLoW*&mVck!qHkK}(eFV&jnTq-16UJVEwZ`Tkz^=m1zHE*)pj z%M0h(*6HdH?e`!<2QNwxn32{O94ecx)JiBd3o7X-hJ!~PLso=&(ud*~$l+ut}Wv`8#ADYUNA2(v?4DKmV!|eUBD@z{?E^KXsB9a}Z+4 xCwv`AclZ;2)*|;`zvg{LP}+a;^@a@k)YvdVUzSM^-1~8Ta95gtXpx?K@P7>~tMdQ= diff --git a/docs/style.css b/docs/style.css index 4232db7..ddf41e1 100644 --- a/docs/style.css +++ b/docs/style.css @@ -19,42 +19,54 @@ body { width: 100%; display: flex; flex-direction: column; - margin: 8px; + margin: 6px; } .editor-container:first-child { margin-right: 0; } .editor-header { display: flex; - height: 48px; - padding: 4px 8px; + margin: 0 2px; +} +.editor-header > li { + height: 32px; + line-height: 24px; } .editor-header > li > span { - height: 38px; - line-height: 38px; + margin-right: 6px; } -.editor-header > li > a { - height: 38px; - line-height: 38px; - padding: .3em .5em; - border: 1px solid red; -} -.editor-header > li.validation-indicator { +.editor-options { margin-left: auto; } -.editor-header.right-align { - margin-left: auto; +.editor-header-options { + display: flex; } -.editor-validation { - padding: 9px 11px; - color: green; +.validation { + display: inline-block; + height: 20px; + width: 20px; + margin: 2px 0; + border-radius: 50%; background-color: lightgreen; - border-radius: 5px; } -.editor-validation-invalid { - color: red; +.validation-invalid { background-color: pink; } +.option { + margin-right: 8px; +} +.option:last-child { + margin-right: 0; +} +.option input[type=checkbox] { + margin-right: 4px; +} +.option .parse { + padding-left: 8px; + padding-right: 8px; + height: 24px; + cursor: pointer; +} .editor-area { flex: 1; border: 1px solid lightgray; @@ -73,19 +85,8 @@ body { background-color: lightyellow; } .editor-sub-header { - padding: 4px 8px; + padding: 4px; } -.option { - margin-right: 12px; -} -.option:last-child { - margin-right: 0; -} -.option > span > * { - margin-right: 8px; -} -.option .parse { - cursor: pointer; - padding: 9px 11px; - margin-right: 0; +.show-toggle { + margin-right: 6px; } diff --git a/peglib.h b/peglib.h index facd906..05aa778 100644 --- a/peglib.h +++ b/peglib.h @@ -4548,32 +4548,40 @@ inline void enable_profiling(parser &parser, std::ostream &os) { } else { stat.fail++; } + if (index == 0) { - size_t id = 0; + char buff[BUFSIZ]; + + size_t total_success = 0; + size_t total_fail = 0; + for (auto &[name, success, fail] : stats.items) { + total_success += success; + total_fail += fail; + } + os << " id total % success fail " "definition" << std::endl; - size_t total_total, total_success = 0, total_fail = 0; - char buff[BUFSIZ]; + + auto grand_total = total_success + total_fail; + sprintf(buff, "%4s %10lu %5s %10lu %10lu %s", "", grand_total, + "", total_success, total_fail, "Total counters"); + os << buff << std::endl; + + sprintf(buff, "%4s %10s %5s %10.2f %10.2f %s", "", "", "", + total_success * 100.0 / grand_total, + total_fail * 100.0 / grand_total, "% success/fail"); + os << buff << std::endl; + + size_t id = 0; for (auto &[name, success, fail] : stats.items) { auto total = success + fail; - total_success += success; - total_fail += fail; auto ratio = total * 100.0 / stats.total; sprintf(buff, "%4zu %10lu %5.2f %10lu %10lu %s", id, total, ratio, success, fail, name.c_str()); os << buff << std::endl; id++; } - os << std::endl; - total_total = total_success + total_fail; - sprintf(buff, "%4s %10lu %5s %10lu %10lu %s", "", total_total, - "", total_success, total_fail, "Total counters"); - os << buff << std::endl; - sprintf(buff, "%4s %10s %5s %10.2f %10.2f %s", "", "", "", - total_success * 100.0 / total_total, - total_fail * 100.0 / total_total, "% success/fail"); - os << buff << std::endl; } } },