예제 #1
0
 /// <summary>
 /// Parses the specified arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
 /// <exception cref="System.NotSupportedException"></exception>
 public override IEnumerable <IDefinition> Parse(ParserArgs args)
 {
     throw new NotSupportedException();
 }
        public void Parse_multiple_types_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"NArmy = {");
            sb.AppendLine(@"	ARMY_MILITARY_POWER_EXPONENT = 0.5	# 0.65");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"NGameplay = {");
            sb.AppendLine(@"	ASCENSION_PERKS_SLOTS = 12");
            sb.AppendLine(@"	JUMP_DRIVE_COOLDOWN = 0");
            sb.AppendLine(@"}");



            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\defines\\t.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(3);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("common\\defines\\t.txt");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("ARMY_MILITARY_POWER_EXPONENT");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NArmy-txt");
                    result[i].Code.Should().Be("NArmy = {\r\n    ARMY_MILITARY_POWER_EXPONENT = 0.5\r\n}");
                    break;

                case 1:
                    result[i].Id.Should().Be("ASCENSION_PERKS_SLOTS");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NGameplay-txt");
                    result[i].Code.Should().Be("NGameplay = {\r\n    ASCENSION_PERKS_SLOTS = 12\r\n}");
                    break;

                case 2:
                    result[i].Id.Should().Be("JUMP_DRIVE_COOLDOWN");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NGameplay-txt");
                    result[i].Code.Should().Be("NGameplay = {\r\n    JUMP_DRIVE_COOLDOWN = 0\r\n}");
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
            }
        }
        public void Parse_lua_multiple_complex_object_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"NDefines_Graphics = {");
            sb.AppendLine(@"	NInterface = {");
            sb.AppendLine(@"		NO_COMBATS_COLOR = { 0.0, 0.0, 0.8 },				-- Color for icons if all combats are successful");
            sb.AppendLine(@"		MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1");
            sb.AppendLine(@"	},");
            sb.AppendLine(@"	NInterface2 = {");
            sb.AppendLine(@"		NO_COMBATS_COLOR = { 0.0, 0.0, 0.8 },				-- Color for icons if all combats are successful");
            sb.AppendLine(@"		MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\defines\\t.lua",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(4);
            for (int i = 0; i < 4; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("common\\defines\\t.lua");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("NO_COMBATS_COLOR");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface-txt");
                    result[i].Code.Should().Be("NDefines_Graphics.NInterface.NO_COMBATS_COLOR = {\r\n    0,\r\n    0,\r\n    0.8\r\n}");
                    break;

                case 1:
                    result[i].Id.Should().Be("MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface-txt");
                    result[i].Code.Should().Be("NDefines_Graphics.NInterface.MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1");
                    break;

                case 2:
                    result[i].Id.Should().Be("NO_COMBATS_COLOR");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface2-txt");
                    result[i].Code.Should().Be("NDefines_Graphics.NInterface2.NO_COMBATS_COLOR = {\r\n    0,\r\n    0,\r\n    0.8\r\n}");
                    break;

                case 3:
                    result[i].Id.Should().Be("MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface2-txt");
                    result[i].Code.Should().Be("NDefines_Graphics.NInterface2.MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1");
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
            }
        }
예제 #4
0
 /// <summary>
 /// Parses the specified arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
 public abstract IEnumerable <IDefinition> Parse(ParserArgs args);
예제 #5
0
 public override void Select(BinaryExpression expr, ParserArgs args)
 {
     throw new NotImplementedException();
 }
