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


C# LNode.ReplaceRecursive方法代码示例

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


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

示例1: GetSubstitutionVar

			internal static Symbol GetSubstitutionVar(LNode expr, out LNode condition, out bool isParams, out bool refExistingVar)
			{
				condition = null;
				isParams = false;
				refExistingVar = false;
				if (expr.Calls(S.Substitute, 1)) {
					LNode id = expr.Args[0];
					if (id.AttrNamed(S.Params) != null)
						isParams = true;
					else if (id.Calls(S.DotDotDot, 1) || id.Calls(S.DotDot, 1)) {
						isParams = true;
						id = id.Args[0];
					}
					if (id.AttrNamed(S.Ref) != null)
						refExistingVar = true;
					if (id.Calls(S.IndexBracks, 2)) {
						condition = id.Args[1];
						id = id.Args[0];
					} else
						while (id.Calls(S.And, 2)) {
							condition = condition == null ? id.Args[1] : LNode.Call(CodeSymbols.And, LNode.List(id.Args[1], condition)).SetStyle(NodeStyle.Operator);
							id = id.Args[0];
						}
					if (condition != null)
						condition = condition.ReplaceRecursive(n => n.IsIdNamed(S._HashMark) ? id : null);
					if (!id.IsId)
						return null;
					return id.Name;
				}
				return null;
			}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:31,代码来源:MatchCode.out.cs

示例2: ReplaceCaptures

		static LNode ReplaceCaptures(LNode node, MMap<Symbol, LNode> captures)
		{
			if (captures.Count != 0)
			{
				// TODO: EXPAND SPLICES! Generally it works anyway though because 
				// the macro processor has built-in support for #splice.
				return node.ReplaceRecursive(n => {
					LNode sub, cap;
					if (n.Calls(S.Substitute, 1) && (sub = n.Args.Last).IsId && captures.TryGetValue(sub.Name, out cap))
						return cap;
					return null;
				});
			}
			return node;
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:15,代码来源:ReplaceMacro.cs

示例3: GetSubstitutionVar

			internal static Symbol GetSubstitutionVar(LNode expr, out LNode condition, out bool isParams, out bool refExistingVar)
			{
				condition = null;
				isParams = false;
				refExistingVar = false;
				if (expr.Calls(S.Substitute, 1)) {
					LNode id = expr.Args[0];
					if (id.AttrNamed(S.Params) != null)
						isParams = true;
					else if (id.Calls(S.DotDot, 1)) {
						isParams = true;
						id = id.Args[0];
					}
					if (id.AttrNamed(S.Ref) != null)
						refExistingVar = true;
					if (id.Calls(S.IndexBracks, 2)) {
						condition = id.Args[1];
						id = id.Args[0];
					} else if (id.ArgCount == 1) {
						condition = id.Args[0];
						id = id.Target;
					}
					if (condition != null)
						condition = condition.ReplaceRecursive(n => n.IsIdNamed(S._HashMark) ? id : null);
					if (!id.IsId)
						return null;
					return id.Name;
				}
				return null;
			}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:30,代码来源:MatchCode.out.cs

示例4: ScanForVariables

		private static Dictionary<Symbol, LNode> ScanForVariables(LNode code)
		{
			var nameTable = new Dictionary<Symbol, LNode>();
			code.ReplaceRecursive(n =>
				{
					if (n.IsId)
						nameTable[n.Name] = n;
					else {
						LNode id = LNodeExt.GetCaptureIdentifier(n);
						if (id != null) {
							if (!nameTable.ContainsKey(n.Name))
								nameTable[id.Name] = n;
							return n;
						}
					}
					return null;
				});
			return nameTable;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:19,代码来源:ReplaceMacro.cs

示例5: ReplaceCaptures

		/// <summary>Finds capture variables like <c>$x</c> and replaces them with values
		/// from <c>captures</c> (e.g. <c>captures[(Symbol)"x"]</c> for <c>$x</c>)</summary>
		public static LNode ReplaceCaptures(LNode outputSpec, MMap<Symbol, LNode> captures)
		{
			if (captures.Count != 0)
			{
				// TODO: EXPAND SPLICES! Generally it works anyway though because 
				// the macro processor has built-in support for #splice.
				return outputSpec.ReplaceRecursive(n => {
					LNode id, cap;
					if ((id = LNodeExt.GetCaptureIdentifier(n)) != null) {
						if (captures.TryGetValue(id.Name, out cap))
							return cap;
					}
					return null;
				});
			}
			return outputSpec;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:19,代码来源:ReplaceMacro.cs

示例6: VisitCode

			void VisitCode(Pred pred, LNode code)
			{
				if (code == null) return;
				code.ReplaceRecursive(node => {
					if (node.Calls(S.Substitute, 1)) {
						var arg = node.Args[0];
						PredsUsingSubstitution.Add(pred);
						if (arg.IsId && _rules.ContainsKey(arg.Name))
							RulesReferenced.Add(_rules[arg.Name]);
						else
							OtherReferences[arg] = 0;
					}
					return null; // search only, no replace
				});
			}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:15,代码来源:AutoValueSaverVisitor.cs

示例7: ReplaceSubstitutionsIn

		LNode ReplaceSubstitutionsIn(LNode code)
		{
			if (code == null) return null;
			return code.ReplaceRecursive(node =>
			{
				if (node.Calls(S.Substitute, 1))
				{ // found $subst_expr
					var label = node.Args[0];
					if (label.IsId)
					{
						if (_data.ProperLabels.ContainsKey(label.Name))
							return label;
						else if (_rules.ContainsKey(label.Name))
							return F.Id(PickVarNameForRuleName(label.Name));
					}
					if (_data.OtherReferences.TryGetValue(label, -1) > 0)
					{
						return F.Id(PickVarNameForLNode(label));
					}
					// Do not change the code in other cases (e.g. the code 
					// block might contain $LI/$LA, handled in a later stage)
				}
				return null;
			});
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:25,代码来源:AutoValueSaverVisitor.cs


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