@Title
-
Visualization for CSLY with Viz.js
-
-
+
Visualization for CSLY with Viz.js
+
+
@@ -20,49 +16,75 @@
-
-
-
+
-
-
@code {
- [Parameter] public string? Title { get; set; }
+ // Demonstrates how a parent component can supply parameters
+ [Parameter]
+ public string? Title { get; set; }
+
+ string source = @"
- string source = @"1 / 2 / 3 + 4 + 3.14";
+while i < 10 do
+(
+ i := i + 1;
+ print ""hello""
+)";
string grammar = @"
-genericLexer ExprLexer;
-[Int] I;
-[Double] D;
+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 : ""-"";
@@ -71,23 +93,52 @@ genericLexer ExprLexer;
[Sugar] LPAREN : ""("";
[Sugar] RPAREN : "")"";
+[Sugar] SEMICOLON : "";"";
+parser WhileParser;
-parser ExprParser;
-
-
--> root: ExprParser_expressions ;
+[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;
-[Operand] operand : [I|D];
-[Operand] operand : LPAREN ExprParser_expressions RPAREN;
+[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;
";
@@ -97,154 +148,53 @@ parser ExprParser;
{
}
+// private StandaloneCodeEditor _grammar;
+// private StandaloneCodeEditor _source;
+
+
+
private async Task LoadGrammar(InputFileChangeEventArgs e)
{
- var content =
+
+ var content =
await new StreamReader(e.File.OpenReadStream()).ReadToEndAsync();
grammar = content;
- StateHasChanged();
+ //_grammar.SetValue(grammar);
}
-
- private async Task LoadSource(InputFileChangeEventArgs e)
+
+ private async Task LoadSource(InputFileChangeEventArgs e)
{
- var content =
+ var content =
await new StreamReader(e.File.OpenReadStream()).ReadToEndAsync();
source = content;
- StateHasChanged();
- }
-
-
- private async void GetJson()
- {
- var json = CslyProcessor.GetJson(grammar, source);
- if (json.IsOK)
- {
- string fileName = "source.json";
- string contentType = "text/json";
-
- // Check if the IJSRuntime is the WebAssembly implementation of the JSRuntime
- if (JSUnmarshalledRuntime is IJSUnmarshalledRuntime webAssemblyJSRuntime)
- {
- webAssemblyJSRuntime.InvokeUnmarshalled