예제 #6
0
        /// <summary>
        /// Parses the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
        public override IEnumerable <IDefinition> Parse(ParserArgs args)
        {
            var data = TryParse(args, false);

            if (data.Error != null)
            {
                return(new List <IDefinition>()
                {
                    TranslateScriptError(data.Error, args)
                });
            }
            var result = new List <IDefinition>();

            if (data.Values?.Count() > 0)
            {
                foreach (var dataItem in data.Values)
                {
                    if (dataItem.Values != null)
                    {
                        foreach (var item in dataItem.Values)
                        {
                            var    definition = GetDefinitionInstance();
                            string id         = EvalDefinitionId(item.Values, item.Key);
                            MapDefinitionFromArgs(ConstructArgs(args, definition, typeOverride: $"{dataItem.Key}-{Common.Constants.TxtType}"));
                            definition.Id            = TrimId(id);
                            definition.ValueType     = ValueType.SpecialVariable;
                            definition.Code          = FormatCode(item, dataItem.Key);
                            definition.OriginalCode  = FormatCode(item, skipVariables: true);
                            definition.CodeSeparator = Constants.CodeSeparators.ClosingSeparators.CurlyBracket;
                            definition.CodeTag       = dataItem.Key;
                            var tags = ParseScriptTags(item.Values, item.Key);
                            if (tags.Any())
                            {
                                foreach (var tag in tags)
                                {
                                    var lower = tag.ToLowerInvariant();
                                    if (!definition.Tags.Contains(lower))
                                    {
                                        definition.Tags.Add(lower);
                                    }
                                }
                            }
                            result.Add(definition);
                        }
                    }
                    else
                    {
                        // No operator detected means something is wrong in the mod file
                        if (string.IsNullOrWhiteSpace(dataItem.Operator))
                        {
                            var definesError = DIResolver.Get <IScriptError>();
                            definesError.Message = $"There appears to be a syntax error detected in: {args.File}";
                            return(new List <IDefinition>()
                            {
                                TranslateScriptError(definesError, args)
                            });
                        }
                    }
                }
            }
            return(result);
        }
예제 #7
0
        /// <summary>
        /// Parses the simple types.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="typeOverride">The type override.</param>
        /// <param name="isFirstLevel">if set to <c>true</c> [is first level].</param>
        /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
        protected virtual IEnumerable <IDefinition> ParseSimpleTypes(IEnumerable <IScriptElement> values, ParserArgs args, string parent = Shared.Constants.EmptyParam, string typeOverride = Shared.Constants.EmptyParam, bool isFirstLevel = true)
        {
            var result = new List <IDefinition>();

            if (values?.Count() > 0)
            {
                foreach (var item in values.Where(p => p.IsSimpleType))
                {
                    var definition = GetDefinitionInstance();
                    MapDefinitionFromArgs(ConstructArgs(args, definition, isFirstLevel: isFirstLevel));
                    definition.OriginalCode = definition.Code = FormatCode(item, parent);
                    if (!isFirstLevel)
                    {
                        definition.OriginalCode  = FormatCode(item);
                        definition.CodeTag       = parent;
                        definition.CodeSeparator = Shared.Constants.CodeSeparators.ClosingSeparators.CurlyBracket;
                    }
                    bool typeAssigned = false;
                    var  op           = item.Operator ?? string.Empty;
                    if (op.Equals(Constants.Scripts.EqualsOperator.ToString()))
                    {
                        if (item.Key.StartsWith(Constants.Scripts.Namespace, StringComparison.OrdinalIgnoreCase))
                        {
                            typeAssigned         = true;
                            definition.Id        = $"{Path.GetFileNameWithoutExtension(args.File)}-{TrimId(item.Key)}";
                            definition.ValueType = ValueType.Namespace;
                        }
                        else if (item.Key.StartsWith(Constants.Scripts.VariableId))
                        {
                            typeAssigned         = true;
                            definition.Id        = TrimId(item.Key);
                            definition.ValueType = ValueType.Variable;
                        }
                    }
                    if (typeAssigned)
                    {
                        result.Add(definition);
                    }
                }
            }
            return(result);
        }
예제 #8
0
 /// <summary>
 /// Parses the specified arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
 public override IEnumerable <IDefinition> Parse(ParserArgs args)
 {
     return(ParseRoot(args));
 }
예제 #9
0
 public override void Where(ParameterExpression expr, ParserArgs args)
 {
     args.Builder.Append(' ');
     args.Builder.Append(expr.Name);
     args.Builder.Append('.');
 }
예제 #10
0
 /// <summary>
 /// Parses the specified arguments.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
 public override IEnumerable <IDefinition> Parse(ParserArgs args)
 {
     return(ParseSecondLevel(args));
 }
