feat: temporary grammar

This commit is contained in:
Mattia Belletti
2025-03-01 12:30:36 +01:00
parent aa3baa780d
commit eed28168ad
31 changed files with 1409 additions and 479 deletions

View File

@@ -17,11 +17,12 @@ public class ContentTextTest
public void TestBaseContentSuccess(string inkInput, string result, int numErrors) public void TestBaseContentSuccess(string inkInput, string result, int numErrors)
{ {
// parse the story // parse the story
var fileReader = new PreMadeFileReader([ var fileReader = new InMemoryFileReader([
("main.ink", inkInput) ("main.ink", inkInput)
]); ]);
var parser = new InkBlotParser(); var parser = new InkBlotParser();
var (story, diagnostics) = parser.Parse(fileReader, "main.ink"); using var loggerFactory = Helpers.GetLoggerFactory();
var (story, diagnostics) = InkBlotParser.Parse(fileReader, loggerFactory, "main.ink");
// check the diagnostic counts match // check the diagnostic counts match
diagnostics.Count().ShouldBe(numErrors); diagnostics.Count().ShouldBe(numErrors);

View File

@@ -1,4 +1,5 @@
using System.Text; using System.Text;
using Microsoft.Extensions.Logging;
namespace InkBlot.Tests; namespace InkBlot.Tests;
@@ -6,10 +7,19 @@ namespace InkBlot.Tests;
/// A file reader where the contents are directly provided as strings. /// A file reader where the contents are directly provided as strings.
/// </summary> /// </summary>
/// <param name="filesToContents">A map between file names and their contents.</param> /// <param name="filesToContents">A map between file names and their contents.</param>
internal class PreMadeFileReader((string, string)[] filesToContents) : IFileReader internal class InMemoryFileReader((string, string)[] filesToContents) : IFileReader
{ {
public Stream GetContents(string filename) public Stream GetContents(string filename)
{ {
return new MemoryStream(Encoding.UTF8.GetBytes(filesToContents.First(e => e.Item1 == filename).Item2)); return new MemoryStream(Encoding.UTF8.GetBytes(filesToContents.First(e => e.Item1 == filename).Item2));
} }
}
internal static class Helpers
{
public static ILoggerFactory GetLoggerFactory()
{
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
return loggerFactory;
}
} }

View File

@@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"/> <PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="Shouldly" Version="4.3.0"/> <PackageReference Include="Shouldly" Version="4.3.0"/>
<PackageReference Include="xunit" Version="2.9.2"/> <PackageReference Include="xunit" Version="2.9.2"/>

View File

@@ -0,0 +1,34 @@
using Antlr4.Runtime;
using Shouldly;
namespace InkBlot.Tests;
public class LexerTest
{
[Fact]
public void TestDivertForLexer()
{
var divertTokens = GetTokens("<- threadName");
divertTokens.ShouldSatisfyAllConditions(
() => divertTokens[0].Text.ShouldBe("<-"),
() => divertTokens[0].Type.ShouldBe(InkBlotAntlrGrammarLexer.THREAD_ARROW),
() => divertTokens[1].Text.ShouldBe(" "),
() => divertTokens[1].Type.ShouldBe(InkBlotAntlrGrammarLexer.WS),
() => divertTokens[2].Text.ShouldBe("threadName"),
() => divertTokens[2].Type.ShouldBe(InkBlotAntlrGrammarLexer.IDENTIFIER),
() => divertTokens[3].Text.ShouldBe("<EOF>"),
() => divertTokens[3].Type.ShouldBe(InkBlotAntlrGrammarLexer.Eof)
);
}
private IList<IToken> GetTokens(string text)
{
var fileReader = new InMemoryFileReader([
("main.ink", text)
]);
var tokensStream = InkBlotParser.GetTokenStream(fileReader, "main.ink");
tokensStream.Fill();
var tokens = tokensStream.GetTokens();
return tokens;
}
}

View File

@@ -0,0 +1,24 @@
using InkBlot.ParseHierarchy;
using Shouldly;
namespace InkBlot.Tests;
public class MultiDivertTest
{
[Fact]
public void TestThreadDivert()
{
var fileReader = new InMemoryFileReader([
("main.ink", "<- threadName")
]);
var tokensStream = InkBlotParser.GetTokenStream(fileReader, "main.ink");
tokensStream.Fill();
var tokens = tokensStream.GetTokens();
using var loggerFactory = Helpers.GetLoggerFactory();
var (story, diagnostics) = InkBlotParser.Parse(fileReader, loggerFactory, "main.ink");
diagnostics.ShouldBe([]);
var storyNodes = story.StoryNodes.ToArray();
storyNodes.ShouldBe([new MultiDivert(new ThreadDivert(new Identifier(["threadName"])))]);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -21,10 +21,10 @@ THREAD_ARROW=20
DIVERT_ARROW=21 DIVERT_ARROW=21
TUNNEL_ARROW=22 TUNNEL_ARROW=22
IDENTIFIER=23 IDENTIFIER=23
'.'=1 '('=1
'('=2 ','=2
','=3 ')'=3
')'=4 '.'=4
'-'=5 '-'=5
'|'=6 '|'=6
'{'=11 '{'=11

View File

@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Generated from E:/ProgettiUnity/InkAntlr/InkBlot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2 // Generated from C:/Users/mbelletti/RiderProjects/inkblot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2
// Unreachable code detected // Unreachable code detected
#pragma warning disable 0162 #pragma warning disable 0162
@@ -180,6 +180,90 @@ public partial class InkBlotAntlrGrammarBaseListener : IInkBlotAntlrGrammarListe
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context) { } public virtual void ExitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context) { }
/// <summary> /// <summary>
/// Enter a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context) { }
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context) { }
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context) { }
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context) { }
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context) { }
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context) { }
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>. /// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>.
/// <para>The default implementation does nothing.</para> /// <para>The default implementation does nothing.</para>
/// </summary> /// </summary>
@@ -192,6 +276,30 @@ public partial class InkBlotAntlrGrammarBaseListener : IInkBlotAntlrGrammarListe
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
public virtual void ExitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context) { } public virtual void ExitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context) { }
/// <summary> /// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>. /// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>.
/// <para>The default implementation does nothing.</para> /// <para>The default implementation does nothing.</para>
/// </summary> /// </summary>

