Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
zilf
zilf
Commits
6f324040930f
Commit
84e08b62
authored
Dec 10, 2020
by
Jesse McGrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on Blazor REPL and project editor
parent
c1a62e02fdc6
Changes
72
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
72 changed files
with
23058 additions
and
375 deletions
+23058
-375
Zilf.sln
Zilf.sln
+1
-1
src/Analyzers/ZilfAnalyzers.Test/ZilfAnalyzers.Test.csproj
src/Analyzers/ZilfAnalyzers.Test/ZilfAnalyzers.Test.csproj
+1
-1
src/Analyzers/ZilfAnalyzers/ErrorExceptionUsageAnalyzer.cs
src/Analyzers/ZilfAnalyzers/ErrorExceptionUsageAnalyzer.cs
+2
-2
src/Analyzers/ZilfAnalyzers/ErrorExceptionUsageCodeFixProvider.cs
...yzers/ZilfAnalyzers/ErrorExceptionUsageCodeFixProvider.cs
+6
-1
src/Analyzers/ZilfAnalyzers/MessageConstantAnalyzer.cs
src/Analyzers/ZilfAnalyzers/MessageConstantAnalyzer.cs
+1
-1
src/Analyzers/ZilfAnalyzers/MessageConstantCodeFixProvider.cs
...Analyzers/ZilfAnalyzers/MessageConstantCodeFixProvider.cs
+2
-1
src/Analyzers/ZilfAnalyzers/ZilfAnalyzers.csproj
src/Analyzers/ZilfAnalyzers/ZilfAnalyzers.csproj
+1
-1
src/Zilf.Playground/JSInterop.cs
src/Zilf.Playground/JSInterop.cs
+42
-0
src/Zilf.Playground/Pages/Documentation.razor
src/Zilf.Playground/Pages/Documentation.razor
+8
-0
src/Zilf.Playground/Pages/Index.razor
src/Zilf.Playground/Pages/Index.razor
+50
-152
src/Zilf.Playground/Pages/OldIndex.razor
src/Zilf.Playground/Pages/OldIndex.razor
+175
-0
src/Zilf.Playground/Pages/ProjectEdit.razor
src/Zilf.Playground/Pages/ProjectEdit.razor
+53
-0
src/Zilf.Playground/Pages/ProjectNew.razor
src/Zilf.Playground/Pages/ProjectNew.razor
+45
-0
src/Zilf.Playground/Pages/Repl.razor
src/Zilf.Playground/Pages/Repl.razor
+103
-0
src/Zilf.Playground/Program.cs
src/Zilf.Playground/Program.cs
+13
-0
src/Zilf.Playground/Services/Builds/BuildService.cs
src/Zilf.Playground/Services/Builds/BuildService.cs
+109
-0
src/Zilf.Playground/Services/Repl/ReplService.cs
src/Zilf.Playground/Services/Repl/ReplService.cs
+55
-0
src/Zilf.Playground/Services/Templates/JsonModel.cs
src/Zilf.Playground/Services/Templates/JsonModel.cs
+46
-0
src/Zilf.Playground/Services/Templates/TemplateService.cs
src/Zilf.Playground/Services/Templates/TemplateService.cs
+111
-0
src/Zilf.Playground/Services/Workspaces/Project.cs
src/Zilf.Playground/Services/Workspaces/Project.cs
+93
-0
src/Zilf.Playground/Services/Workspaces/ProjectFile.cs
src/Zilf.Playground/Services/Workspaces/ProjectFile.cs
+16
-0
src/Zilf.Playground/Services/Workspaces/WorkspaceService.cs
src/Zilf.Playground/Services/Workspaces/WorkspaceService.cs
+55
-0
src/Zilf.Playground/Shared/BuildBadge.razor
src/Zilf.Playground/Shared/BuildBadge.razor
+25
-0
src/Zilf.Playground/Shared/CompilerOutput.razor
src/Zilf.Playground/Shared/CompilerOutput.razor
+2
-3
src/Zilf.Playground/Shared/ContainerlessLayout.razor
src/Zilf.Playground/Shared/ContainerlessLayout.razor
+19
-0
src/Zilf.Playground/Shared/MainLayout.razor
src/Zilf.Playground/Shared/MainLayout.razor
+2
-9
src/Zilf.Playground/Shared/MainLayout.razor.css
src/Zilf.Playground/Shared/MainLayout.razor.css
+0
-70
src/Zilf.Playground/Shared/Modal.razor
src/Zilf.Playground/Shared/Modal.razor
+81
-0
src/Zilf.Playground/Shared/ModalButton.razor
src/Zilf.Playground/Shared/ModalButton.razor
+31
-0
src/Zilf.Playground/Shared/NavMenu.razor
src/Zilf.Playground/Shared/NavMenu.razor
+15
-34
src/Zilf.Playground/Shared/NavMenu.razor.css
src/Zilf.Playground/Shared/NavMenu.razor.css
+0
-62
src/Zilf.Playground/Shared/NavMenuItem.razor
src/Zilf.Playground/Shared/NavMenuItem.razor
+23
-0
src/Zilf.Playground/Shared/ProjectBadge.razor
src/Zilf.Playground/Shared/ProjectBadge.razor
+16
-0
src/Zilf.Playground/Shared/ProjectLayout.razor
src/Zilf.Playground/Shared/ProjectLayout.razor
+123
-0
src/Zilf.Playground/Shared/ProjectRoot.razor
src/Zilf.Playground/Shared/ProjectRoot.razor
+16
-0
src/Zilf.Playground/Shared/ProjectSidebar.razor
src/Zilf.Playground/Shared/ProjectSidebar.razor
+62
-0
src/Zilf.Playground/Shared/ProjectSidebarFileGroup.razor
src/Zilf.Playground/Shared/ProjectSidebarFileGroup.razor
+34
-0
src/Zilf.Playground/Shared/ProjectSidebarFileLink.razor
src/Zilf.Playground/Shared/ProjectSidebarFileLink.razor
+33
-0
src/Zilf.Playground/Shared/ProjectTemplateCard.razor
src/Zilf.Playground/Shared/ProjectTemplateCard.razor
+46
-0
src/Zilf.Playground/Shared/ProjectTemplateCard.razor.css
src/Zilf.Playground/Shared/ProjectTemplateCard.razor.css
+15
-0
src/Zilf.Playground/Shared/ReplBadge.razor
src/Zilf.Playground/Shared/ReplBadge.razor
+25
-0
src/Zilf.Playground/Zilf.Playground.csproj
src/Zilf.Playground/Zilf.Playground.csproj
+7
-4
src/Zilf.Playground/_Imports.razor
src/Zilf.Playground/_Imports.razor
+5
-0
src/Zilf.Playground/wwwroot/css/app.css
src/Zilf.Playground/wwwroot/css/app.css
+8
-8
src/Zilf.Playground/wwwroot/css/bootstrap/bootstrap.min.css
src/Zilf.Playground/wwwroot/css/bootstrap/bootstrap.min.css
+0
-7
src/Zilf.Playground/wwwroot/css/bootstrap/bootstrap.min.css.map
...lf.Playground/wwwroot/css/bootstrap/bootstrap.min.css.map
+0
-1
src/Zilf.Playground/wwwroot/index.html
src/Zilf.Playground/wwwroot/index.html
+18
-5
src/Zilf.Playground/wwwroot/interop.js
src/Zilf.Playground/wwwroot/interop.js
+39
-3
src/Zilf.Playground/wwwroot/project_templates/advent/advent.svg
...lf.Playground/wwwroot/project_templates/advent/advent.svg
+117
-0
src/Zilf.Playground/wwwroot/project_templates/advent/advent.zil
...lf.Playground/wwwroot/project_templates/advent/advent.zil
+4762
-0
src/Zilf.Playground/wwwroot/project_templates/advent/hints.zil
...ilf.Playground/wwwroot/project_templates/advent/hints.zil
+135
-0
src/Zilf.Playground/wwwroot/project_templates/beer/beer.zil
src/Zilf.Playground/wwwroot/project_templates/beer/beer.zil
+27
-0
src/Zilf.Playground/wwwroot/project_templates/cloak/cloak.svg
...Zilf.Playground/wwwroot/project_templates/cloak/cloak.svg
+9795
-0
src/Zilf.Playground/wwwroot/project_templates/cloak/cloak.zil
...Zilf.Playground/wwwroot/project_templates/cloak/cloak.zil
+105
-0
src/Zilf.Playground/wwwroot/project_templates/empty/empty.svg
...Zilf.Playground/wwwroot/project_templates/empty/empty.svg
+276
-0
src/Zilf.Playground/wwwroot/project_templates/empty/empty.zil
...Zilf.Playground/wwwroot/project_templates/empty/empty.zil
+28
-0
src/Zilf.Playground/wwwroot/project_templates/hello/hello.zil
...Zilf.Playground/wwwroot/project_templates/hello/hello.zil
+5
-0
src/Zilf.Playground/wwwroot/project_templates/project-templates-schema.json
...d/wwwroot/project_templates/project-templates-schema.json
+70
-0
src/Zilf.Playground/wwwroot/project_templates/project_templates.json
...ayground/wwwroot/project_templates/project_templates.json
+89
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/LICENSE.txt
...f.Playground/wwwroot/project_templates/zillib/LICENSE.txt
+32
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/events.zil
...lf.Playground/wwwroot/project_templates/zillib/events.zil
+148
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/orphan.zil
...lf.Playground/wwwroot/project_templates/zillib/orphan.zil
+168
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/parser.zil
...lf.Playground/wwwroot/project_templates/zillib/parser.zil
+3115
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/pronouns.zil
....Playground/wwwroot/project_templates/zillib/pronouns.zil
+150
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/pseudo.zil
...lf.Playground/wwwroot/project_templates/zillib/pseudo.zil
+224
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/scope.zil
...ilf.Playground/wwwroot/project_templates/zillib/scope.zil
+232
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/template.zil
....Playground/wwwroot/project_templates/zillib/template.zil
+138
-0
src/Zilf.Playground/wwwroot/project_templates/zillib/verbs.zil
...ilf.Playground/wwwroot/project_templates/zillib/verbs.zil
+1714
-0
src/Zilf.Playground/wwwroot/zilf-logo-transparent.png
src/Zilf.Playground/wwwroot/zilf-logo-transparent.png
+0
-0
src/Zilf.Playground/wwwroot/zilf-logo.png
src/Zilf.Playground/wwwroot/zilf-logo.png
+0
-0
src/Zilf/Compiler/FrontEnd.cs
src/Zilf/Compiler/FrontEnd.cs
+94
-8
test/Zilf.Emit.Tests/Zilf.Emit.Tests.csproj
test/Zilf.Emit.Tests/Zilf.Emit.Tests.csproj
+1
-1
No files found.
Zilf.sln
View file @
6f324040
...
...
@@ -66,7 +66,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Package", "Package", "{3E28
Package\zip\Zip.Packaging.targets = Package\zip\Zip.Packaging.targets
EndProjectSection
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Zilf.Common.Tests", "test\Zilf.Common.Tests\Zilf.Common.Tests.csproj", "{337F098C-4DD4-420D-825C-4A40DF99AD89}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Zilf.Common.Tests", "test\Zilf.Common.Tests\Zilf.Common.Tests.csproj", "{337F098C-4DD4-420D-825C-4A40DF99AD89}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zilf.Playground", "src\Zilf.Playground\Zilf.Playground.csproj", "{D38CAE84-836D-416D-83F6-DE2F2502658C}"
EndProject
...
...
src/Analyzers/ZilfAnalyzers.Test/ZilfAnalyzers.Test.csproj
View file @
6f324040
...
...
@@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="JunitXml.TestLogger" Version="2.1.78" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.
7
.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.
8
.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.9.1025">
<PrivateAssets>all</PrivateAssets>
...
...
src/Analyzers/ZilfAnalyzers/ErrorExceptionUsageAnalyzer.cs
View file @
6f324040
...
...
@@ -116,7 +116,7 @@ namespace ZilfAnalyzers
// has a constant value?
var
constantValue
=
semanticModel
.
GetConstantValue
(
expressionToReplace
);
if
(
constantValue
.
HasValue
)
if
(
constantValue
.
HasValue
&&
constantValue
.
Value
!=
null
)
{
format
=
(
string
)
constantValue
.
Value
;
newArgs
=
ImmutableList
<
ExpressionSyntax
>.
Empty
;
...
...
@@ -178,7 +178,7 @@ namespace ZilfAnalyzers
var
formatConstValue
=
semanticModel
.
GetConstantValue
(
formatExpr
);
if
(!
formatConstValue
.
HasValue
)
if
(!
formatConstValue
.
HasValue
||
formatConstValue
.
Value
==
null
)
return
false
;
formatStr
=
(
string
)
formatConstValue
.
Value
;
...
...
src/Analyzers/ZilfAnalyzers/ErrorExceptionUsageCodeFixProvider.cs
View file @
6f324040
...
...
@@ -142,9 +142,13 @@ namespace ZilfAnalyzers
i
.
ConstantAccessSyntax
.
WithTriviaFrom
(
i
.
ExpressionToReplace
));
if
(
i
.
NewMessageArgs
.
Any
())
{
ArgumentSyntax
?
ancestor
=
i
.
ExpressionToReplace
.
FirstAncestorOrSelf
<
ArgumentSyntax
>();
Debug
.
Assert
(
ancestor
!=
null
);
docEditor
.
InsertAfter
(
i
.
ExpressionToReplace
.
FirstAncestorOrSelf
<
ArgumentSyntax
>()
,
ancestor
,
i
.
NewMessageArgs
.
Select
(
a
=>
SyntaxFactory
.
Argument
(
a
).
WithAdditionalAnnotations
(
Formatter
.
Annotation
)));
}
}
AddUsingIfNeeded
(
docEditor
);
...
...
@@ -335,6 +339,7 @@ namespace ZilfAnalyzers
{
case
FixAllScope
.
Document
:
{
Debug
.
Assert
(
fixAllContext
.
Document
!=
null
);
var
diagnostics
=
await
fixAllContext
.
GetDocumentDiagnosticsAsync
(
fixAllContext
.
Document
).
ConfigureAwait
(
false
);
diagnosticsToFix
.
Add
(
new
KeyValuePair
<
Project
,
ImmutableArray
<
Diagnostic
>>(
fixAllContext
.
Project
,
diagnostics
));
fixAllTitle
=
string
.
Format
(
TitleFormat
,
"document"
,
fixAllContext
.
Document
.
Name
);
...
...
src/Analyzers/ZilfAnalyzers/MessageConstantAnalyzer.cs
View file @
6f324040
...
...
@@ -115,7 +115,7 @@ namespace ZilfAnalyzers
{
var
constValue
=
context
.
SemanticModel
.
GetConstantValue
(
varDecl
.
Initializer
.
Value
);
if
(!
constValue
.
HasValue
)
if
(!
constValue
.
HasValue
||
constValue
.
Value
==
null
)
continue
;
// check for duplicate code
...
...
src/Analyzers/ZilfAnalyzers/MessageConstantCodeFixProvider.cs
View file @
6f324040
...
...
@@ -115,7 +115,8 @@ namespace ZilfAnalyzers
// get format string and split it into prefix + rest
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
);
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
);
var
formatStr
=
(
string
)
semanticModel
!.
GetConstantValue
(
FindFormatExpr
(
root
!),
cancellationToken
).
Value
;
var
formatStr
=
(
string
?)
semanticModel
!.
GetConstantValue
(
FindFormatExpr
(
root
!),
cancellationToken
).
Value
;
Debug
.
Assert
(
formatStr
!=
null
);
var
match
=
MessageConstantAnalyzer
.
PrefixedMessageFormatRegex
.
Match
(
formatStr
);
var
prefix
=
match
.
Groups
[
"prefix"
].
Value
;
var
rest
=
match
.
Groups
[
"rest"
].
Value
;
...
...
src/Analyzers/ZilfAnalyzers/ZilfAnalyzers.csproj
View file @
6f324040
...
...
@@ -24,7 +24,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.
7
.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.
8
.0" PrivateAssets="all" />
<!--<PackageReference Update="NETStandard.Library" PrivateAssets="all" />-->
</ItemGroup>
...
...
src/Zilf.Playground/JSInterop.cs
0 → 100644
View file @
6f324040
#
nullable
enable
using
Microsoft.AspNetCore.Components
;
using
Microsoft.JSInterop
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
Zilf.Playground
{
internal
sealed
class
JSInterop
{
private
readonly
IJSRuntime
js
;
public
JSInterop
(
IJSRuntime
js
)
{
this
.
js
=
js
;
}
public
void
DownloadBytesAsFile
(
byte
[]
bytes
,
string
filename
,
string
contentType
)
{
var
jsu
=
(
IJSUnmarshalledRuntime
)
js
;
jsu
.
InvokeUnmarshalled
<
string
,
string
,
byte
[],
bool
>(
"ZilfJsInterop.BlazorDownloadFileFast"
,
filename
,
contentType
,
bytes
);
}
public
async
Task
ScrollToBottomAsync
(
ElementReference
element
)
{
await
js
.
InvokeVoidAsync
(
"ZilfJsInterop.scrollToBottom"
,
element
);
}
public
async
Task
<
string
>
PromptAsync
(
string
prompt
,
string
value
)
{
return
await
js
.
InvokeAsync
<
string
>(
"prompt"
,
prompt
,
value
);
}
public
async
Task
AddEventListenerAsync
(
ElementReference
element
,
string
eventName
,
string
jsHandler
,
params
object
[]
extraHandlerArgs
)
{
await
js
.
InvokeVoidAsync
(
"ZilfJsInterop.addEventListener"
,
element
,
eventName
,
jsHandler
,
extraHandlerArgs
);
}
}
}
src/Zilf.Playground/Pages/Documentation.razor
0 → 100644
View file @
6f324040
@page "/doc"
<h3>Documentation</h3>
<ul>
<li><a href="http://faq.zilf.io/">Getting Started</a></li>
<li><a href="http://g.zilf.io/">ZIL Group on Facebook</a></li>
</ul>
src/Zilf.Playground/Pages/Index.razor
View file @
6f324040
@page "/"
@using Zapf
@using Zilf.Common
@using Zilf.Compiler
@using Zilf.Diagnostics
<h1>ZIL Playground</h1>
<div>
<div style="margin:10px 0;">
Theme:
<select @onchange="ChangeTheme">
<option value="vs">Visual Studio</option>
<option value="vs-dark">Visual Studio Dark</option>
<option value="hc-black">High Contrast Black</option>
</select>
</div>
@*<div style="margin:10px 0;">
New Value: <input type="text" @bind="ValueToSet" style="width: 400px;" /> <button @onclick="SetValue">Set Value</button>
</div>
<div style="margin:10px 0;">
<button @onclick="GetValue">Get Value</button>
</div>
<div style="margin:10px 0;">
<button @onclick="AddCommand">Add Command (Ctrl+Enter)</button>
</div>
<div style="margin:10px 0;">
<button @onclick="AddAction">Add Action (Ctrl+D)</button>
</div>
<div style="margin:10px 0;">
See the console for results.
</div>*@
<div style="margin:10px 0;">
<button @onclick="Compile">Compile</button>
@layout ContainerlessLayout
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">ZIL Forever</h1>
<p class="lead">
It’s scary, ugly, and hard to understand—and until recently, it was dead.
But it’s back on its feet again, and you’re gonna love it.
</p>
<p class="text-muted">
Before video games, there was interactive fiction.
The genre was defined by classics like <a href="https://en.wikipedia.org/wiki/Zork">Zork</a>,
<a href="https://en.wikipedia.org/wiki/Planetfall">Planetfall</a>,
and <a href="https://en.wikipedia.org/wiki/Enchanter_(video_game)">Enchanter</a>,
which were written in Infocom’s custom programming language:
the Zork Implementation Language, or ZIL.
</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more »</a></p>
</div>
</div>
<MonacoEditor @ref="_editor"
Id="code-editor"
ConstructionOptions="EditorConstructionOptions"
OnDidInit="EditorOnDidInit"
OnContextMenu="EditorOnContextMenu"
/>
<CompilerOutput CompileResult="@CompileResult"
AssembleResult="@AssembleResult"
FileSystem="@FileSystem" />
@code {
private MonacoEditor _editor { get; set; }
private string ValueToSet { get; set; }
private FrontEndResult CompileResult { get; set; }
private AssemblyResult? AssembleResult { get; set; }
private InMemoryFileSystem FileSystem { get; set; }
private StandaloneEditorConstructionOptions EditorConstructionOptions(MonacoEditor editor)
{
return new StandaloneEditorConstructionOptions
{
Language = "zil",
GlyphMargin = true,
Value = "<VERSION ZIP>\n" +
"\n" +
"<ROUTINE GO ()\n" +
" <TELL \"Hello world!\" CR>\n" +
" <QUIT>>",
};
}
private async Task EditorOnDidInit(MonacoEditorBase editor)
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.KEY_H, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+H : Initial editor command is triggered.");
System.Diagnostics.Debugger.Break();
});
//var newDecorations = new ModelDeltaDecoration[]
//{
// new ModelDeltaDecoration
// {
// Range = new BlazorMonaco.Bridge.Range(3,1,3,1),
// Options = new ModelDecorationOptions
// {
// IsWholeLine = true,
// ClassName = "decorationContentClass",
// GlyphMarginClassName = "decorationGlyphMarginClass"
// }
// }
//};
//decorationIds = await _editor.DeltaDecorations(null, newDecorations);
// You can now use 'decorationIds' to change or remove the decorations
}
//private string[] decorationIds;
private void EditorOnContextMenu(EditorMouseEvent eventArg)
{
Console.WriteLine("OnContextMenu : " + System.Text.Json.JsonSerializer.Serialize(eventArg));
}
private async Task ChangeTheme(ChangeEventArgs e)
{
Console.WriteLine($"setting theme to: {e.Value.ToString()}");
await MonacoEditor.SetTheme(e.Value.ToString());
}
private async Task SetValue()
{
Console.WriteLine($"setting value to: {ValueToSet}");
await _editor.SetValue(ValueToSet);
}
private async Task GetValue()
{
var val = await _editor.GetValue();
Console.WriteLine($"value is: {val}");
}
private async Task AddCommand()
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.Enter, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+Enter : Editor command is triggered.");
});
}
private async Task AddAction()
{
await _editor.AddAction("testAction", "Test Action", new int[] { (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_D, (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_B }, null, null, "navigation", 1.5, (editor, keyCodes) =>
{
Console.WriteLine("Ctrl+D : Editor action is triggered.");
});
}
private async Task Compile()
{
var fileSystem = new InMemoryFileSystem
{
["main.zil"] = await _editor.GetValue(),
};
var compiler = new FrontEnd { FileSystem = fileSystem, Logger = NullDiagnosticLogger.Instance };
var compResult = compiler.Compile("main.zil", "main.zap", false);
<div class="container">
<div class="row">
<div class="col-md-4">
<h2>Portable</h2>
<p>
ZILF games run anywhere there’s a <a href="https://en.wikipedia.org/wiki/Z-machine">Z-machine</a>
interpreter, including most computers, phones, and web browsers. ZILF itself is built with
<a href="https://dotnet.microsoft.com/">.NET</a> and runs on most computers too—Windows,
Linux, and macOS. You can even try it out right here, on the web.
</p>
<p><a class="btn btn-secondary" href="project/new" role="button">Try it now »</a></p>
</div>
<div class="col-md-4">
<h2>Retro</h2>
<p>
ZIL is based on <a href="https://mdl-language.readthedocs.io/en/latest/">MDL</a>, a Lisp-like
language developed for AI research in the 1970s. And it feels like it. All caps? Check.
Command line interface? Oh, yeah. Cryptic names? We got ’em.
</p>
<p><a class="btn btn-secondary" href="repl" role="button">Nerd it up »</a></p>
</div>
<div class="col-md-4">
<h2>Open</h2>
<p>
ZILF is free, open source software distributed under the GNU General Public License. You
can read the code, report issues, and submit patches at the Heptapod project site.
</p>
<p><a class="btn btn-secondary" href="https://foss.heptapod.net/zilf/zilf/" role="button">View project »</a></p>
</div>
</div>
CompileResult = compResult;
AssembleResult = null;
FileSystem = fileSystem;
<hr>
if (compResult.Success)
{
var assembler = new Zapf.ZapfAssembler { FileSystem = fileSystem };
AssembleResult = assembler.Assemble("main.zap", "main.z#");
}
}
}
\ No newline at end of file
</div> <!-- /container -->
src/Zilf.Playground/Pages/OldIndex.razor
0 → 100644
View file @
6f324040
@page "/oldindex"
@using Zapf
@using Zilf.Compiler
@using Zilf.Diagnostics
@inject TemplateService Templates
<h1>ZIL Playground</h1>
<div>
<div style="margin:10px 0;">
<label for="theme">Theme:</label>
<select id="theme" @onchange="ChangeTheme">
<option value="vs">Visual Studio</option>
<option value="vs-dark">Visual Studio Dark</option>
<option value="hc-black">High Contrast Black</option>
</select>
</div>
<div style="margin:10px 0;">
<label for="project">Project:</label>
<select id="project" @onchange="ChangeProject">
@foreach (var name in AvailableTemplates)
{
<option value="@name">@name</option>
}
</select>
</div>
@*<FileSystemBrowser FileSystem="FileSystem"
OnChange="FileSystemBrowserOnChange"
/>*@
<div style="margin:10px 0;">
<button @onclick="Compile">Compile</button>
</div>
</div>
<MonacoEditor @ref="_editor"
Id="code-editor"
ConstructionOptions="EditorConstructionOptions"
OnDidInit="EditorOnDidInit"
OnContextMenu="EditorOnContextMenu"
/>
<CompilerOutput CompileResult="@CompileResult"
AssembleResult="@AssembleResult"
FileSystem="@FileSystem" />
@code {
private MonacoEditor _editor { get; set; }
private string ValueToSet { get; set; }
private FrontEndResult CompileResult { get; set; }
private AssemblyResult? AssembleResult { get; set; }
private InMemoryFileSystem FileSystem { get; } = new InMemoryFileSystem();
private IEnumerable<string> AvailableTemplates { get; set; } = Enumerable.Empty<string>();
protected override async Task OnInitializedAsync()
{
AvailableTemplates = await Templates.GetTemplateNamesAsync();
}
private StandaloneEditorConstructionOptions EditorConstructionOptions(MonacoEditor editor)
{
return new StandaloneEditorConstructionOptions
{
Language = "zil",
GlyphMargin = true,
Value = "<VERSION ZIP>\n" +
"\n" +
"<ROUTINE GO ()\n" +
" <TELL \"Hello world!\" CR>\n" +
" <QUIT>>",
};
}
private async Task EditorOnDidInit(MonacoEditorBase editor)
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.KEY_H, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+H : Initial editor command is triggered.");
System.Diagnostics.Debugger.Break();
});
//var newDecorations = new ModelDeltaDecoration[]
//{
// new ModelDeltaDecoration
// {
// Range = new BlazorMonaco.Bridge.Range(3,1,3,1),
// Options = new ModelDecorationOptions
// {
// IsWholeLine = true,
// ClassName = "decorationContentClass",
// GlyphMarginClassName = "decorationGlyphMarginClass"
// }
// }
//};
//decorationIds = await _editor.DeltaDecorations(null, newDecorations);
// You can now use 'decorationIds' to change or remove the decorations
}
//private string[] decorationIds;
private void EditorOnContextMenu(EditorMouseEvent eventArg)
{
Console.WriteLine("OnContextMenu : " + System.Text.Json.JsonSerializer.Serialize(eventArg));
}
private async Task ChangeTheme(ChangeEventArgs e)
{
Console.WriteLine($"setting theme to: {e.Value.ToString()}");
await MonacoEditor.SetTheme(e.Value.ToString());
}
private async Task SetValue()
{
Console.WriteLine($"setting value to: {ValueToSet}");
await _editor.SetValue(ValueToSet);
}
private async Task GetValue()
{
var val = await _editor.GetValue();
Console.WriteLine($"value is: {val}");
}
private async Task AddCommand()
{
await _editor.AddCommand((int)KeyMode.CtrlCmd | (int)KeyCode.Enter, (editor, keyCode) =>
{
Console.WriteLine("Ctrl+Enter : Editor command is triggered.");
});
}
private async Task AddAction()
{
await _editor.AddAction("testAction", "Test Action", new int[] { (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_D, (int)KeyMode.CtrlCmd | (int)KeyCode.KEY_B }, null, null, "navigation", 1.5, (editor, keyCodes) =>
{
Console.WriteLine("Ctrl+D : Editor action is triggered.");
});
}
private async Task Compile()
{
FileSystem.SetText("main.zil", await _editor.GetValue());
var compiler = new FrontEnd { FileSystem = FileSystem, Logger = NullDiagnosticLogger.Instance };
var compResult = compiler.Compile("main.zil", "main.zap", false);
CompileResult = compResult;
AssembleResult = null;
if (compResult.Success)
{
var assembler = new Zapf.ZapfAssembler { FileSystem = FileSystem };
AssembleResult = assembler.Assemble("main.zap", "main.z#");
}
}
private Task ChangeProject(ChangeEventArgs e)
{
return Task.CompletedTask;
//if (e.Value is string name)
//{
// var (template, fileContents) = await Templates.LoadTemplateAsync(name);
// FileSystem.Clear();
// foreach (var (path, content) in fileContents)
// FileSystem.SetText(path, content);
// await _editor.SetValue(fileContents[0].content);
//}
}
}
src/Zilf.Playground/Pages/ProjectEdit.razor
0 → 100644
View file @
6f324040
@page "/project/{ProjectId:guid}/edit"
@inject WorkspaceService Workspace
@inject NavigationManager Nav
@layout ProjectLayout
<h3>Editing @Path</h3>
<textarea @bind="FileContent" class="w-100 h-75" ></textarea>
@code {
public static string GetLink(Project project, string path) => GetLink(project.Guid.ToString(), path);
public static string GetLink(string projectId, string path) =>
$"/project/{projectId}/edit?file={path}";
[Parameter]
public Guid ProjectId { get; set; }
[Parameter]
public string Path { get; set; }
[System.Diagnostics.CodeAnalysis.MaybeNull]
private ProjectFile File => Workspace.Project.Files.SingleOrDefault(f => f.Path == Path);
public string FileContent
{
get => File?.Content;
set
{
var f = File;
if (f != null)
f.Content = value;
}
}
[CascadingParameter]
public ProjectLayout ProjectLayout { get; set; }
protected override void OnParametersSet()
{
var uri = new Uri(Nav.Uri);
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query);
Path = query.GetValueOrDefault("file");
if (Path == null && Workspace.Project.Files.Count > 0)
{
Nav.NavigateTo(GetLink(Workspace.Project, Workspace.Project.MainFile.Path));
return;
}
ProjectLayout.ActivePath = Path;
}
}
src/Zilf.Playground/Pages/ProjectNew.razor
0 → 100644
View file @
6f324040
@page "/project/new"
@inject TemplateService Templates
@inject NavigationManager Nav
@inject WorkspaceService Workspace
@layout ContainerlessLayout
<div class="px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-4">Select template</h1>
<p class="lead">Start a new project without having to write out all the boilerplate, or learn ZIL by hacking on one of the example games.</p>
</div>
<div class="container">
@if (Showcase.Length == 0)