feat: base structure for getting a MultiDivert.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -60,6 +60,18 @@ public partial class InkBlotAntlrGrammarBaseListener : IInkBlotAntlrGrammarListe
|
|||||||
/// <param name="context">The parse tree.</param>
|
/// <param name="context">The parse tree.</param>
|
||||||
public virtual void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { }
|
public virtual void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { }
|
||||||
/// <summary>
|
/// <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"/>.
|
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
|
||||||
/// <para>The default implementation does nothing.</para>
|
/// <para>The default implementation does nothing.</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ public partial class InkBlotAntlrGrammarBaseVisitor<Result> : AbstractParseTreeV
|
|||||||
/// <return>The visitor result.</return>
|
/// <return>The visitor result.</return>
|
||||||
public virtual Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { return VisitChildren(context); }
|
public virtual Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context) { return VisitChildren(context); }
|
||||||
/// <summary>
|
/// <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"/>.
|
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
|
||||||
/// <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)"/>
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ public interface IInkBlotAntlrGrammarListener : IParseTreeListener {
|
|||||||
/// <param name="context">The parse tree.</param>
|
/// <param name="context">The parse tree.</param>
|
||||||
void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
|
void ExitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
|
||||||
/// <summary>
|
/// <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"/>.
|
/// Enter a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
|
||||||
/// </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
@@ -44,6 +44,12 @@ public interface IInkBlotAntlrGrammarVisitor<Result> : IParseTreeVisitor<Result>
|
|||||||
/// <return>The visitor result.</return>
|
/// <return>The visitor result.</return>
|
||||||
Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
|
Result VisitTopLevelStatements([NotNull] InkBlotAntlrGrammarParser.TopLevelStatementsContext context);
|
||||||
/// <summary>
|
/// <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"/>.
|
/// Visit a parse tree produced by <see cref="InkBlotAntlrGrammarParser.knotLevelStatements"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">The parse tree.</param>
|
/// <param name="context">The parse tree.</param>
|
||||||
|
|||||||
@@ -13,19 +13,30 @@ story: topLevelStatements ;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
topLevelStatements:
|
topLevelStatements:
|
||||||
contentText+
|
topLevelStatement+
|
||||||
|
;
|
||||||
|
|
||||||
|
topLevelStatement:
|
||||||
|
contentText
|
||||||
|
| multiDivert
|
||||||
;
|
;
|
||||||
|
|
||||||
knotLevelStatements:
|
knotLevelStatements:
|
||||||
contentText+
|
(contentText
|
||||||
|
| multiDivert
|
||||||
|
)+
|
||||||
;
|
;
|
||||||
|
|
||||||
stitchLevelStatements:
|
stitchLevelStatements:
|
||||||
contentText+
|
(contentText
|
||||||
|
| multiDivert
|
||||||
|
)+
|
||||||
;
|
;
|
||||||
|
|
||||||
innerBlockLevelStatements:
|
innerBlockLevelStatements:
|
||||||
contentText+
|
(contentText
|
||||||
|
| multiDivert
|
||||||
|
)+
|
||||||
;
|
;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -52,7 +63,10 @@ inlineLogic:
|
|||||||
INLINE_LOGIC_START
|
INLINE_LOGIC_START
|
||||||
WS?
|
WS?
|
||||||
innerLogic
|
innerLogic
|
||||||
|
// TODO: += and -= are disabled here (don't know why)
|
||||||
|
WS?
|
||||||
INLINE_LOGIC_END
|
INLINE_LOGIC_END
|
||||||
|
// TODO: tags ftw
|
||||||
;
|
;
|
||||||
|
|
||||||
innerLogic:
|
innerLogic:
|
||||||
@@ -97,7 +111,7 @@ expression:
|
|||||||
|
|
||||||
// all possible symbols or word(s) for sequencing
|
// all possible symbols or word(s) for sequencing
|
||||||
sequenceTypeAnnotation:
|
sequenceTypeAnnotation:
|
||||||
SEQUENCE_TYPE_SYMBOL_ANNOTATION
|
op=SEQUENCE_TYPE_SYMBOL_ANNOTATION
|
||||||
| ONCE
|
| ONCE
|
||||||
| CYCLE
|
| CYCLE
|
||||||
| SHUFFLE
|
| SHUFFLE
|
||||||
|
|||||||
3
InkBlot/ParseHierarchy/MultiDivert.cs
Normal file
3
InkBlot/ParseHierarchy/MultiDivert.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace InkBlot.ParseHierarchy;
|
||||||
|
|
||||||
|
public record MultiDivert : StoryNode;
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Antlr4.Runtime.Tree;
|
using Antlr4.Runtime.Tree;
|
||||||
|
using InkBlot.ParseHierarchy;
|
||||||
|
|
||||||
namespace InkBlot.Visitor;
|
namespace InkBlot.Visitor;
|
||||||
|
|
||||||
public partial class Listener
|
public partial class Listener
|
||||||
{
|
{
|
||||||
private readonly ParseTreeProperty<string> _contentTextValue = new();
|
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 string GetContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
|
private Content GetContentText(InkBlotAntlrGrammarParser.ContentTextContext context)
|
||||||
{
|
{
|
||||||
return _contentTextValue.Get(context);
|
return _contentTextValue.Get(context);
|
||||||
}
|
}
|
||||||
@@ -29,6 +30,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, 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
|
var storyNodes = context
|
||||||
.topLevelStatements()
|
.topLevelStatements()
|
||||||
.contentText()
|
.topLevelStatement()
|
||||||
.Select(child => new Content(GetContentText(child)));
|
.Select(topLevelStatement =>
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user