View File

@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Generated from E:/ProgettiUnity/InkAntlr/InkBlot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2 // Generated from C:/Users/mbelletti/RiderProjects/inkblot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2
// Unreachable code detected // Unreachable code detected
#pragma warning disable 0162 #pragma warning disable 0162
@@ -155,6 +155,72 @@ public partial class InkBlotAntlrGrammarBaseVisitor<Result> : AbstractParseTreeV
/// <return>The visitor result.</return> /// <return>The visitor result.</return>
public virtual Result VisitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context) { return VisitChildren(context); } public virtual Result VisitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context) { return VisitChildren(context); }
/// <summary> /// <summary>
/// Visit a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>. /// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>.
/// <para> /// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
@@ -165,6 +231,26 @@ public partial class InkBlotAntlrGrammarBaseVisitor<Result> : AbstractParseTreeV
/// <return>The visitor result.</return> /// <return>The visitor result.</return>
public virtual Result VisitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context) { return VisitChildren(context); } public virtual Result VisitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context) { return VisitChildren(context); }
/// <summary> /// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
/// on <paramref name="context"/>.
/// </para>
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
public virtual Result VisitDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>. /// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>.
/// <para> /// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>

View File

@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Generated from E:/ProgettiUnity/InkAntlr/InkBlot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2 // Generated from C:/Users/mbelletti/RiderProjects/inkblot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2
// Unreachable code detected // Unreachable code detected
#pragma warning disable 0162 #pragma warning disable 0162
@@ -65,7 +65,7 @@ public partial class InkBlotAntlrGrammarLexer : Lexer {
} }
private static readonly string[] _LiteralNames = { private static readonly string[] _LiteralNames = {
null, "'.'", "'('", "','", "')'", "'-'", "'|'", null, null, null, null, null, "'('", "','", "')'", "'.'", "'-'", "'|'", null, null, null, null,
"'{'", "'}'", null, null, null, null, null, null, null, "'<-'", "'->'", "'{'", "'}'", null, null, null, null, null, null, null, "'<-'", "'->'",
"'->->'" "'->->'"
}; };
@@ -112,78 +112,76 @@ public partial class InkBlotAntlrGrammarLexer : Lexer {
private bool CONTENT_TEXT_NO_ESCAPE_SIMPLE_sempred(RuleContext _localctx, int predIndex) { private bool CONTENT_TEXT_NO_ESCAPE_SIMPLE_sempred(RuleContext _localctx, int predIndex) {
switch (predIndex) { switch (predIndex) {
case 0: return InputStream.LA(1) != '>' ; case 0: return InputStream.LA(1) != '>' ;
case 1: return InputStream.LA(1) != '-' && InputStream.LA(1) != '>' ;
} }
return true; return true;
} }
private static int[] _serializedATN = { private static int[] _serializedATN = {
4,0,23,200,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, 4,0,23,198,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,
7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,
7,21,2,22,7,22,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,4,6, 7,21,2,22,7,22,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,4,6,
61,8,6,11,6,12,6,62,1,7,3,7,66,8,7,1,7,3,7,69,8,7,1,7,1,7,1,8,4,8,74,8, 61,8,6,11,6,12,6,62,1,7,3,7,66,8,7,1,7,3,7,69,8,7,1,7,1,7,1,8,4,8,74,8,
8,11,8,12,8,75,1,9,1,9,1,9,1,9,1,9,1,9,1,9,4,9,85,8,9,11,9,12,9,86,1,10, 8,11,8,12,8,75,1,9,1,9,1,9,1,9,1,9,4,9,83,8,9,11,9,12,9,84,1,10,1,10,1,
1,10,1,11,1,11,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,3,13,101,8,13,1, 11,1,11,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,3,13,99,8,13,1,13,1,13,
13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,14,3,14,112,8,14,1,14,1,14,1,15, 1,14,1,14,1,14,1,14,1,14,1,14,1,14,3,14,110,8,14,1,14,1,14,1,15,1,15,1,
1,15,1,15,1,15,1,15,1,15,1,15,1,15,1,15,3,15,125,8,15,1,15,1,15,1,16,1, 15,1,15,1,15,1,15,1,15,1,15,1,15,3,15,123,8,15,1,15,1,15,1,16,1,16,1,16,
16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,3,16,139,8,16,1,16,1,16,1,17, 1,16,1,16,1,16,1,16,1,16,1,16,1,16,3,16,137,8,16,1,16,1,16,1,17,1,17,1,
1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17, 17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,1,17,3,17,156,
3,17,158,8,17,1,17,1,17,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1, 8,17,1,17,1,17,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,
18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,3,18,181,8,18,1,18,1,18, 1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,3,18,179,8,18,1,18,1,18,1,19,1,
1,19,1,19,1,19,1,20,1,20,1,20,1,21,1,21,1,21,1,21,1,21,1,22,4,22,197,8, 19,1,19,1,20,1,20,1,20,1,21,1,21,1,21,1,21,1,21,1,22,4,22,195,8,22,11,
22,11,22,12,22,198,0,0,23,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10, 22,12,22,196,0,0,23,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,
21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22, 23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,
45,23,1,0,5,2,0,9,9,32,32,5,0,10,10,13,13,35,60,92,92,123,125,1,0,0,65535, 1,0,5,2,0,9,9,32,32,6,0,10,10,13,13,32,32,35,60,92,92,123,125,1,0,0,65535,
4,0,32,33,36,36,38,38,126,126,4,0,48,57,65,90,95,95,97,122,214,0,1,1,0, 4,0,32,33,36,36,38,38,126,126,4,0,48,57,65,90,95,95,97,122,211,0,1,1,0,
0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13, 0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,
1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0, 1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,
0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35, 0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,
1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0, 1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,
0,1,47,1,0,0,0,3,49,1,0,0,0,5,51,1,0,0,0,7,53,1,0,0,0,9,55,1,0,0,0,11, 0,1,47,1,0,0,0,3,49,1,0,0,0,5,51,1,0,0,0,7,53,1,0,0,0,9,55,1,0,0,0,11,
57,1,0,0,0,13,60,1,0,0,0,15,65,1,0,0,0,17,73,1,0,0,0,19,84,1,0,0,0,21, 57,1,0,0,0,13,60,1,0,0,0,15,65,1,0,0,0,17,73,1,0,0,0,19,82,1,0,0,0,21,
88,1,0,0,0,23,90,1,0,0,0,25,92,1,0,0,0,27,94,1,0,0,0,29,104,1,0,0,0,31, 86,1,0,0,0,23,88,1,0,0,0,25,90,1,0,0,0,27,92,1,0,0,0,29,102,1,0,0,0,31,
115,1,0,0,0,33,128,1,0,0,0,35,142,1,0,0,0,37,161,1,0,0,0,39,184,1,0,0, 113,1,0,0,0,33,126,1,0,0,0,35,140,1,0,0,0,37,159,1,0,0,0,39,182,1,0,0,
0,41,187,1,0,0,0,43,190,1,0,0,0,45,196,1,0,0,0,47,48,5,46,0,0,48,2,1,0, 0,41,185,1,0,0,0,43,188,1,0,0,0,45,194,1,0,0,0,47,48,5,40,0,0,48,2,1,0,
0,0,49,50,5,40,0,0,50,4,1,0,0,0,51,52,5,44,0,0,52,6,1,0,0,0,53,54,5,41, 0,0,49,50,5,44,0,0,50,4,1,0,0,0,51,52,5,41,0,0,52,6,1,0,0,0,53,54,5,46,
0,0,54,8,1,0,0,0,55,56,5,45,0,0,56,10,1,0,0,0,57,58,5,124,0,0,58,12,1, 0,0,54,8,1,0,0,0,55,56,5,45,0,0,56,10,1,0,0,0,57,58,5,124,0,0,58,12,1,
0,0,0,59,61,7,0,0,0,60,59,1,0,0,0,61,62,1,0,0,0,62,60,1,0,0,0,62,63,1, 0,0,0,59,61,7,0,0,0,60,59,1,0,0,0,61,62,1,0,0,0,62,60,1,0,0,0,62,63,1,
0,0,0,63,14,1,0,0,0,64,66,3,13,6,0,65,64,1,0,0,0,65,66,1,0,0,0,66,68,1, 0,0,0,63,14,1,0,0,0,64,66,3,13,6,0,65,64,1,0,0,0,65,66,1,0,0,0,66,68,1,
0,0,0,67,69,5,13,0,0,68,67,1,0,0,0,68,69,1,0,0,0,69,70,1,0,0,0,70,71,5, 0,0,0,67,69,5,13,0,0,68,67,1,0,0,0,68,69,1,0,0,0,69,70,1,0,0,0,70,71,5,
10,0,0,71,16,1,0,0,0,72,74,3,15,7,0,73,72,1,0,0,0,74,75,1,0,0,0,75,73, 10,0,0,71,16,1,0,0,0,72,74,3,15,7,0,73,72,1,0,0,0,74,75,1,0,0,0,75,73,
1,0,0,0,75,76,1,0,0,0,76,18,1,0,0,0,77,85,8,1,0,0,78,79,5,92,0,0,79,85, 1,0,0,0,75,76,1,0,0,0,76,18,1,0,0,0,77,83,8,1,0,0,78,79,5,92,0,0,79,83,
7,2,0,0,80,81,5,45,0,0,81,85,4,9,0,0,82,83,5,60,0,0,83,85,4,9,1,0,84,77, 7,2,0,0,80,81,5,45,0,0,81,83,4,9,0,0,82,77,1,0,0,0,82,78,1,0,0,0,82,80,
1,0,0,0,84,78,1,0,0,0,84,80,1,0,0,0,84,82,1,0,0,0,85,86,1,0,0,0,86,84, 1,0,0,0,83,84,1,0,0,0,84,82,1,0,0,0,84,85,1,0,0,0,85,20,1,0,0,0,86,87,
1,0,0,0,86,87,1,0,0,0,87,20,1,0,0,0,88,89,5,123,0,0,89,22,1,0,0,0,90,91, 5,123,0,0,87,22,1,0,0,0,88,89,5,125,0,0,89,24,1,0,0,0,90,91,7,3,0,0,91,
5,125,0,0,91,24,1,0,0,0,92,93,7,3,0,0,93,26,1,0,0,0,94,95,5,111,0,0,95, 26,1,0,0,0,92,93,5,111,0,0,93,94,5,110,0,0,94,95,5,99,0,0,95,96,5,101,
96,5,110,0,0,96,97,5,99,0,0,97,98,5,101,0,0,98,100,1,0,0,0,99,101,3,13, 0,0,96,98,1,0,0,0,97,99,3,13,6,0,98,97,1,0,0,0,98,99,1,0,0,0,99,100,1,
6,0,100,99,1,0,0,0,100,101,1,0,0,0,101,102,1,0,0,0,102,103,5,58,0,0,103, 0,0,0,100,101,5,58,0,0,101,28,1,0,0,0,102,103,5,99,0,0,103,104,5,121,0,
28,1,0,0,0,104,105,5,99,0,0,105,106,5,121,0,0,106,107,5,99,0,0,107,108, 0,104,105,5,99,0,0,105,106,5,108,0,0,106,107,5,101,0,0,107,109,1,0,0,0,
5,108,0,0,108,109,5,101,0,0,109,111,1,0,0,0,110,112,3,13,6,0,111,110,1, 108,110,3,13,6,0,109,108,1,0,0,0,109,110,1,0,0,0,110,111,1,0,0,0,111,112,
0,0,0,111,112,1,0,0,0,112,113,1,0,0,0,113,114,5,58,0,0,114,30,1,0,0,0, 5,58,0,0,112,30,1,0,0,0,113,114,5,115,0,0,114,115,5,104,0,0,115,116,5,
115,116,5,115,0,0,116,117,5,104,0,0,117,118,5,117,0,0,118,119,5,102,0, 117,0,0,116,117,5,102,0,0,117,118,5,102,0,0,118,119,5,108,0,0,119,120,
0,119,120,5,102,0,0,120,121,5,108,0,0,121,122,5,101,0,0,122,124,1,0,0, 5,101,0,0,120,122,1,0,0,0,121,123,3,13,6,0,122,121,1,0,0,0,122,123,1,0,
0,123,125,3,13,6,0,124,123,1,0,0,0,124,125,1,0,0,0,125,126,1,0,0,0,126, 0,0,123,124,1,0,0,0,124,125,5,58,0,0,125,32,1,0,0,0,126,127,5,115,0,0,
127,5,58,0,0,127,32,1,0,0,0,128,129,5,115,0,0,129,130,5,116,0,0,130,131, 127,128,5,116,0,0,128,129,5,111,0,0,129,130,5,112,0,0,130,131,5,112,0,
5,111,0,0,131,132,5,112,0,0,132,133,5,112,0,0,133,134,5,105,0,0,134,135, 0,131,132,5,105,0,0,132,133,5,110,0,0,133,134,5,103,0,0,134,136,1,0,0,
5,110,0,0,135,136,5,103,0,0,136,138,1,0,0,0,137,139,3,13,6,0,138,137,1, 0,135,137,3,13,6,0,136,135,1,0,0,0,136,137,1,0,0,0,137,138,1,0,0,0,138,
0,0,0,138,139,1,0,0,0,139,140,1,0,0,0,140,141,5,58,0,0,141,34,1,0,0,0, 139,5,58,0,0,139,34,1,0,0,0,140,141,5,115,0,0,141,142,5,104,0,0,142,143,
142,143,5,115,0,0,143,144,5,104,0,0,144,145,5,117,0,0,145,146,5,102,0, 5,117,0,0,143,144,5,102,0,0,144,145,5,102,0,0,145,146,5,108,0,0,146,147,
0,146,147,5,102,0,0,147,148,5,108,0,0,148,149,5,101,0,0,149,150,1,0,0, 5,101,0,0,147,148,1,0,0,0,148,149,3,13,6,0,149,150,5,111,0,0,150,151,5,
0,150,151,3,13,6,0,151,152,5,111,0,0,152,153,5,110,0,0,153,154,5,99,0, 110,0,0,151,152,5,99,0,0,152,153,5,101,0,0,153,155,1,0,0,0,154,156,3,13,
0,154,155,5,101,0,0,155,157,1,0,0,0,156,158,3,13,6,0,157,156,1,0,0,0,157, 6,0,155,154,1,0,0,0,155,156,1,0,0,0,156,157,1,0,0,0,157,158,5,58,0,0,158,
158,1,0,0,0,158,159,1,0,0,0,159,160,5,58,0,0,160,36,1,0,0,0,161,162,5, 36,1,0,0,0,159,160,5,115,0,0,160,161,5,104,0,0,161,162,5,117,0,0,162,163,
115,0,0,162,163,5,104,0,0,163,164,5,117,0,0,164,165,5,102,0,0,165,166, 5,102,0,0,163,164,5,102,0,0,164,165,5,108,0,0,165,166,5,101,0,0,166,167,
5,102,0,0,166,167,5,108,0,0,167,168,5,101,0,0,168,169,1,0,0,0,169,170, 1,0,0,0,167,168,3,13,6,0,168,169,5,115,0,0,169,170,5,116,0,0,170,171,5,
3,13,6,0,170,171,5,115,0,0,171,172,5,116,0,0,172,173,5,111,0,0,173,174, 111,0,0,171,172,5,112,0,0,172,173,5,112,0,0,173,174,5,105,0,0,174,175,
5,112,0,0,174,175,5,112,0,0,175,176,5,105,0,0,176,177,5,110,0,0,177,178, 5,110,0,0,175,176,5,103,0,0,176,178,1,0,0,0,177,179,3,13,6,0,178,177,1,
5,103,0,0,178,180,1,0,0,0,179,181,3,13,6,0,180,179,1,0,0,0,180,181,1,0, 0,0,0,178,179,1,0,0,0,179,180,1,0,0,0,180,181,5,58,0,0,181,38,1,0,0,0,
0,0,181,182,1,0,0,0,182,183,5,58,0,0,183,38,1,0,0,0,184,185,5,60,0,0,185, 182,183,5,60,0,0,183,184,5,45,0,0,184,40,1,0,0,0,185,186,5,45,0,0,186,
186,5,45,0,0,186,40,1,0,0,0,187,188,5,45,0,0,188,189,5,62,0,0,189,42,1, 187,5,62,0,0,187,42,1,0,0,0,188,189,5,45,0,0,189,190,5,62,0,0,190,191,
0,0,0,190,191,5,45,0,0,191,192,5,62,0,0,192,193,5,45,0,0,193,194,5,62, 5,45,0,0,191,192,5,62,0,0,192,44,1,0,0,0,193,195,7,4,0,0,194,193,1,0,0,
0,0,194,44,1,0,0,0,195,197,7,4,0,0,196,195,1,0,0,0,197,198,1,0,0,0,198, 0,195,196,1,0,0,0,196,194,1,0,0,0,196,197,1,0,0,0,197,46,1,0,0,0,14,0,
196,1,0,0,0,198,199,1,0,0,0,199,46,1,0,0,0,14,0,62,65,68,75,84,86,100, 62,65,68,75,82,84,98,109,122,136,155,178,196,0
111,124,138,157,180,198,0
}; };
public static readonly ATN _ATN = public static readonly ATN _ATN =

File diff suppressed because one or more lines are too long

View File

@@ -21,10 +21,10 @@ THREAD_ARROW=20
DIVERT_ARROW=21 DIVERT_ARROW=21
TUNNEL_ARROW=22 TUNNEL_ARROW=22
IDENTIFIER=23 IDENTIFIER=23
'.'=1 '('=1
'('=2 ','=2
','=3 ')'=3
')'=4 '.'=4
'-'=5 '-'=5
'|'=6 '|'=6
'{'=11 '{'=11

View File

@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Generated from E:/ProgettiUnity/InkAntlr/InkBlot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2 // Generated from C:/Users/mbelletti/RiderProjects/inkblot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2
// Unreachable code detected // Unreachable code detected
#pragma warning disable 0162 #pragma warning disable 0162
@@ -151,6 +151,78 @@ public interface IInkBlotAntlrGrammarListener : IParseTreeListener {
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
void ExitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context); void ExitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context);
/// <summary> /// <summary>
/// Enter a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context);
/// <summary>
/// Enter a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context);
/// <summary>
/// Exit a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>. /// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>.
/// </summary> /// </summary>
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
@@ -161,6 +233,26 @@ public interface IInkBlotAntlrGrammarListener : IParseTreeListener {
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
void ExitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context); void ExitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context);
/// <summary> /// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>. /// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>.
/// </summary> /// </summary>
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Generated from E:/ProgettiUnity/InkAntlr/InkBlot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2 // Generated from C:/Users/mbelletti/RiderProjects/inkblot/InkBlot/InkBlotAntlrGrammar.g4 by ANTLR 4.13.2
// Unreachable code detected // Unreachable code detected
#pragma warning disable 0162 #pragma warning disable 0162
@@ -104,12 +104,66 @@ public interface IInkBlotAntlrGrammarVisitor<Result> : IParseTreeVisitor<Result>
/// <return>The visitor result.</return> /// <return>The visitor result.</return>
Result VisitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context); Result VisitMultiDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertContext context);
/// <summary> /// <summary>
/// Visit a parse tree produced by the <c>MultiDivertThread</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertThread([NotNull] InkBlotAntlrGrammarParser.MultiDivertThreadContext context);
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivert_withoutWS"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertArrows([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrowsContext context);
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailDefaultChoice</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertArrows_tailDefaultChoice([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context);
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailDivert</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertArrows_tailDivert([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context);
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailTunnelWithReplacement</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertArrows_tailTunnelWithReplacement([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context);
/// <summary>
/// Visit a parse tree produced by the <c>MultiDivertArrows_tailTunnel</c>
/// labeled alternative in <see cref="InkBlotAntlrGrammarParser.multiDivertArrows_tail"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitMultiDivertArrows_tailTunnel([NotNull] InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>. /// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments"/>.
/// </summary> /// </summary>
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return> /// <return>The visitor result.</return>
Result VisitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context); Result VisitDivertIdentifierWithArguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context);
/// <summary> /// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_name"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitDivertIdentifierWithArguments_name([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.divertIdentifierWithArguments_arguments"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitDivertIdentifierWithArguments_arguments([NotNull] InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_argumentsContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>. /// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.identifier"/>.
/// </summary> /// </summary>
/// <param name="context">The parse tree.</param> /// <param name="context">The parse tree.</param>

18
InkBlot/Helpers.cs Normal file
View File

@@ -0,0 +1,18 @@
using System.Diagnostics;
namespace InkBlot;
public static class Helpers
{
public static T AsNotNull<T>(this T? value) where T : struct
{
Debug.Assert(value.HasValue);
return value.Value;
}
public static T AsNotNull<T>(this T? value) where T : class
{
Debug.Assert(value != null);
return value;
}
}

View File

@@ -8,6 +8,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Antlr4.Runtime.Standard" Version="4.13.1"/> <PackageReference Include="Antlr4.Runtime.Standard" Version="4.13.1"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.2"/>
<PackageReference Include="OneOf" Version="3.0.271"/>
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -17,8 +17,8 @@ topLevelStatements:
; ;
topLevelStatement: topLevelStatement:
contentText multiDivert
| multiDivert | contentText
; ;
knotLevelStatements: knotLevelStatements:
@@ -63,7 +63,7 @@ inlineLogic:
INLINE_LOGIC_START INLINE_LOGIC_START
WS? WS?
innerLogic innerLogic
// TODO: += and -= are disabled here (don't know why) // TODO: += and -= are disabled here (don't know why, maybe because they're statements?)
WS? WS?
INLINE_LOGIC_END INLINE_LOGIC_END
// TODO: tags ftw // TODO: tags ftw
@@ -77,28 +77,47 @@ innerLogic:
multiDivert: multiDivert:
WS? WS?
( multiDivert_withoutWS
THREAD_ARROW divertIdentifierWithArguments
// here be dragons: trying to express the various "Possible patterns" of InkParser_Divert => MultiDivert
| (DIVERT_ARROW divertIdentifierWithArguments)+ TUNNEL_ARROW divertIdentifierWithArguments
| (DIVERT_ARROW divertIdentifierWithArguments)+ TUNNEL_ARROW
| (DIVERT_ARROW divertIdentifierWithArguments)+ DIVERT_ARROW
| TUNNEL_ARROW
| DIVERT_ARROW // TODO: this is only valid in default choices ( https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#fallback-choices )
)
; ;
multiDivert_withoutWS:
THREAD_ARROW divertIdentifierWithArguments # MultiDivertThread
// here be dragons: trying to express the various "Possible patterns" of InkParser_Divert => MultiDivert
// syntax in the original ink parser is overly concessive: https://discord.com/channels/329929050866843648/329929390358265857/1342130940981284945
| (DIVERT_ARROW divertIdentifierWithArguments)* multiDivertArrows_tail # MultiDivertArrows
// TODO: a single DIVERT_ARROW above is only valid in default choices ( https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md#fallback-choices )
// TODO: tags ftw
;
multiDivertArrows_tail:
DIVERT_ARROW # MultiDivertArrows_tailDefaultChoice
| DIVERT_ARROW divertIdentifierWithArguments # MultiDivertArrows_tailDivert
| TUNNEL_ARROW divertIdentifierWithArguments # MultiDivertArrows_tailTunnelWithReplacement
| TUNNEL_ARROW # MultiDivertArrows_tailTunnel
;
divertIdentifierWithArguments: divertIdentifierWithArguments:
WS? identifier WS? ('.' WS? identifier WS? )* WS?
divertIdentifierWithArguments_name
WS? WS?
( (
'(' '('
expression (',' expression)* expression (',' WS? expression)*
')' ')'
)? )?
WS? WS?
; ;
divertIdentifierWithArguments_name:
WS? identifier WS? ('.' WS? identifier WS? )*
;
divertIdentifierWithArguments_arguments:
'('
expression (',' WS? expression)*
')'
;
identifier: identifier:
// TODO: reject numbers-only identifier - see InkParser_Logic => Identifier // TODO: reject numbers-only identifier - see InkParser_Logic => Identifier
IDENTIFIER IDENTIFIER

View File

@@ -17,13 +17,13 @@ CONTENT_TEXT_NO_ESCAPE_SIMPLE:
// - \n\r ==> a new line of content // - \n\r ==> a new line of content
// - # ==> a tag // - # ==> a tag
// - \, < and - with exceptions (see below) // - \, < and - with exceptions (see below)
~[{}|\n\r\\#-<] ~[{}|\n\r\\#-< ]
// any character can be escaped // any character can be escaped
| '\\' [\u0000-\uFFFF] // TODO: is there a better way to say "any character"? | '\\' [\u0000-\uFFFF] // TODO: is there a better way to say "any character"?
// accept a - only if not followed by a > (->, a divert) // accept a - only if not followed by a > (->, a divert)
| '-' { InputStream.LA(1) != '>' }? | '-' { InputStream.LA(1) != '>' }?
// same for threads (<-) and glue (<>) // same for threads (<-) and glue (<>)
| '<' { InputStream.LA(1) != '-' && InputStream.LA(1) != '>' }? // | '<' { InputStream.LA(1) != '-' && InputStream.LA(1) != '>' }?
)+ ; )+ ;
INLINE_LOGIC_START: '{' ; INLINE_LOGIC_START: '{' ;