예제 #11
0
 public override void Object(MemberExpression expr, ParserArgs args)
 {
     throw new NotImplementedException();
 }
        public void Parse_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"l_english:");
            sb.AppendLine(@" NEW_ACHIEVEMENT_2_0_NAME:0 ""Brave New World""");
            sb.AppendLine(@" NEW_ACHIEVEMENT_2_0_DESC:0 ""Colonize a planet""");
            sb.AppendLine(@" NEW_ACHIEVEMENT_2_1_NAME:0 ""Digging Deep""");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"l_english:");
            sb2.AppendLine(@" NEW_ACHIEVEMENT_2_0_NAME:0 ""Brave New World""");

            var sb3 = new StringBuilder();

            sb3.AppendLine(@"l_english:");
            sb3.AppendLine(@" NEW_ACHIEVEMENT_2_0_DESC:0 ""Colonize a planet""");

            var sb4 = new StringBuilder();

            sb4.AppendLine(@"l_english:");
            sb4.AppendLine(@" NEW_ACHIEVEMENT_2_1_NAME:0 ""Digging Deep""");

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "loc\\loc.yml",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new LocalizationParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(3);
            for (int i = 0; i < 3; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("loc\\loc.yml");
                switch (i)
                {
                case 0:
                    result[i].Code.Trim().Should().Be(sb2.ToString().Trim());
                    result[i].Id.Should().Be("NEW_ACHIEVEMENT_2_0_NAME");
                    result[i].ValueType.Should().Be(Common.ValueType.SpecialVariable);
                    break;

                case 1:
                    result[i].Code.Trim().Should().Be(sb3.ToString().Trim());
                    result[i].Id.Should().Be("NEW_ACHIEVEMENT_2_0_DESC");
                    result[i].ValueType.Should().Be(Common.ValueType.SpecialVariable);
                    break;

                case 2:
                    result[i].Code.Trim().Should().Be(sb4.ToString().Trim());
                    result[i].Id.Should().Be("NEW_ACHIEVEMENT_2_1_NAME");
                    result[i].ValueType.Should().Be(Common.ValueType.SpecialVariable);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("loc\\l_english-yml");
            }
        }
예제 #13
0
        public void Validate_result_should_not_be_null()
        {
            DISetup.SetupContainer();
            var sb = new StringBuilder();

            sb.AppendLine(@"@test = 1");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_1 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		NOT = {");
            sb.AppendLine(@"			has_country_flag = asl_modify_3");
            sb.AppendLine(@"			has_country_flag = asl_modify_5");
            sb.AppendLine(@"		}");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_3 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		has_country_flag = asl_modify_3");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_5 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		has_country_flag = asl_modify_5");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"### END TEMPLATE:effects ###");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\fake\\fake.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new ValidateParser(new CodeParser(new Logger()), null);
            var result = parser.Validate(args);

            result.Should().NotBeNullOrEmpty();
        }
예제 #14
0
 public UpdateSetParser(LambdaExpression _NewExpression, StringBuilder Code, ParserArgs _ParserArgs)
 {
     if (_NewExpression.Body is NewExpression)
     {
         var _Set     = new List <object>();
         var body     = _NewExpression.Body as NewExpression;
         var _Members = body.Members;
         for (int i = 0; i < body.Members.Count; i++)
         {
             var _Member    = body.Members[i];
             var _Arguments = body.Arguments[i];
             var _Count     = _ParserArgs.SqlParameters.Count;
             if (_Arguments is ConstantExpression)
             {
                 if (_Member.Name.StartsWith("SqlString"))
                 {
                     var _ConstantExpression = _Arguments as ConstantExpression;
                     _Set.Add(_ConstantExpression.Value);
                 }
                 else
                 {
                     var _ConstantExpression = _Arguments as ConstantExpression;
                     var _Name  = _Member.Name;
                     var _Value = _ConstantExpression.Value;
                     _Set.Add(_Name + "=@" + _Name + "_" + _Count);
                     _ParserArgs.SqlParameters.Add(_Name + "_" + _Count, _Value);
                 }
             }
             else if (_Arguments is MemberExpression)
             {
                 var _MemberExpression = _Arguments as MemberExpression;
                 var _Name             = _Member.Name;
                 var _Value            = Parser.Eval(_MemberExpression).ToStr();
                 _Set.Add(_Name + "=@" + _Name + "_" + _Count);
                 _ParserArgs.SqlParameters.Add(_Name + "_" + _Count, _Value);
             }
             else if (_Arguments is BinaryExpression)
             {
                 var _BinaryExpression = _Arguments as BinaryExpression;
                 if (_BinaryExpression.NodeType == ExpressionType.Add)
                 {
                     if (_BinaryExpression.Left is MemberExpression)
                     {
                         var _Left      = _BinaryExpression.Left as MemberExpression;
                         var _Left_Name = _Left.Member.Name;
                         var _Name      = _Member.Name;
                         var _Value     = _Left_Name + "+" + Parser.Eval(_BinaryExpression.Right).ToStr();
                         _Set.Add(_Name + "=" + _Value);
                     }
                     else if (
                         _BinaryExpression.Left is ConstantExpression &&
                         _BinaryExpression.Left.Type == typeof(string) &&
                         _Member.Name.StartsWith("SqlString"))
                     {
                         var _Left        = _BinaryExpression.Left as ConstantExpression;
                         var _Right_Value = Parser.Eval(_BinaryExpression.Right).ToStr();
                         var _Sql         = _Left.Value.ToStr() + _Right_Value;
                         _Set.Add(_Sql);
                     }
                 }
             }
         }
         Code.Append(string.Join(",", _Set));
     }
     else
     {
         throw new DbFrameException("无法解析的表达式!");
     }
 }
