当前位置: 首页>>代码示例>>C#>>正文


C# Tokenizer.Next方法代码示例

本文整理汇总了C#中Tokenizer.Next方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.Next方法的具体用法?C# Tokenizer.Next怎么用?C# Tokenizer.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tokenizer的用法示例。


在下文中一共展示了Tokenizer.Next方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        public void Parse(string filename)
        {
            Tokenizer t = new Tokenizer();
            if (!t.FromFile(filename))
                return;

            sections.Clear();
            Section global = this[""];
            Section section = global;

            try
            {
                while(t.Next())
                {
                    if(t.IsSymbol('['))
                    {
                        t.Next();
                        section = this[t.GetItem()];
                        t.Next();
                        t.AssertSymbol(']');
                    }
                    else
                    {
                        string key = t.GetItem();
                        t.Next();
                        t.AssertSymbol('=');
                        t.NextLine();
                        string value = t.GetItem();
                        section[key] = value;
                    }
                }
            }
            catch(Exception e)
            {
                string err = e.ToString();
            }
        }
开发者ID:Tomash667,项目名称:hunters,代码行数:37,代码来源:Config.cs

示例2: ReadInstruction

			public static Instruction ReadInstruction(ref Tokenizer tokenizer) {
				Token token = new Token();
				tokenizer.Next(out token);
				if (token.name != TokenName.KEYWORD) {
					if (token.name == TokenName.CLOSE_PARENTHESIS) {
						return Instruction.COMPLETE;
					}
					return Instruction.INVALID;
				}
				if (token.value.ToLower() == "gear") {
					return Instruction.GEAR;
				} else if (token.value.ToLower() == "head") {
					return Instruction.HEAD;
				} else if (token.value.ToLower() == "body") {
					return Instruction.BODY;
				} else if (token.value.ToLower() == "arms") {
					return Instruction.ARMS;
				} else if (token.value.ToLower() == "waist") {
					return Instruction.WAIST;
				} else if (token.value.ToLower() == "legs") {
					return Instruction.LEGS;
				} else if (token.value.ToLower() == "amulet") {
					return Instruction.AMULET;
				} else {
					return Instruction.INVALID;
				}
			}
开发者ID:followcat,项目名称:monster-avengers,代码行数:27,代码来源:armor_up_wrapper.cs

示例3: NextValue

 private object NextValue(Tokenizer tokenizer) {
   if (tokenizer.Peek() == tokenizer.SeparatorToken || tokenizer.Peek() == tokenizer.NewlineToken) return string.Empty;
   Token current = tokenizer.Next();
   if (current.type == TokenTypeEnum.Separator) {
     return double.NaN;
   } else if (current.type == TokenTypeEnum.String) {
     return current.stringValue;
   } else if (current.type == TokenTypeEnum.Double) {
     return current.doubleValue;
   } else if (current.type == TokenTypeEnum.DateTime) {
     return current.dateTimeValue;
   }
   // found an unexpected token => throw error 
   Error("Unexpected token.", current.stringValue, tokenizer.CurrentLineNumber);
   // this line is never executed because Error() throws an exception
   throw new InvalidOperationException();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:17,代码来源:TableFileParser.cs

示例4: LoadItems

        public static void LoadItems()
        {
            Game.Instance.Log("Loading items...");

            string path = "../../System/items.txt";

            Tokenizer t = new Tokenizer();
            int errors = 0;

            t.AddKeywords(new TupleList<string, Type>{
                {"weapon", Type.Weapon},
                {"gun", Type.Gun},
                {"armor", Type.Armor},
                {"potion", Type.Potion},
                {"ammo", Type.Ammo},
                {"other", Type.Other}
            });

            t.AddKeywords(new TupleList<string, Keyword>{
                {"name", Keyword.Name},
                {"desc", Keyword.Desc},
                {"value", Keyword.Value},
                {"weight", Keyword.Weight},
                {"attack", Keyword.Attack},
                {"defense", Keyword.Defense},
                {"subtype", Keyword.Subtype},
                {"material", Keyword.Material},
                {"range", Keyword.Range},
                {"capacity", Keyword.Capacity}
            });

            t.AddKeywords(new TupleList<string, WeaponType>{
                {"slash", WeaponType.Slash},
                {"pierce", WeaponType.Pierce},
                {"blunt", WeaponType.Blunt}
            });

            t.AddKeywords(new TupleList<string, Material>{
                {"wood", Material.Wood},
                {"iron", Material.Iron},
                {"steel", Material.Steel},
                {"silver", Material.Silver}
            });

            t.AddKeywords(new TupleList<string, AmmoType>{
                {"bullet9mm", AmmoType.Bullet9mm}
            });

            if (!t.FromFile(path))
                throw new Exception(string.Format("Failed to open file \"{0}\".", path));

            try
            {
                while(t.Next())
                {
                retry:
                    try
                    {

                        Item item = new Item();

                        // type
                        item.type = t.GetKeyword<Type>();
                        t.Next();

                        // id
                        item.id = t.GetItem();
                        t.Next();

                        // {
                        t.AssertSymbol('{');
                        t.Next();

                        bool[] have = new bool[(int)Keyword.Max];

                        while(true)
                        {
                            if (t.IsSymbol('}'))
                                break;

                            Keyword key = t.GetKeyword<Keyword>();
                            string key_name = t.GetKeywordName();
                            t.Next();

                            if(have[(int)key])
                                throw new Exception(string.Format("Item '{0}' already have {1}.", item.id, key_name));
                            have[(int)key] = true;

                            if(!CanHave(item.type, key))
                                throw new Exception(string.Format("Item '{0}' can't have {1}.", item.id, key_name));

                            switch(key)
                            {
                                case Keyword.Name:
                                    item.name = t.GetString();
                                    break;
                                case Keyword.Desc:
                                    item.desc = t.GetString();
                                    break;
                                case Keyword.Value:
//.........这里部分代码省略.........
开发者ID:Tomash667,项目名称:hunters,代码行数:101,代码来源:Item.cs


注:本文中的Tokenizer.Next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。