本文整理汇总了C#中LNode.HasPAttrs方法的典型用法代码示例。如果您正苦于以下问题:C# LNode.HasPAttrs方法的具体用法?C# LNode.HasPAttrs怎么用?C# LNode.HasPAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LNode
的用法示例。
在下文中一共展示了LNode.HasPAttrs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: unroll
public static LNode unroll(LNode var, LNode cases, LNode body, IMessageSink sink)
{
if (!cases.Calls(S.Tuple) && !cases.Calls(S.Braces))
return Reject(sink, cases, "unroll: the right-hand side of 'in' should be a tuple");
// Maps identifiers => replacements. The integer counts how many times replacement occurred.
var replacements = InternalList<Triplet<Symbol, LNode, int>>.Empty;
if (var.IsId && !var.HasPAttrs()) {
replacements.Add(Pair.Create(var.Name, (LNode)LNode.Missing, 0));
} else {
var vars = var.Args;
if ((var.Calls(S.Tuple) || var.Calls(S.Braces)) && vars.All(a => a.IsId && !a.HasPAttrs())) {
replacements = new Triplet<Symbol, LNode, int>[vars.Count].AsInternalList();
for (int i = 0; i < vars.Count; i++) {
replacements.InternalArray[i].A = vars[i].Name;
// Check for duplicate names
for (int j = 0; j < i; j++)
if (replacements[i].A == replacements[j].A && replacements[i].A.Name != "_")
sink.Write(Severity.Error, vars[i], "unroll: duplicate name in the left-hand tuple"); // non-fatal
}
} else
return Reject(sink, cases, "unroll: the left-hand side of 'in' should be a simple identifier or a tuple of simple identifiers.");
}
UnrollCtx ctx = new UnrollCtx { Replacements = replacements };
WList<LNode> output = new WList<LNode>();
int iteration = 0;
foreach (LNode replacement in cases.Args)
{
iteration++;
bool tuple = replacement.Calls(S.Tuple) || replacement.Calls(S.Braces);
int count = tuple ? replacement.ArgCount : 1;
if (replacements.Count != count)
{
sink.Write(Severity.Error, replacement, "unroll, iteration {0}: Expected {1} replacement items, got {2}", iteration, replacements.Count, count);
if (count < replacements.Count)
continue; // too few
}
for (int i = 0; i < replacements.Count; i++)
replacements.InternalArray[i].B = tuple ? replacement.Args[i] : replacement;
if (body.Calls(S.Braces)) {
foreach (LNode stmt in body.Args)
output.Add(ctx.Replace(stmt).Value);
} else
output.Add(ctx.Replace(body).Value);
}
foreach (var r in replacements)
if (r.C == 0 && !r.A.Name.StartsWith("_"))
sink.Write(Severity.Warning, var, "Replacement variable '{0}' was never used", r.A);
return body.With(S.Splice, output.ToVList());
}
示例2: unroll
public static LNode unroll(LNode node, IMacroContext context)
{
LNode clause;
// unroll (X, Y) \in ((X, Y), (Y, X)) {...}
// unroll ((X, Y) in ((X, Y), (Y, X))) {...}
if (node.ArgCount == 2 && ((clause = node.Args[0]).Calls(@in, 2) || clause.Calls(S.In, 2)))
{
LNode identifiers = clause.Args[0], cases = clause.Args[1];
if (!cases.Calls(S.Tuple) && !cases.Calls(S.Braces) && !cases.Calls(S.Splice)) {
cases = context.PreProcess(cases);
if (!cases.Calls(S.Tuple) && !cases.Calls(S.Braces) && !cases.Calls(S.Splice))
return Reject(context, cases, "The right-hand side of 'in' should be a tuple or braced block.");
}
var result = unroll(identifiers, cases.Args, node.Args[1], context.Sink);
if (result != null && node.HasPAttrs())
context.Sink.Warning(result.Attrs[0], "'unroll' does not support attributes.");
return result;
}
return null;
}
示例3: AttributesMatch
static bool AttributesMatch(LNode candidate, LNode pattern, ref MMap<Symbol, LNode> captures, out VList<LNode> unmatchedAttrs)
{
if (pattern.HasPAttrs()) {
unmatchedAttrs = LNode.List();
return ListMatches(candidate.Attrs, pattern.Attrs, ref captures, ref unmatchedAttrs);
} else {
unmatchedAttrs = candidate.Attrs;
}
return true;
}
示例4: AutoStripBraces
static LNode AutoStripBraces(LNode node)
{
if (node.Calls(S.Braces, 1) && !node.HasPAttrs())
return node.Args[0];
return node;
}
示例5: AttributesMatch
static bool AttributesMatch(LNode candidate, LNode pattern, ref MMap<Symbol, LNode> captures, out RVList<LNode> unmatchedAttrs)
{
if (pattern.HasPAttrs())
throw new NotImplementedException("TODO: attributes in patterns are not yet supported");
unmatchedAttrs = candidate.Attrs;
return true;
}
示例6: HasPAttrs
// These are validators for printing purposes: they check that each node
// that shouldn't have attributes, doesn't; if attributes are present in
// strange places then we print with prefix notation instead to avoid
// losing them when round-tripping.
internal static bool HasPAttrs(LNode node, Pedantics p) // for use in expression context
{
return (p & Pedantics.IgnoreWeirdAttributes) == 0 && node.HasPAttrs();
}