예제 #15
0
        public void Parse_should_yield_results()
        {
            DISetup.SetupContainer();
            var sb = new StringBuilder();

            sb.AppendLine(@"@test = 1");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_1 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		NOT = {");
            sb.AppendLine(@"			has_country_flag = asl_modify_3");
            sb.AppendLine(@"			has_country_flag = asl_modify_5");
            sb.AppendLine(@"		}");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_3 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		has_country_flag = asl_modify_3");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"asl_mode_options_5 = {");
            sb.AppendLine(@"	potential = {");
            sb.AppendLine(@"		has_country_flag = asl_modify_5");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	allow = {");
            sb.AppendLine(@"		always = yes");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	effect = {");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");
            sb.AppendLine(@"");
            sb.AppendLine(@"### END TEMPLATE:effects ###");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"asl_mode_options_1 = {");
            sb2.AppendLine(@"	potential = {");
            sb2.AppendLine(@"		NOT = {");
            sb2.AppendLine(@"			has_country_flag = asl_modify_3");
            sb2.AppendLine(@"			has_country_flag = asl_modify_5");
            sb2.AppendLine(@"		}");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"	allow = {");
            sb2.AppendLine(@"		always = yes");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"	effect = {");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"}");

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\fake\\fake.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new DefaultParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(4);
            for (int i = 0; i < 4; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("common\\fake\\fake.txt");
                switch (i)
                {
                case 0:
                    result[i].Code.Trim().Should().Be("@test = 1");
                    result[i].Id.Should().Be("@test");
                    result[i].ValueType.Should().Be(ValueType.Variable);
                    break;

                case 1:
                    result[i].Id.Should().Be("asl_mode_options_1");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                case 2:
                    result[i].Id.Should().Be("asl_mode_options_3");
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                case 3:
                    result[i].Id.Should().Be("asl_mode_options_5");
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("common\\fake\\txt");
            }
        }
예제 #16
0
 public override void OrderBy(ParameterExpression expr, ParserArgs args)
 {
     throw new NotImplementedException();
 }
예제 #17
0
        public JoinTableParser(LambdaExpression _LambdaExpression, StringBuilder Code, Dictionary <string, string> Alias, ParserArgs _ParserArgs, string JoinStr, string JoinTabName)
        {
            if (!Alias.ContainsKey(JoinTabName))
            {
                throw new DbFrameException("链接表 别名未找到!");
            }

            if (_LambdaExpression.Body is BinaryExpression)
            {
                var body = (_LambdaExpression.Body as BinaryExpression);
                Code.Append(" " + JoinStr + " ");
                var ByName  = JoinTabName;
                var TabName = Alias[ByName] + " AS " + ByName;
                Code.Append(" " + TabName + " ON ");
                Parser.Where(_LambdaExpression, _ParserArgs);
                Code.Append(_ParserArgs.Builder);
            }
        }
        public void Parse_gfx_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"bitmapfonts = {");
            sb.AppendLine(@"");
            sb.AppendLine(@"	### ship size icons ###");
            sb.AppendLine(@"");
            sb.AppendLine(@"	bitmapfont = {");
            sb.AppendLine(@"		name = ""GFX_text_military_size_1""");
            sb.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds""");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"	");
            sb.AppendLine(@"	bitmapfont = {");
            sb.AppendLine(@"		name = ""GFX_text_military_size_2""");
            sb.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_2.dds""");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");


            var sb2 = new StringBuilder();

            sb2.AppendLine(@"bitmapfonts = {");
            sb2.AppendLine(@"	bitmapfont = {");
            sb2.AppendLine(@"		name = ""GFX_text_military_size_1""");
            sb2.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds""");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"}");


            var sb3 = new System.Text.StringBuilder();

            sb3.AppendLine(@"bitmapfonts = {");
            sb3.AppendLine(@"	bitmapfont = {");
            sb3.AppendLine(@"		name = ""GFX_text_military_size_2""");
            sb3.AppendLine(@"		texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_2.dds""");
            sb3.AppendLine(@"	}");
            sb3.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gfx\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(2);
            for (int i = 0; i < 2; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gfx\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("GFX_text_military_size_1");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                case 1:
                    result[i].Id.Should().Be("GFX_text_military_size_2");
                    result[i].Code.Should().Be(sb3.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gfx\\gfx");
            }
        }