View File

@@ -3,20 +3,17 @@ using Antlr4.Runtime.Atn;
using Antlr4.Runtime.Tree; using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy; using InkBlot.ParseHierarchy;
using InkBlot.Visitor; using InkBlot.Visitor;
using Microsoft.Extensions.Logging;
namespace InkBlot; namespace InkBlot;
public class InkBlotParser public class InkBlotParser
{ {
public (Story, IEnumerable<Diagnostic>) Parse(IFileReader fileReader, string mainFileName) public static (Story, IEnumerable<Diagnostic>) Parse(IFileReader fileReader, ILoggerFactory loggerFactory,
string mainFileName)
{ {
var stream = fileReader.GetContents(mainFileName); var tokens = GetTokenStream(fileReader, mainFileName, out var lexerErrorListener);
var inputStream = new AntlrInputStream(stream);
var lexer = new InkBlotAntlrGrammarLexer(inputStream);
var lexerErrorListener = new LexerErrorListener();
lexer.RemoveErrorListeners();
lexer.AddErrorListener(lexerErrorListener);
var tokens = new CommonTokenStream(lexer);
var parser = new InkBlotAntlrGrammarParser(tokens); var parser = new InkBlotAntlrGrammarParser(tokens);
var parserErrorListener = new ParserErrorListener(); var parserErrorListener = new ParserErrorListener();
parser.RemoveErrorListeners(); parser.RemoveErrorListeners();
@@ -26,9 +23,27 @@ public class InkBlotParser
parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION; parser.Interpreter.PredictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION;
#endif #endif
var tree = parser.story(); var tree = parser.story();
var listener = new Listener(); var listener = new Listener(loggerFactory.CreateLogger<Listener>());
var walker = new ParseTreeWalker(); var walker = new ParseTreeWalker();
walker.Walk(listener, tree); walker.Walk(listener, tree);
return (listener.Story, lexerErrorListener.Diagnostics.Concat(parserErrorListener.Diagnostics)); return (listener.Story, lexerErrorListener.Diagnostics.Concat(parserErrorListener.Diagnostics));
} }
private static CommonTokenStream GetTokenStream(IFileReader fileReader, string mainFileName,
out LexerErrorListener lexerErrorListener)
{
var stream = fileReader.GetContents(mainFileName);
var inputStream = new AntlrInputStream(stream);
var lexer = new InkBlotAntlrGrammarLexer(inputStream);
lexerErrorListener = new LexerErrorListener();
lexer.RemoveErrorListeners();
lexer.AddErrorListener(lexerErrorListener);
var tokens = new CommonTokenStream(lexer);
return tokens;
}
public static CommonTokenStream GetTokenStream(IFileReader fileReader, string mainFileName)
{
return GetTokenStream(fileReader, mainFileName, out _);
}
} }

