private void GenerateZenFileNodes()
        {
            foreach (IParseTree parseTree in _parseTrees)
            {
                ZenParseTreeVisitor visitor  = new ZenParseTreeVisitor();
                ZenFileNode         fileNode = (ZenFileNode)visitor.Visit(parseTree);
                ZenFileNodes.Add(fileNode);
            }

            _parseTrees = null;
        }
Beispiel #2
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);
        }