예제 #19
0
        /// <summary>
        /// Parses the complex types.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="typeOverride">The type override.</param>
        /// <param name="isFirstLevel">if set to <c>true</c> [is first level].</param>
        /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
        protected virtual IEnumerable <IDefinition> ParseComplexTypes(IEnumerable <IScriptElement> values, ParserArgs args, string parent = Shared.Constants.EmptyParam, string typeOverride = Shared.Constants.EmptyParam, bool isFirstLevel = true)
        {
            var result = new List <IDefinition>();

            if (values?.Count() > 0)
            {
                foreach (var item in values.Where(p => !p.IsSimpleType))
                {
                    var definition = GetDefinitionInstance();
                    var sbLangs    = new StringBuilder();
                    if (item.Values != null && item.Values.Any(s => s.Key.Equals(Constants.Scripts.LanguagesId, StringComparison.OrdinalIgnoreCase)))
                    {
                        var langNode = item.Values.FirstOrDefault(p => p.Key.Equals(Constants.Scripts.LanguagesId, StringComparison.OrdinalIgnoreCase));
                        if (langNode.Values?.Count() > 0)
                        {
                            foreach (var value in langNode.Values.OrderBy(p => p.Key))
                            {
                                sbLangs.Append($"{TrimId(value.Key)}-");
                            }
                        }
                    }
                    string id = EvalDefinitionId(item.Values, item.Key);
                    if (sbLangs.Length > 0)
                    {
                        id = $"{sbLangs}{id}";
                    }
                    MapDefinitionFromArgs(ConstructArgs(args, definition, typeOverride: typeOverride, isFirstLevel: isFirstLevel));
                    definition.Id           = TrimId(id);
                    definition.ValueType    = ValueType.Object;
                    definition.OriginalCode = definition.Code = FormatCode(item, parent);
                    if (!isFirstLevel)
                    {
                        definition.OriginalCode  = FormatCode(item, skipVariables: true);
                        definition.CodeTag       = parent;
                        definition.CodeSeparator = Shared.Constants.CodeSeparators.ClosingSeparators.CurlyBracket;
                    }
                    var tags = ParseScriptTags(item.Values, item.Key);
                    if (tags.Any())
                    {
                        foreach (var tag in tags)
                        {
                            var lower = tag.ToLowerInvariant();
                            if (!definition.Tags.Contains(lower))
                            {
                                definition.Tags.Add(lower);
                            }
                        }
                    }
                    result.Add(definition);
                }
            }
            return(result);
        }
        public void Parse_gfx_bitmap_type_override_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"bitmapfonts = {");
            sb.AppendLine(@"	 bitmapfont_override = {");
            sb.AppendLine(@"		name = ""large_title_font""");
            sb.AppendLine(@"        ttf_font = ""Easter_bigger""");
            sb.AppendLine(@"        ttf_size = ""30""");
            sb.AppendLine(@"		languages = { ""l_russian"" ""l_polish"" }");
            sb.AppendLine(@"	 }	");
            sb.AppendLine(@"	 bitmapfont_override = {");
            sb.AppendLine(@"		name = ""large_title_font""");
            sb.AppendLine(@"        ttf_font = ""Easter_bigger""");
            sb.AppendLine(@"        ttf_size = ""30""");
            sb.AppendLine(@"		languages = { ""l_russian"" ""l_polish"" }");
            sb.AppendLine(@"	 }	");
            sb.AppendLine(@"}");


            var sb2 = new StringBuilder();

            sb2.AppendLine(@"bitmapfonts = {");
            sb2.AppendLine(@"	bitmapfont_override = {");
            sb2.AppendLine(@"		name = ""large_title_font""");
            sb2.AppendLine(@"		ttf_font = ""Easter_bigger""");
            sb2.AppendLine(@"		ttf_size = ""30""");
            sb2.AppendLine(@"		languages = {");
            sb2.AppendLine(@"			""l_russian""");
            sb2.AppendLine(@"			""l_polish""");
            sb2.AppendLine(@"		}");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gfx\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(2);
            for (int i = 0; i < 2; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gfx\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("l_polish-l_russian-large_title_font");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                case 1:
                    result[i].Id.Should().Be("l_polish-l_russian-large_title_font");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gfx\\gfx");
            }
        }
