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


C# Tokenizer.AcceptOrThrow方法代码示例

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


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

示例1: ParseTypeReference

	public static TypeReference ParseTypeReference (Tokenizer tokenizer)
	{
		TypeReference tr = new TypeReference ();
		StringBuilder result = new StringBuilder ();

		if (tokenizer.Accept (Token2Type.Identifier, "const"))
			tr.IsConst = true;

		if (tokenizer.Accept (Token2Type.Identifier, "unsigned"))
			result.Append ("unsigned");

		if (tokenizer.Accept (Token2Type.Identifier, "const"))
			tr.IsConst = true;

		result.Append (tokenizer.GetIdentifier ());

		if (tokenizer.Accept (Token2Type.Punctuation, ":")) {
			tokenizer.AcceptOrThrow (Token2Type.Punctuation, ":");
			result.Append ("::");
			result.Append (tokenizer.GetIdentifier ());
		}

		if (tokenizer.Accept (Token2Type.Identifier, "const"))
			tr.IsConst = true;

		while (tokenizer.Accept (Token2Type.Punctuation, "*"))
			result.Append ("*");

		if (tokenizer.Accept (Token2Type.Identifier, "const"))
			tr.IsConst = true;

		if (tokenizer.Accept (Token2Type.Punctuation, "&"))
			result.Append ("&");

		if (tokenizer.Accept (Token2Type.Identifier, "const"))
			tr.IsConst = true;

		//Console.WriteLine ("ParseTypeReference: parsed '{0}'", result.ToString ());

		tr.Value = result.ToString ();

		return tr;
	}
开发者ID:kangaroo,项目名称:moon,代码行数:43,代码来源:Generator.cs

示例2: ParseMembers


