feat: base structure for getting a MultiDivert.

This commit is contained in:
mattia
2025-02-16 22:29:22 +01:00
parent 4f8e83da9d
commit 1947ebd372
11 changed files with 585 additions and 279 deletions

File diff suppressed because one or more lines are too long

View File

@@ -60,6 +60,18 @@ public partial class InkBlotAntlrGrammarBaseListener : IInkBlotAntlrGrammarListe
/// <param name="context">The parse tree.</param>
public virtual void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void EnterTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context) { }
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>
/// <param name="context">The parse tree.</param>
public virtual void ExitTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context) { }
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
/// <para>The default implementation does nothing.</para>
/// </summary>

View File

@@ -55,6 +55,16 @@ public partial class InkBlotAntlrGrammarBaseVisitor<Result> : AbstractParseTreeV
/// <return>The visitor result.</return>
public virtual Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// <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 VisitTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context) { return VisitChildren(context); }
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
/// <para>
/// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>

View File

@@ -51,6 +51,16 @@ public interface IInkBlotAntlrGrammarListener : IParseTreeListener {
/// <param name="context">The parse tree.</param>
void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void EnterTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context);
/// <summary>
/// Exit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
void ExitTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context);
/// <summary>
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
/// </summary>
/// <param name="context">The parse tree.</param>

File diff suppressed because it is too large Load Diff

View File

@@ -44,6 +44,12 @@ public interface IInkBlotAntlrGrammarVisitor<Result> : IParseTreeVisitor<Result>
/// <return>The visitor result.</return>
Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.topLevelStatement"/>.
/// </summary>
/// <param name="context">The parse tree.</param>
/// <return>The visitor result.</return>
Result VisitTopLevelStatement([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementContext context);
/// <summary>
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
/// </summary>
/// <param name="context">The parse tree.</param>

View File

@@ -13,19 +13,30 @@ story: topLevelStatements ;
*/
topLevelStatements:
contentText+
topLevelStatement+
;
topLevelStatement:
contentText
| multiDivert
;
knotLevelStatements:
contentText+
(contentText
| multiDivert
)+
;
stitchLevelStatements:
contentText+
(contentText
| multiDivert
)+
;
innerBlockLevelStatements:
contentText+
(contentText
| multiDivert
)+
;
/*
@@ -52,7 +63,10 @@ inlineLogic:
INLINE_LOGIC_START
WS?
innerLogic
// TODO: += and -= are disabled here (don't know why)
WS?
INLINE_LOGIC_END
// TODO: tags ftw
;
innerLogic:
@@ -97,7 +111,7 @@ expression:
// all possible symbols or word(s) for sequencing
sequenceTypeAnnotation:
SEQUENCE_TYPE_SYMBOL_ANNOTATION
op=SEQUENCE_TYPE_SYMBOL_ANNOTATION
| ONCE
| CYCLE
| SHUFFLE

View File

@@ -0,0 +1,3 @@
namespace InkBlot.ParseHierarchy;
public record MultiDivert : StoryNode;

View File

@@ -1,18 +1,19 @@
using System.Text.RegularExpressions;
using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy;
namespace InkBlot.Visitor;
public partial class Listener
{
private readonly ParseTreeProperty<string> _contentTextValue = new();
private readonly ParseTreeProperty<Content> _contentTextValue = new();
private readonly Regex _escapeRegex = MyRegex();
[GeneratedRegex(@"\\(.)")]
private static partial Regex MyRegex();
private string GetContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
private Content GetContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
{
return _contentTextValue.Get(context);
}
@@ -29,6 +30,6 @@ public partial class Listener
var content = _escapeRegex.Replace(contentWithEscapes, match => match.Groups[1].Value);
// save the result
_contentTextValue.Put(context, content);
_contentTextValue.Put(context, new Content(content));
}
}

View File

@@ -0,0 +1,19 @@
using Antlr4.Runtime.Tree;
using InkBlot.ParseHierarchy;
namespace InkBlot.Visitor;
public partial class Listener
{
private readonly ParseTreeProperty<MultiDivert> _multiDivertValues = new();
private MultiDivert GetMultiDivert(InkBlotAntlrGrammarParser.MultiDivertContext context)
{
return _multiDivertValues.Get(context);
}
public override void ExitMultiDivert(InkBlotAntlrGrammarParser.MultiDivertContext context)
{
_multiDivertValues.Put(context, new MultiDivert());
}
}

View File

@@ -12,8 +12,16 @@ public partial class Listener
{
var storyNodes = context
.topLevelStatements()
.contentText()
.Select(child => new Content(GetContentText(child)));
.topLevelStatement()
.Select(topLevelStatement =>
topLevelStatement.children.Single() switch
{
InkBlotAntlrGrammarParser.ContentTextContext contentTextContext =>
(StoryNode)GetContentText(contentTextContext),
InkBlotAntlrGrammarParser.MultiDivertContext multiDivertContext =>
GetMultiDivert(multiDivertContext),
_ => throw new InvalidOperationException()
});
_story = new Story(storyNodes);
}
}