View File

@@ -1,3 +1,3 @@
namespace InkBlot.ParseHierarchy; namespace InkBlot.ParseHierarchy;
public record Content(string Text) : StoryNode; public record Content(string Text) : IStoryNode;

View File

@@ -3,4 +3,4 @@
/// <summary> /// <summary>
/// Any node in the parsed story /// Any node in the parsed story
/// </summary> /// </summary>
public record StoryNode; public interface IStoryNode;

View File

@@ -1,3 +1,27 @@
namespace InkBlot.ParseHierarchy; using OneOf;
public record MultiDivert : StoryNode; namespace InkBlot.ParseHierarchy;
[GenerateOneOf]
public partial class
MultiDivert : OneOfBase<ThreadDivert, DivertsListWithReturnFromTunnel, DivertsListWithoutReturnFromTunnel>,
IStoryNode
{
}
public record Identifier(string[] Elements /* TODO: expressions */);
// <- thread_name
public record ThreadDivert(Identifier Identifier) : IStoryNode;
// -> ... ->-> // return from tunnel
// or
// -> ... ->-> tunnelReplacement // return from tunnel, but replace destination
public record DivertsListWithReturnFromTunnel(Identifier[] Identifiers, Identifier? TunnelReplacement)
: IStoryNode;
// -> ... -> div // not a tunnel
// or
// -> ... -> div -> // is tunnel
public record DivertsListWithoutReturnFromTunnel(Identifier[] Identifiers, bool IsTunnel)
: IStoryNode;