예제 #21
0
        /// <summary>
        /// Parses the complex script nodes for variables.
        /// </summary>
        /// <param name="values">The nodes.</param>
        /// <param name="args">The arguments.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="typeOverride">The type override.</param>
        /// <param name="isFirstLevel">if set to <c>true</c> [is first level].</param>
        /// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
        protected virtual IEnumerable <IDefinition> ParseTypesForVariables(IEnumerable <IScriptElement> values, ParserArgs args, string parent = Shared.Constants.EmptyParam, string typeOverride = Shared.Constants.EmptyParam, bool isFirstLevel = true)
        {
            var result = new List <IDefinition>();

            if (values?.Count() > 0)
            {
                foreach (var item in values)
                {
                    if (item.Values?.Count() > 0)
                    {
                        var variables = ParseSimpleTypes(item.Values, args, parent, typeOverride, isFirstLevel);
                        if (variables.Any())
                        {
                            result.AddRange(variables);
                        }
                        variables = ParseTypesForVariables(item.Values, args, parent, typeOverride, isFirstLevel);
                        if (variables.Any())
                        {
                            result.AddRange(variables);
                        }
                    }
                }
            }
            return(result);
        }
        public void Parse_gui_edge_case_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"guiTypes = {	");
            sb.AppendLine(@"	containerWindowType = { ");
            sb.AppendLine(@"		name = ""test""");
            sb.AppendLine(@"	}		");
            sb.AppendLine(@"}");
            sb.AppendLine(@"guiTypes = {	");
            sb.AppendLine(@"	containerWindowType = { ");
            sb.AppendLine(@"		name = ""test2""");
            sb.AppendLine(@"	}		");
            sb.AppendLine(@"}");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"guiTypes = {");
            sb2.AppendLine(@"	containerWindowType = {");
            sb2.AppendLine(@"		name = ""test""");
            sb2.AppendLine(@"	}");
            sb2.AppendLine(@"}");

            var sb3 = new StringBuilder();

            sb3.AppendLine(@"guiTypes = {");
            sb3.AppendLine(@"	containerWindowType = {");
            sb3.AppendLine(@"		name = ""test2""");
            sb3.AppendLine(@"	}");
            sb3.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gui\\gui.gui",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(2);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gui\\gui.gui");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("test");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                case 1:
                    result[i].Id.Should().Be("test2");
                    result[i].Code.Should().Be(sb3.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gui\\gui");
            }
        }
