Exemple #1
0
        public override ZenNode VisitMain(ZenParser.MainContext ctx)
        {
            ZenParser.HeadContext headCtx = ctx.head();

            ZenFileNode fileNode = new ZenFileNode
            {
                Version      = int.Parse(headCtx.version.Text),
                Type         = headCtx.zenType.Text,
                SaveGame     = int.Parse(headCtx.saveGame.Text),
                DateTime     = GetDateTime(headCtx.date.Text, headCtx.time.Text),
                User         = headCtx.user.Text,
                ObjectsCount = int.Parse(headCtx.objectsCount.Text),
            };

            foreach (IParseTree childCtx in ctx.body.children)   //ctx.body is oCWorld
            {
                if (childCtx is ZenParser.BlockContext blockCtx) // childCtx is VobTree | WayNet | EndMarker
                {
                    switch (blockCtx.blockName().GetText())
                    {
                    case VobTree:
                        fileNode.VobTree = (ZenBlockNode)VisitBlock(blockCtx);
                        break;

                    case WayNet:
                        fileNode.WayNet = (ZenBlockNode)VisitBlock(blockCtx);
                        break;

                    case EndMarker:
                        break;

                    default:
                        throw new Exception($"Invalid section: {blockCtx.blockName().GetText()}");
                    }
                }
            }

            return(fileNode);
        }
Exemple #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="ZenParser.head"/>.
 /// <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 VisitHead([NotNull] ZenParser.HeadContext context)
 {
     return(VisitChildren(context));
 }