View File

@@ -1,3 +1,3 @@
namespace InkBlot.ParseHierarchy; namespace InkBlot.ParseHierarchy;
public record Story(IEnumerable<StoryNode> StoryNodes) : StoryNode; public record Story(IEnumerable<IStoryNode> StoryNodes) : IStoryNode;

View File

@@ -1,5 +1,7 @@
namespace InkBlot.Visitor; using Microsoft.Extensions.Logging;
public partial class Listener : InkBlotAntlrGrammarBaseListener namespace InkBlot.Visitor;
public partial class Listener(ILogger<Listener> Logger) : InkBlotAntlrGrammarBaseListener
{ {
} }

View File

@@ -1,23 +1,15 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy; using InkBlot.ParseHierarchy;
namespace InkBlot.Visitor; namespace InkBlot.Visitor;
public partial class Listener public partial class Listener
{ {
private readonly ParseTreeProperty<Content> _contentTextValue = new();
private readonly Regex _escapeRegex = MyRegex(); private readonly Regex _escapeRegex = MyRegex();
[GeneratedRegex(@"\\(.)")] [GeneratedRegex(@"\\(.)")]
private static partial Regex MyRegex(); private static partial Regex MyRegex();
private Content GetContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
{
return _contentTextValue.Get(context);
}
public override void ExitContentText(InkBlotAntlrGrammarParser.ContentTextContext context) public override void ExitContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
{ {
// escape sequences are captured by this node, but not interpreted // escape sequences are captured by this node, but not interpreted
@@ -30,6 +22,6 @@ public partial class Listener
var content = _escapeRegex.Replace(contentWithEscapes, match => match.Groups[1].Value); var content = _escapeRegex.Replace(contentWithEscapes, match => match.Groups[1].Value);
// save the result // save the result
_contentTextValue.Put(context, new Content(content)); PutStoryNode(context, new Content(content));
} }
} }