예제 #23
0
        public void Parse_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"@test = 1");
            sb.AppendLine(@"");
            sb.AppendLine(@"namespace = dmm_mod");
            sb.AppendLine(@"");
            sb.AppendLine(@"country_event = {");
            sb.AppendLine(@"    id = dmm_mod.1");
            sb.AppendLine(@"    hide_window = yes");
            sb.AppendLine(@"    is_triggered_only = yes");
            sb.AppendLine(@"");
            sb.AppendLine(@"    trigger = {");
            sb.AppendLine(@"        has_global_flag = dmm_mod_1");
            sb.AppendLine(@"    }");
            sb.AppendLine(@"");
            sb.AppendLine(@"    after = {");
            sb.AppendLine(@"        remove_global_flag = dmm_mod_1_opened");
            sb.AppendLine(@"    }");
            sb.AppendLine(@"");
            sb.AppendLine(@"    immediate = {");
            sb.AppendLine(@"        country_event = {");
            sb.AppendLine(@"            id = asl_options.1");
            sb.AppendLine(@"        }");
            sb.AppendLine(@"    }");
            sb.AppendLine(@"}");


            var sb2 = new StringBuilder();

            sb2.AppendLine(@"country_event = {");
            sb2.AppendLine(@"    id = dmm_mod.1");
            sb2.AppendLine(@"    hide_window = yes");
            sb2.AppendLine(@"    is_triggered_only = yes");
            sb2.AppendLine(@"    trigger = {");
            sb2.AppendLine(@"        has_global_flag = dmm_mod_1");
            sb2.AppendLine(@"    }");
            sb2.AppendLine(@"    after = {");
            sb2.AppendLine(@"        remove_global_flag = dmm_mod_1_opened");
            sb2.AppendLine(@"    }");
            sb2.AppendLine(@"    immediate = {");
            sb2.AppendLine(@"        country_event = {");
            sb2.AppendLine(@"            id = asl_options.1");
            sb2.AppendLine(@"        }");
            sb2.AppendLine(@"    }");
            sb2.AppendLine(@"}");

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "events\\fake.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new KeyParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(3);
            for (int i = 0; i < 3; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("events\\fake.txt");
                switch (i)
                {
                case 0:
                    result[i].Code.Trim().Should().Be("@test = 1");
                    result[i].Id.Should().Be("@test");
                    result[i].ValueType.Should().Be(ValueType.Variable);
                    break;

                case 1:
                    result[i].Id.Should().Be("fake-namespace");
                    result[i].ValueType.Should().Be(ValueType.Namespace);
                    break;

                case 2:
                    result[i].Id.Should().Be("dmm_mod.1");
                    result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs());
                    result[i].ValueType.Should().Be(ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("events\\txt");
            }
        }
        public void Parse_gfx_variable_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"@test1 = 0");
            sb.AppendLine(@"spriteTypes = {");
            sb.AppendLine(@"	@test2 = 1");
            sb.AppendLine(@"	spriteType = {");
            sb.AppendLine(@"	    @test3 = 1");
            sb.AppendLine(@"		name = ""GFX_dmm_mod_1""");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gfx\\gfx.gfx",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(4);
            for (int i = 0; i < 2; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gfx\\gfx.gfx");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("@test1");
                    result[i].CodeTag.Should().BeNullOrWhiteSpace();
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                case 1:
                    result[i].Id.Should().Be("@test2");
                    result[i].CodeTag.Should().Be("spriteTypes");
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                case 2:
                    result[i].Id.Should().Be("@test3");
                    result[i].CodeTag.Should().Be("spriteTypes");
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                case 3:
                    result[i].Id.Should().Be("GFX_dmm_mod_1");
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gfx\\gfx");
            }
        }
        public void Parse_complex_type_edge_case_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"	NInterface = { TOPBAR_BUTTONS_SHORTCUTS				= {");
            sb.AppendLine(@"		""contacts"" ""F1""");
            sb.AppendLine(@"		""situation"" ""F2""");
            sb.AppendLine(@"		""technology"" ""F3""");
            sb.AppendLine(@"		""empire"" ""F4""");
            sb.AppendLine(@"		""leaders"" ""F5""");
            sb.AppendLine(@"		""species"" ""F6""");
            sb.AppendLine(@"		""ship_designer"" ""F7""");
            sb.AppendLine(@"		""fleet_manager"" ""F8""");
            sb.AppendLine(@"		""edicts"" ""F9""");
            sb.AppendLine(@"		""policies"" ""F10""");
            sb.AppendLine(@"		}}");

            var sb2 = new StringBuilder();

            sb2.AppendLine(@"NInterface = {");
            sb2.AppendLine(@"	TOPBAR_BUTTONS_SHORTCUTS = {");
            sb2.AppendLine(@"		""contacts""");
            sb2.AppendLine(@"		""F1""");
            sb2.AppendLine(@"		""situation""");
            sb2.AppendLine(@"		""F2""");
            sb2.AppendLine(@"		""technology""");
            sb2.AppendLine(@"		""F3""");
            sb2.AppendLine(@"		""empire""");
            sb2.AppendLine(@"		""F4""");
            sb2.AppendLine(@"		""leaders""");
            sb2.AppendLine(@"		""F5""");
            sb2.AppendLine(@"		""species""");
            sb2.AppendLine(@"		""F6""");
            sb2.AppendLine(@"		""ship_designer""");
            sb2.AppendLine(@"		""F7""");
            sb2.AppendLine(@"		""fleet_manager""");
            sb2.AppendLine(@"		""F8""");
            sb2.AppendLine(@"		""edicts""");
            sb2.AppendLine(@"		""F9""");
            sb2.AppendLine(@"		""policies""");
            sb2.AppendLine(@"		""F10""");
            sb2.AppendLine(@"	}");
            sb2.Append('}');

            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\defines\\t.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(1);
            for (int i = 0; i < 1; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("common\\defines\\t.txt");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("TOPBAR_BUTTONS_SHORTCUTS");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Code.Should().Be(sb2.ToString().ReplaceTabs());
                    result[i].Type.Should().Be("common\\defines\\NInterface-txt");
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
            }
        }
        public void Parse_gui_variable_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"@sort_button_height = 80");
            sb.AppendLine(@"guiTypes = {");
            sb.AppendLine(@"	@entry_info_height = 17");
            sb.AppendLine(@"	# Button in the lower right of the main view, opening the Alliance View.");
            sb.AppendLine(@"	containerWindowType = {");
            sb.AppendLine(@"	    @why_am_i_here = 17");
            sb.AppendLine(@"		name = ""alliance_button_window""");
            sb.AppendLine(@"		position = { x = -458 y = 43 }");
            sb.AppendLine(@"	}");
            sb.AppendLine(@"}");


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "gui\\gui.gui",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new GraphicsParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count().Should().Be(4);
            for (int i = 0; i < 3; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("gui\\gui.gui");
                switch (i)
                {
                case 0:
                    result[i].Id.Should().Be("@sort_button_height");
                    result[i].CodeTag.Should().BeNullOrWhiteSpace();
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                case 1:
                    result[i].Id.Should().Be("@entry_info_height");
                    result[i].CodeTag.Should().Be("guiTypes");
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                case 2:
                    result[i].Id.Should().Be("alliance_button_window");
                    result[i].ValueType.Should().Be(Common.ValueType.Object);
                    break;

                case 3:
                    result[i].Id.Should().Be("@why_am_i_here");
                    result[i].CodeTag.Should().Be("guiTypes");
                    result[i].ValueType.Should().Be(Common.ValueType.Variable);
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
                result[i].Type.Should().Be("gui\\gui");
            }
        }
        public void Parse_should_yield_results()
        {
            DISetup.SetupContainer();

            var sb = new StringBuilder();

            sb.AppendLine(@"NCamera = {FOV							= 35 # Field-of-View");
            sb.AppendLine(@"		# Used for all ships");
            sb.AppendLine(@"		ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR = 	{ -1.0 -0.6 0.3 }");
            sb.AppendLine(@"}");
            sb.AppendLine(@"NGraphics = {");
            sb.AppendLine(@"		CAMERA_DISTANCE_TO_ZOOM				= 10.0");
            sb.AppendLine(@"}");


            var sb2 = new StringBuilder();

            sb2.AppendLine(@"NCamera = {");
            sb2.AppendLine(@"    FOV = 35");
            sb2.Append('}');

            var sb3 = new System.Text.StringBuilder();

            sb3.AppendLine(@"NCamera = {");
            sb3.AppendLine(@"    ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR = {");
            sb3.AppendLine(@"        -1");
            sb3.AppendLine(@"        -0.6");
            sb3.AppendLine(@"        0.3");
            sb3.AppendLine(@"    }");
            sb3.Append('}');

            var sb4 = new StringBuilder();

            sb4.AppendLine(@"NGraphics = {");
            sb4.AppendLine(@"    CAMERA_DISTANCE_TO_ZOOM = 10");
            sb4.Append('}');


            var args = new ParserArgs()
            {
                ContentSHA      = "sha",
                ModDependencies = new List <string> {
                    "1"
                },
                File    = "common\\defines\\t.txt",
                Lines   = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries),
                ModName = "fake"
            };
            var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null);
            var result = parser.Parse(args).ToList();

            result.Should().NotBeNullOrEmpty();
            result.Count.Should().Be(3);
            for (int i = 0; i < 3; i++)
            {
                result[i].ContentSHA.Should().Be("sha");
                result[i].Dependencies.First().Should().Be("1");
                result[i].File.Should().Be("common\\defines\\t.txt");
                switch (i)
                {
                case 0:
                    result[i].Code.Trim().Should().Be(sb2.ToString().Trim());
                    result[i].Id.Should().Be("FOV");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NCamera-txt");
                    break;

                case 1:
                    result[i].Code.Trim().Should().Be(sb3.ToString().Trim());
                    result[i].Id.Should().Be("ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NCamera-txt");
                    break;

                case 2:
                    result[i].Code.Trim().Should().Be(sb4.ToString().Trim());
                    result[i].Id.Should().Be("CAMERA_DISTANCE_TO_ZOOM");
                    result[i].ValueType.Should().Be(ValueType.SpecialVariable);
                    result[i].Type.Should().Be("common\\defines\\NGraphics-txt");
                    break;

                default:
                    break;
                }
                result[i].ModName.Should().Be("fake");
            }
        }
예제 #28
0
 public XmlParser(ParserArgs parserArgs) : base(parserArgs)
 {
 }
예제 #29
0
 private void DealConstantExpression(ConstantExpression _Expression, ParserArgs _ParserArgs)
 {
     this.Eval(_Expression, _ParserArgs);
 }
예제 #30
0
 public override void Where(MemberExpression expr, ParserArgs args)
 {
     Parser.Where(expr.Expression, args);
     args.Builder.Append(expr.Member.Name);
 }