コード例 #1
0
ファイル: Parser.cs プロジェクト: Doom2fan/CSharp-ChronosLib
        public void InitializeDataClass(UDMFParsedMapData data)
        {
            foreach (var block in Blocks.Values)
            {
                var propVal = block.Delegates.Getter(data);

                if (propVal is null)
                {
                    propVal = (IUDMFBlockList)Activator.CreateInstance(block.Delegates.Info.PropertyType);
                    block.Delegates.Setter(data, propVal);
                }
            }
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: Doom2fan/CSharp-ChronosLib
        private void ParseGlobal_Expr_List(UDMFParsedMapData dataClass, ParserInfo info)
        {
            unknownGlobalAssignmentsPooled.Clear();
            unknownBlocksPooled.Clear();

            UDMFToken tok = scanner.LookAhead();

            while (tok.Type == UDMFTokenType.IDENTIFIER)
            {
                ParseGlobal_Expr(dataClass, info);

                tok = scanner.LookAhead();
            }

            if (unknownGlobalAssignmentsPooled.Count > 0)
            {
                dataClass.UnknownGlobalAssignments = new Dictionary <string, UDMFUnknownAssignment> (
                    unknownGlobalAssignmentsPooled,
                    StringComparer.InvariantCultureIgnoreCase
                    );

                unknownGlobalAssignmentsPooled.Clear();
            }

            if (unknownBlocksPooled.Count > 0)
            {
                dataClass.UnknownBlocks = new Dictionary <string, List <UDMFUnknownBlock> > (unknownBlocksPooled.Count);
                foreach (var kvp in unknownBlocksPooled)
                {
                    var pooledList = kvp.Value;
                    var newList    = new List <UDMFUnknownBlock> (pooledList.Count);

                    foreach (var block in pooledList)
                    {
                        newList.Add(block);
                    }

                    dataClass.UnknownBlocks.Add(kvp.Key, newList);

                    pooledList.Clear();
                    pooledList.Capacity = 0;
                }

                unknownBlocksPooled.Clear();
            }
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: Doom2fan/CSharp-ChronosLib
        private void ParseGlobal_Expr(UDMFParsedMapData dataClass, ParserInfo info)
        {
            UDMFToken tok = scanner.Scan();

            if (tok.Type != UDMFTokenType.IDENTIFIER)
            {
                Errors.Add(new UDMFParseError("Unexpected token '" + tok.Text.ToString().Replace("\n", "") + "' found. Expected " + UDMFToken.TokenTypeToString(UDMFTokenType.IDENTIFIER), 0x1001, tok));
                return;
            }

            var ident     = tok;
            var identText = namePool.GetOrCreate(ident.Text);

            tok = scanner.LookAhead();
            switch (tok.Type)
            {
            case UDMFTokenType.BROPEN:
                ParserInfo.BlockInfo block;
                info.Blocks.TryGetValue(identText, out block);
                ParseBlock(dataClass, identText, block);
                break;

            case UDMFTokenType.EQSIGN:
                if (info.GlobalAssignments.TryGetValue(identText, out var assignment))
                {
                    ParseAssignment_Expr(dataClass, assignment);
                }
                else
                {
                    var val = ParseAssignment_Expr(dataClass, null);
                    unknownGlobalAssignmentsPooled.Add(identText, GetUnknownAssignment(val.Value));
                }
                break;

            default:
                Errors.Add(new UDMFParseError("Unexpected token '" + tok.Text.ToString().Replace("\n", "") + "' found.", 0x0002, tok));
                return;
            }

            return;
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: Doom2fan/CSharp-ChronosLib
        private void ParseBlock(UDMFParsedMapData dataClass, string ident, ParserInfo.BlockInfo?info)
        {
            UDMFToken tok = scanner.Scan();

            if (tok.Type != UDMFTokenType.BROPEN)
            {
                Errors.Add(new UDMFParseError("Unexpected token '" + tok.Text.ToString().Replace("\n", "") + "' found. Expected " + UDMFToken.TokenTypeToString(UDMFTokenType.BROPEN), 0x1001, tok));
                return;
            }

            IUDMFBlock block;

            if (info != null)
            {
                block = (IUDMFBlock)Activator.CreateInstance(info.Value.BlockType);
                info.Value.Delegates.Getter(dataClass).AddBlock(block);
            }
            else
            {
                var newBlock = new UDMFUnknownBlock();
                block = newBlock;

                if (!unknownBlocksPooled.TryGetValue(ident, out var unknownBlocksList))
                {
                    unknownBlocksList = new CL_PooledList <UDMFUnknownBlock> ();
                    unknownBlocksPooled.Add(ident, unknownBlocksList);
                }

                unknownBlocksList.Add(newBlock);
            }

            ParseExpr_List(block, info);

            tok = scanner.Scan();
            if (tok.Type != UDMFTokenType.BRCLOSE)
            {
                Errors.Add(new UDMFParseError("Unexpected token '" + tok.Text.ToString().Replace("\n", "") + "' found. Expected " + UDMFToken.TokenTypeToString(UDMFTokenType.BRCLOSE), 0x1001, tok));
                return;
            }
        }