-
-
-
-
-
-
+
Visualization for C#, Blazor interop wrapper for Viz.js
+
Viz.js, Emscripten version of Graphviz: https://github.com/mdaines/viz.js
+
svg-pan-zoom.js, pan/zoom for HTML SVG: https://github.com/ariutta/svg-pan-zoom
+
Demo is visualization of C# Syntax, used Roslyn CSharpSyntaxWalker to generate Graphviz DOT language file
+
Expression to process:
+
+
-
@code {
@@ -44,175 +33,33 @@
[Parameter]
public string? Title { get; set; }
- string source = @"
-
-while i < 10 do
-(
- i := i + 1;
- print ""hello""
-)";
-
- string grammar = @"
-
-genericLexer WhileLexer;
-
-[String] STRING;
-[Int] INT;
-[AlphaId] ID;
-
-
-[ KeyWord] IF:""if"";
-[ KeyWord] THEN:""then"";
-[ KeyWord] ELSE:""else"";
-[ KeyWord] WHILE:""while"";
-[ KeyWord] DO:""do"";
-[ KeyWord] SKIP:""skip"";
-[ KeyWord] TRUE:""true"";
-[ KeyWord] FALSE:""false"";
-[ KeyWord] NOT:""not"";
-[ KeyWord] AND:""and"";
-[ KeyWord] OR:""or"";
-[ KeyWord] PRINT:""print"";
-
- [Sugar] GREATER : "">"";
-
-[Sugar] LESSER : ""<"";
-
-[Sugar] EQUALS : ""=="";
-
-[Sugar] DIFFERENT : ""!="";
-
-[Sugar] CONCAT : ""."";
-
-[Sugar] ASSIGN : "":="";
-
-[Sugar] PLUS : ""+"";
-[Sugar] MINUS : ""-"";
-[Sugar] TIMES : ""*"";
-[Sugar] DIVIDE : ""/"";
-
-[Sugar] LPAREN : ""("";
-[Sugar] RPAREN : "")"";
-[Sugar] SEMICOLON : "";"";
-
-parser WhileParser;
-
-
-[Right 50] LESSER;
-[Right 50] GREATER;
-[Right 50] EQUALS;
-[Right 50]DIFFERENT;
-
-[Right 10] CONCAT;
-
-[Right 10] PLUS;
-[Left 10] MINUS;
-[Right 50] TIMES;
-[Left 50]DIVIDE;
-
-[Prefix 100] MINUS;
+ private string expression;
-[Right 10] OR;
-[Right 50] AND;
-[Prefix 100] NOT;
-
-
--> statement : LPAREN statement RPAREN ;
-
-
-statement : sequence;
-
-
-[Operand] operand : [INT | TRUE | FALSE | STRING | ID];
-[Operand] operand : LPAREN WhileParser_expressions RPAREN;
-
-sequence : [statementIf | statementWhile | statementAssign | statementSkip | statementPrint] additionalStatements*;
-
-additionalStatements : SEMICOLON [statementIf | statementWhile | statementAssign | statementSkip | statementPrint];
-
-statementIf: IF WhileParser_expressions THEN statement ELSE statement;
-
-statementWhile: WHILE WhileParser_expressions DO statement;
-
-statementAssign: ID ASSIGN WhileParser_expressions;
-
-statementSkip: SKIP;
-
-statementPrint: PRINT WhileParser_expressions;
-
-";
-
- private string dot;
+ private Processing processing = new Processing();
protected override async void OnInitialized()
{
+ expression = "a = x + y * 5 / 4* (56 + 1);";
}
-// private StandaloneCodeEditor _grammar;
-// private StandaloneCodeEditor _source;
-
-
-
- private async Task LoadGrammar(InputFileChangeEventArgs e)
- {
-
- var content =
- await new StreamReader(e.File.OpenReadStream()).ReadToEndAsync();
- grammar = content;
- //_grammar.SetValue(grammar);
- }
-
- private async Task LoadSource(InputFileChangeEventArgs e)
- {
- var content =
- await new StreamReader(e.File.OpenReadStream()).ReadToEndAsync();
- source = content;
- //_source.SetValue(source);
- }
- // private StandaloneEditorConstructionOptions GrammarConstructionOptions(StandaloneCodeEditor editor)
- // {
- //
- // return new StandaloneEditorConstructionOptions
- // {
- // AutomaticLayout = true,
- // Value = grammar
- // };
- // }
-
- // private StandaloneEditorConstructionOptions InputConstructionOptions(StandaloneCodeEditor editor)
- // {
- // return new StandaloneEditorConstructionOptions
- // {
- // AutomaticLayout = true,
- // Value = source
- // };
- // }
-
private async void Render()
{
+ processing.Parse(expression);
- // grammar = await _grammar.GetValue();
- // source = await _source.GetValue();
-
- var dotresult = CslyProcessor.GetDot(grammar, source);
- if (dotresult.IsOK)
+ if(processing.HasErrors())
{
- dot = dotresult.Result;
- await VizRender(dot);
+ await AppendError(processing.Errors);
}
else
{
- foreach (var error in dotresult.Errors)
- {
- AppendError(error);
- }
+ await VizRender(processing.GraphvizText);
}
}
- public async Task VizRender(string graph)
+ public async Task VizRender(string ast)
{
- await JSRuntime.InvokeAsync
("vizRender",graph);
+ await JSRuntime.InvokeAsync("vizRender",ast);
}
public async Task AppendError(string errorMessage)
diff --git a/BlazorVizView/_Imports.razor b/BlazorVizView/_Imports.razor
index 8a2b4af..fdb762e 100644
--- a/BlazorVizView/_Imports.razor
+++ b/BlazorVizView/_Imports.razor
@@ -8,7 +8,4 @@
@using Microsoft.JSInterop
@using BlazorVizView
@using BlazorVizView.Shared
-@using csly_cli_api
-@using BlazorMonaco
-@using BlazorMonaco.Editor
-@using BlazorMonaco.Languages
\ No newline at end of file
+@using DummyClassLibrary
\ No newline at end of file
diff --git a/BlazorVizView/wwwroot/css/app.css b/BlazorVizView/wwwroot/css/app.css
index 8a75c0a..bbe87ab 100644
--- a/BlazorVizView/wwwroot/css/app.css
+++ b/BlazorVizView/wwwroot/css/app.css
@@ -42,13 +42,6 @@ a, .btn-link {
margin-bottom: 10px;
font-family: Consolas, 'Courier New', monospace;
}
-#grammarBox {
- width: 100%;
- height: 150px;
- text-wrap: normal;
- margin-bottom: 10px;
- font-family: Consolas, 'Courier New', monospace;
-}
#submitButton {
margin-bottom: 10px;
diff --git a/BlazorVizView/wwwroot/index.html b/BlazorVizView/wwwroot/index.html
index ca305e4..b215357 100644
--- a/BlazorVizView/wwwroot/index.html
+++ b/BlazorVizView/wwwroot/index.html
@@ -17,18 +17,11 @@
Reload
🗙