//.........这里部分代码省略.........
						return false;
					continue;
				case "typedef":
					StringBuilder requisite = new StringBuilder ();
					requisite.Append (tokenizer.CurrentToken.value);
					requisite.Append (' ');
					tokenizer.Advance (true);
					while (!tokenizer.Accept (Token2Type.Punctuation, ";")) {
						requisite.Append (tokenizer.CurrentToken.value);
						requisite.Append (' ');
						if (tokenizer.CurrentToken.value == "{") {
							tokenizer.Advance (true);
							while (!tokenizer.Accept (Token2Type.Punctuation, "}")) {
								requisite.Append (tokenizer.CurrentToken.value);
								requisite.Append (' ');
								tokenizer.Advance (true);
							}
							requisite.Append (tokenizer.CurrentToken.value);
							requisite.Append (' ');
						}
						tokenizer.Advance (true);
					}
					requisite.Append (";");
					if (properties.ContainsKey ("CBindingRequisite"))
						cbinding_requisites.AppendLine (requisite.ToString ());

					continue;
				case "EVENTHANDLER":
					while (!tokenizer.Accept (Token2Type.Punctuation, ";"))
						tokenizer.Advance (true);
					continue;
				case "template":
					tokenizer.Advance (true);
					tokenizer.AcceptOrThrow (Token2Type.Punctuation, "<");
					tokenizer.AcceptOrThrow (Token2Type.Identifier, "typename");
					tokenizer.GetIdentifier ();
					tokenizer.AcceptOrThrow (Token2Type.Punctuation, ">");
					continue;
				case "using":
					tokenizer.Advance (true);
					continue;
				case "namespace":
					tokenizer.Advance (true);
					tokenizer.GetIdentifier ();
					tokenizer.Accept (Token2Type.Punctuation, "{");
					continue;
				case "mutable":
					tokenizer.Advance (true);
					continue;
				}
			}

			do {
				if (tokenizer.Accept (Token2Type.Identifier, "virtual")) {
					is_virtual = true;
					continue;
				}

				if (tokenizer.Accept (Token2Type.Identifier, "static")) {
					is_static = true;
					continue;
				}

				if (tokenizer.Accept (Token2Type.Identifier, "const")) {
					is_const = true;
					continue;
开发者ID:kangaroo,项目名称:moon,代码行数:67,代码来源:Generator.cs

示例3: ParseEnum

	static void ParseEnum (Annotations properties, MemberInfo parent, Tokenizer tokenizer)
	{
		FieldInfo field;
		StringBuilder value = new StringBuilder ();
		TypeInfo type = new TypeInfo ();

		type.Annotations = properties;
		type.IsEnum = true;

		tokenizer.AcceptOrThrow (Token2Type.Identifier, "enum");
		if (tokenizer.CurrentToken.type == Token2Type.Identifier) {
			type.Name = tokenizer.GetIdentifier ();
		} else {
			type.Name = "<anonymous>";
		}
		parent.Children.Add (type);

		tokenizer.AcceptOrThrow (Token2Type.Punctuation, "{");

		//Console.WriteLine ("ParseEnum: {0}", name);

		while (tokenizer.CurrentToken.type == Token2Type.Identifier) {
			field = new FieldInfo ();
			field.Name = tokenizer.GetIdentifier ();
			value.Length = 0;
			if (tokenizer.Accept (Token2Type.Punctuation, "=")) {
				while (tokenizer.CurrentToken.value != "," && tokenizer.CurrentToken.value != "}") {
					value.Append (" ");
					value.Append (tokenizer.CurrentToken.value);
					tokenizer.Advance (true);
				}
			}
			field.Value = value.ToString ();
			type.Children.Add (field);
			//Console.WriteLine ("ParseEnum: {0}: {1} {2} {3}", name, field, value.Length != 0 != null ? "=" : "", value);

			if (!tokenizer.Accept (Token2Type.Punctuation, ","))
				break;
		}

		tokenizer.AcceptOrThrow (Token2Type.Punctuation, "}");
		tokenizer.AcceptOrThrow (Token2Type.Punctuation, ";");
	}
开发者ID:kangaroo,项目名称:moon,代码行数:43,代码来源:Generator.cs

示例4: ParseClassOrStruct

	// Returns false if there are no more tokens (reached end of code)
	static bool ParseClassOrStruct (Annotations annotations, MemberInfo parent, Tokenizer tokenizer)
	{
		TypeInfo type = new TypeInfo ();

		type.Annotations = annotations;
		type.Header = tokenizer.CurrentFile;
		type.Parent = parent;

		type.IsPublic = tokenizer.Accept (Token2Type.Identifier, "public");

		if (tokenizer.Accept (Token2Type.Identifier, "class")) {
			type.IsClass = true;
		} else if (tokenizer.Accept (Token2Type.Identifier, "struct")) {
			type.IsStruct = true;
			type.IsValueType = true;
		} else if (tokenizer.Accept (Token2Type.Identifier, "union")) {
			type.IsStruct = true; // Not entirely correct, but a union can be parsed as a struct
			type.IsValueType = true;
		} else {
			throw new Exception (string.Format ("Expected 'class' or 'struct', not '{0}'", tokenizer.CurrentToken.value));
		}

		if (tokenizer.CurrentToken.type == Token2Type.Identifier) {
			type.Name = tokenizer.GetIdentifier ();
		} else {
			type.Name = "<anonymous>";
		}

		if (tokenizer.Accept (Token2Type.Punctuation, ";")) {
			// A forward declaration.
			//Console.WriteLine ("ParseType: Found a forward declaration to {0}", type.Name);
			return true;
		}

		if (tokenizer.Accept (Token2Type.Punctuation, ":")) {
			if (!tokenizer.Accept (Token2Type.Identifier, "public") && type.IsClass)
				throw new Exception (string.Format ("The base class of {0} is not public.", type.Name));

			type.Base = ParseTypeReference (tokenizer);

			// accept multiple inheritance the easy way
			while (tokenizer.CurrentToken.value == ",") {
				tokenizer.Accept (Token2Type.Punctuation, ",");

				while (tokenizer.CurrentToken.value != "," &&
				       tokenizer.CurrentToken.value != "{")
					tokenizer.GetIdentifier ();
			}

			//Console.WriteLine ("ParseType: Found {0}'s base class: {1}", type.Name, type.Base);
		}

		tokenizer.AcceptOrThrow (Token2Type.Punctuation, "{");

		//Console.WriteLine ("ParseType: Found a type: {0} in {1}", type.Name, type.Header);
		parent.Children.Add (type);
		ParseMembers (type, tokenizer);

		tokenizer.AcceptOrThrow (Token2Type.Punctuation, "}");

		if (tokenizer.CurrentToken.type == Token2Type.Identifier)
			tokenizer.Advance (true);

		if (tokenizer.CurrentToken.value != ";")
			throw new Exception (string.Format ("Expected ';', not '{0}'", tokenizer.CurrentToken.value));

		return tokenizer.Advance (false);
	}
开发者ID:kangaroo,项目名称:moon,代码行数:69,代码来源:Generator.cs


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