View File

@@ -1,19 +1,97 @@
using Antlr4.Runtime.Tree; using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy; using InkBlot.ParseHierarchy;
using Microsoft.Extensions.Logging;
namespace InkBlot.Visitor; namespace InkBlot.Visitor;
internal record MultiDivertArrowsTail(bool LastArrowIsDivert, Identifier? Identifier);
public partial class Listener public partial class Listener
{ {
private readonly ParseTreeProperty<MultiDivert> _multiDivertValues = new(); private readonly ParseTreeProperty<MultiDivert> _multiDiverts = new();
private MultiDivert GetMultiDivert(InkBlotAntlrGrammarParser.MultiDivertContext context) private readonly ParseTreeProperty<MultiDivertArrowsTail> _multiDivertsArrowsTail = new();
public override void ExitMultiDivertThread(InkBlotAntlrGrammarParser.MultiDivertThreadContext context)
{ {
return _multiDivertValues.Get(context); var threadDivert = new ThreadDivert(
_divertIdentifiers.Get(context.divertIdentifierWithArguments()));
_multiDiverts.Put(context.Parent, threadDivert);
} }
public override void ExitMultiDivert(InkBlotAntlrGrammarParser.MultiDivertContext context) public override void ExitMultiDivertArrows(InkBlotAntlrGrammarParser.MultiDivertArrowsContext context)
{ {
_multiDivertValues.Put(context, new MultiDivert()); var divertIdentifiers = context
.divertIdentifierWithArguments()
.Select(a => _divertIdentifiers.Get(a));
var tail = _multiDivertsArrowsTail.Get(context.multiDivertArrows_tail());
_multiDiverts.Put(context,
tail.LastArrowIsDivert
? new DivertsListWithoutReturnFromTunnel(
(tail.Identifier != null ? divertIdentifiers.Append(tail.Identifier) : divertIdentifiers).ToArray(),
tail.LastArrowIsDivert)
: new DivertsListWithReturnFromTunnel(
divertIdentifiers.ToArray(),
tail.Identifier
));
} }
public override void ExitMultiDivertArrows_tailDefaultChoice(
InkBlotAntlrGrammarParser.MultiDivertArrows_tailDefaultChoiceContext context)
{
_multiDivertsArrowsTail.Put(context.Parent, new MultiDivertArrowsTail(true, null));
}
public override void ExitMultiDivertArrows_tailDivert(
InkBlotAntlrGrammarParser.MultiDivertArrows_tailDivertContext context)
{
_multiDivertsArrowsTail.Put(context.Parent, new MultiDivertArrowsTail(true,
_divertIdentifiers.Get(context.divertIdentifierWithArguments())));
}
public override void ExitMultiDivertArrows_tailTunnelWithReplacement(
InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelWithReplacementContext context)
{
_multiDivertsArrowsTail.Put(context.Parent, new MultiDivertArrowsTail(false,
_divertIdentifiers.Get(context.divertIdentifierWithArguments())));
}
public override void ExitMultiDivertArrows_tailTunnel(
InkBlotAntlrGrammarParser.MultiDivertArrows_tailTunnelContext context)
{
_multiDivertsArrowsTail.Put(context.Parent, new MultiDivertArrowsTail(false, null));
}
#region divertIdentifierWithArguments_name
private readonly ParseTreeProperty<string[]> _divertIdentifierNames = new();
public override void ExitDivertIdentifierWithArguments_name(
InkBlotAntlrGrammarParser.DivertIdentifierWithArguments_nameContext context)
{
var name = context.identifier().Select(identifier => identifier.ToString().AsNotNull()).ToArray();
_divertIdentifierNames.Put(context.Parent, name);
}
#endregion
#region divertIdentifierWithArguments
private readonly ParseTreeProperty<Identifier> _divertIdentifiers = new();
public override void ExitDivertIdentifierWithArguments(
InkBlotAntlrGrammarParser.DivertIdentifierWithArgumentsContext context)
{
var c = context.divertIdentifierWithArguments_name();
if (c == null)
{
Logger.LogWarning("found ExitDivertIdentifierWithArguments without name");
return;
}
var name = _divertIdentifierNames.Get(c);
_divertIdentifiers.Put(context, new Identifier(name));
}
#endregion
} }

