feat: base structure for getting a MultiDivert.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
19
InkBlot/Visitor/ListenerMultiDivert.cs
Normal file
19
InkBlot/Visitor/ListenerMultiDivert.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user