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


C# LNode.IsIdNamed方法代码示例

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


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

示例1: CodeToTerminalPred

		public override Pred CodeToTerminalPred(LNode expr, ref string errorMsg)
		{
			bool isInt = false;
			PGIntSet set;

			if (expr.IsIdNamed(_underscore)) {
				set = PGIntSet.AllExceptEOF;
			} else if (expr.IsIdNamed(_EOF)) {
				set = PGIntSet.EOF;
			} else if (expr.Calls(S.DotDot, 2)) {
				int? from = ConstValue(expr.Args[0], ref isInt);
				int? to   = ConstValue(expr.Args[1], ref isInt);
				if (from == null || to == null) {
					errorMsg = "Expected int32 or character literal on each side of «..»";
					return null;
				}
				set = PGIntSet.WithRanges(from.Value, to.Value);
			} else if (expr.Value is string) {
				return Pred.Seq((string)expr.Value);
			} else {
				int? num = ConstValue(expr, ref isInt);
				if (num == null) {
					errorMsg = "Unrecognized expression. Expected int32 or character literal instead of: " + expr.ToString(); // warning
					return null;
				}
				set = PGIntSet.With(num.Value);
			}
			set.IsCharSet = !isInt;
			return new TerminalPred(expr, set, true);
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:30,代码来源:IntStreamCodeGenHelper.cs

示例2: MergeIdentifiers

		static LNode MergeIdentifiers(LNode left, LNode right)
		{
			if (left == null)
				return right;
			if (right.IsIdNamed(S.Missing))
				return left;
			{
				LNode right1, right2;
				if (right.Calls(CodeSymbols.Dot, 1) && (right2 = right.Args[0]) != null)
					return LNode.Call(CodeSymbols.Dot, LNode.List(left, right2));
				else if (right.Calls(CodeSymbols.Dot, 2) && (right1 = right.Args[0]) != null && (right2 = right.Args[1]) != null)
					return LNode.Call(CodeSymbols.Dot, LNode.List(MergeIdentifiers(left, right1), right2));
				else
					throw new LogException(Severity.Note, right, "Multi-using statement seems malformed. Correct example: `using System(.Text, .Linq));`");
			}
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:16,代码来源:UsingMultiMacro.out.cs

示例3: DefaultOf

		protected virtual LNode DefaultOf(LNode type, bool wantList)
		{
			if (wantList) {
				return ReplaceT(ListInitializer, type);
			} else {
				if (type.IsIdNamed(S.Int32))
					return F.Literal(0);
				return F.Call(S.Default, type);
			}
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:10,代码来源:CodeGenHelperBase.cs

示例4: GenerateSwitch

		public virtual LNode GenerateSwitch(IPGTerminalSet[] branchSets, MSet<int> casesToInclude, LNode[] branchCode, LNode defaultBranch, LNode laVar)
		{
			Debug.Assert(branchSets.Length == branchCode.Length);

			RWList<LNode> stmts = new RWList<LNode>();
			for (int i = 0; i < branchSets.Length; i++)
			{
				if (casesToInclude.Contains(i))
				{
					foreach (LNode value in GetCases(branchSets[i]))
					{
						stmts.Add(F.Call(S.Case, value));
						if (stmts.Count > 65535) // sanity check
							throw new InvalidOperationException("switch is too large to generate");
					}
					AddSwitchHandler(branchCode[i], stmts);
				}
			}

			if (!defaultBranch.IsIdNamed(S.Missing))
			{
				stmts.Add(F.Call(S.Label, F.Id(S.Default)));
				AddSwitchHandler(defaultBranch, stmts);
			}

			return F.Call(S.Switch, (LNode)laVar, F.Braces(stmts.ToRVList()));
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:27,代码来源:CodeGenHelperBase.cs

示例5: GenerateSwitch

		public virtual LNode GenerateSwitch(IPGTerminalSet[] branchSets, MSet<int> casesToInclude, LNode[] branchCode, LNode defaultBranch, LNode laVar)
		{
			Debug.Assert(branchSets.Length == branchCode.Length);

			WList<LNode> stmts = new WList<LNode>();
			for (int i = 0; i < branchSets.Length; i++)
			{
				if (casesToInclude.Contains(i))
				{
					int index = -1;
					foreach (LNode value in GetCases(branchSets[i]))
					{
						var label = F.Call(S.Case, value);
						if (++index > 0 && (index % 4) != 0) // write 4 cases per line
							label = label.PlusAttr(F.Id(S.TriviaAppendStatement));
						stmts.Add(label);
						if (stmts.Count > 65535) // sanity check
							throw new InvalidOperationException("switch is too large to generate");
					}
					AddSwitchHandler(branchCode[i], stmts);
				}
			}

			if (!defaultBranch.IsIdNamed(S.Missing))
			{
				stmts.Add(F.Call(S.Label, F.Id(S.Default)));
				AddSwitchHandler(defaultBranch, stmts);
			}

			return F.Call(S.Switch, (LNode)laVar, F.Braces(stmts.ToVList()));
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:31,代码来源:CodeGenHelperBase.cs

示例6: BranchToPred

		Pred BranchToPred(LNode expr, out BranchMode mode, Context ctx)
		{
			if (expr.Calls(_Default, 1) || expr.Calls(_Default2, 1)) {
				expr = expr.Args[0];
				mode = BranchMode.Default;
			} else if (expr.Calls(_Error, 1) || expr.IsIdNamed(_DefaultError)) {
				mode = (expr.AttrNamed(S.Continue) != null || expr.AttrNamed(GSymbol.Get("continue")) != null) 
				       ? BranchMode.ErrorContinue : BranchMode.ErrorExit;
				if (expr.Calls(_Error, 1))
					expr = expr.Args[0];
				else
					return DefaultErrorBranch.Value;
			} else
				mode = BranchMode.None;

			return NodeToPred(expr, ctx);
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:17,代码来源:StageTwoParser.cs

示例7: asAltList

		static LNode asAltList(LNode node) {
			return node.Calls(S.AltList) ? node
			     : node.IsIdNamed(GSymbol.Empty) ? LNode.Call(S.AltList, node)
			     : LNode.Call(S.AltList, LNode.List(node), node);
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:5,代码来源:Prelude.Les.cs

示例8: IsPropertyDefinition

		/// <summary>Returns true iff the given node has a valid syntax tree for 
		/// a property definition, and gets the component parts of the definition.</summary>
		/// <remarks>The body may be anything. If it calls CodeSymbols.Braces, it's a normal body.</remarks>
		public static bool IsPropertyDefinition(LNode n, out LNode retType, out LNode name, out LNode args, out LNode body, out LNode initialValue, Pedantics p = Pedantics.Lax)
		{
			var argCount = n.ArgCount;
			if (!CallsMinWPAIH(n, S.Property, 4, p) || n.ArgCount > 5) {
				retType = name = args = body = initialValue = null;
				return false;
			}

			retType = n.Args[0];
			name = n.Args[1];
			args = n.Args[2];
			body = n.Args[3];
			initialValue = n.Args[4, null];
			return IsComplexIdentifier(retType, ICI.Default, p) &&
			       IsComplexIdentifier(name, ICI.Default | ICI.NameDefinition, p) &&
			       (args.IsIdNamed(S.Missing) || args.Calls(S.AltList));
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:20,代码来源:EcsValidators.cs

示例9: MethodDefinitionKind

		/// <summary>If the given node has a valid syntax tree for a method definition,
		/// a constructor, or (when orDelegate is true) a delegate definition, gets
		/// the definition kind (#fn, #cons, or #delegate).</summary>
		/// <param name="retType">Return type of the method (if it's a constructor, this will be the empty identifier).</param>
		/// <param name="name">Name of the method.</param>
		/// <param name="args">args.Args is the argument list of the method.</param>
		/// <param name="body">The method body, or null if there is no method body. 
		/// The method body calls <see cref="CodeSymbols.Braces"/> if the method is a 
		/// non-lambda-style method.</param>
		/// <returns>The definition kind (#fn, #cons, or #delegate), or null if it's no kind of method.</returns>
		/// <remarks>
		/// Method declarations (no body) also count.
		/// <para/>
		/// A destructor counts as a #fn with a method name that calls the ~ operator.
		/// </remarks>
		public static Symbol MethodDefinitionKind(LNode n, out LNode retType, out LNode name, out LNode args, out LNode body, bool allowDelegate, Pedantics p = Pedantics.Lax)
		{
			retType = name = args = body = null;
			var kind = n.Name;
			if ((kind != S.Fn && kind != S.Delegate && kind != S.Constructor) || !HasSimpleHeadWPA(n, p))
				return null;
			if (!n.ArgCount.IsInRange(3, kind == S.Delegate ? 3 : 4))
				return null;

			retType = n.Args[0];
			name = n.Args[1];
			args = n.Args[2];
			body = n.Args[3, null];
			if (kind == S.Constructor && !retType.IsIdNamed(S.Missing))
				return null;
			// Note: the parser doesn't require that the argument list have a 
			// particular format, so the printer doesn't either.
			if (!CallsWPAIH(args, S.AltList, p))
				return null;
			if (kind == S.Constructor &&
				((body != null && !CallsWPAIH(body, S.Braces, p) && !CallsWPAIH(body, S.Forward, 1, p))
				|| !retType.IsIdNamed(S.Missing)))
				return null;
			if (IsComplexIdentifier(name, ICI.Default | ICI.NameDefinition, p)) {
				return IsComplexIdentifier(retType, ICI.Default | ICI.AllowAttrs, p) ? kind : null;
			} else {
				// Check for a destructor
				return retType.IsIdNamed(S.Missing)
					&& CallsWPAIH(name, S._Destruct, 1, p) 
					&& IsSimpleIdentifier(name.Args[0], p) ? kind : null;
			}
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:47,代码来源:EcsValidators.cs

示例10: EliminateSequenceExpressionsInLambdaExpr

			LNode EliminateSequenceExpressionsInLambdaExpr(LNode expr, LNode retType)
			{
				var stmt = EliminateSequenceExpressions(expr, false);
				if (stmt.Calls(__numrunSequence)) {
					stmt = stmt.WithTarget(S.Braces);
					if (!retType.IsIdNamed(S.Void)) {
						if (retType.IsIdNamed(S.Missing) && stmt.Args.Last.IsCall)
							Context.Sink.Warning(expr, "This lambda must be converted to a braced block, but in LeMP it's not possible to tell whether the return keyword is needed. The output assumes `return` is required.");
						stmt = stmt.WithArgChanged(stmt.Args.Count - 1, LNode.Call(CodeSymbols.Return, LNode.List(stmt.Args.Last)));
					}
				}
				return stmt;
			}
开发者ID:qwertie,项目名称:ecsharp,代码行数:13,代码来源:UseSequenceExpressions.out.cs


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