View File

@@ -13,15 +13,7 @@ public partial class Listener
var storyNodes = context var storyNodes = context
.topLevelStatements() .topLevelStatements()
.topLevelStatement() .topLevelStatement()
.Select(topLevelStatement => .Select(topLevelStatement => GetStoryNode(topLevelStatement.children.Single()));
topLevelStatement.children.Single() switch
{
InkBlotAntlrGrammarParser.ContentTextContext contentTextContext =>
(StoryNode)GetContentText(contentTextContext),
InkBlotAntlrGrammarParser.MultiDivertContext multiDivertContext =>
GetMultiDivert(multiDivertContext),
_ => throw new InvalidOperationException()
});
_story = new Story(storyNodes); _story = new Story(storyNodes);
} }
} }

View File

@@ -0,0 +1,19 @@
using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy;
namespace InkBlot.Visitor;
public partial class Listener
{
private readonly ParseTreeProperty<IStoryNode> _storyNodeValue = new();
private void PutStoryNode(IParseTree tree, IStoryNode storyNode)
{
_storyNodeValue.Put(tree, storyNode);
}
private IStoryNode GetStoryNode(IParseTree tree)
{
return _storyNodeValue.Get(tree);
}
}

View File

@@ -11,4 +11,8 @@
<ProjectReference Include="..\InkBlot\InkBlot.csproj"/> <ProjectReference Include="..\InkBlot\InkBlot.csproj"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2"/>
</ItemGroup>
</Project> </Project>

View File

@@ -2,12 +2,15 @@
using System.Text; using System.Text;
using InkBlot; using InkBlot;
using Microsoft.Extensions.Logging;
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var parser = new InkBlotParser(); var parser = new InkBlotParser();
parser.Parse(new PreMadeFileReader(new Dictionary<string, string> InkBlotParser.Parse(new PreMadeFileReader(new Dictionary<string, string>
{ {
{ "main.ink", "Hel-\\lo!" } { "main.ink", "Hel-\\lo!" }
}), "main.ink"); }), loggerFactory, "main.ink");
internal class PreMadeFileReader(Dictionary<string, string> filesToContents) : IFileReader internal class PreMadeFileReader(Dictionary<string, string> filesToContents) : IFileReader