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

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);
}
}