本文整理汇总了C#中LNode.WithoutAttrs方法的典型用法代码示例。如果您正苦于以下问题:C# LNode.WithoutAttrs方法的具体用法?C# LNode.WithoutAttrs怎么用?C# LNode.WithoutAttrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LNode
的用法示例。
在下文中一共展示了LNode.WithoutAttrs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPatternComponents
void GetPatternComponents(LNode pattern, out LNode varBinding, out bool refExistingVar, out LNode cmpExpr, out LNode isType, out LNode inRange, out VList<LNode> subPatterns, out VList<LNode> conditions)
{
bool haveSubPatterns = false;
subPatterns = VList<LNode>.Empty;
refExistingVar = pattern.AttrNamed(S.Ref) != null;
conditions = VList<LNode>.Empty;
while (pattern.Calls(S.And, 2)) {
conditions.Add(pattern.Args.Last);
pattern = pattern.Args[0];
}
LNode cmpExprOrBinding = null;
varBinding = cmpExpr = isType = inRange = null;
for (int pass = 1; pass <= 3; pass++) {
LNode inRange2 = inRange, isType2 = isType;
{
LNode patternL;
if (pattern.Calls(CodeSymbols.In, 2) && (patternL = pattern.Args[0]) != null && (inRange = pattern.Args[1]) != null || pattern.Calls((Symbol) "in", 2) && (patternL = pattern.Args[0]) != null && (inRange = pattern.Args[1]) != null) {
pattern = patternL;
if (inRange2 != null)
_context.Write(Severity.Error, inRange2, "match-case does not support multiple 'in' operators");
} else if (pattern.Calls(CodeSymbols.Is, 2) && (cmpExprOrBinding = pattern.Args[0]) != null && (isType = pattern.Args[1]) != null || pattern.Calls((Symbol) "is", 2) && (cmpExprOrBinding = pattern.Args[0]) != null && (isType = pattern.Args[1]) != null) {
pattern = cmpExprOrBinding;
if (isType2 != null)
_context.Write(Severity.Error, isType2, "match-case does not support multiple 'is' operators");
} else if (pattern.Calls(CodeSymbols.Is, 1) && (isType = pattern.Args[0]) != null || pattern.Calls((Symbol) "is", 1) && (isType = pattern.Args[0]) != null) {
if (isType2 != null)
_context.Write(Severity.Error, isType2, "match-case does not support multiple 'is' operators");
goto doneAnalysis;
} else if (pattern.Calls(CodeSymbols.DotDotDot, 2) || pattern.Calls(CodeSymbols.DotDot, 2) || pattern.Calls(CodeSymbols.DotDotDot, 1) || pattern.Calls(CodeSymbols.DotDot, 1)) {
inRange = pattern;
goto doneAnalysis;
} else if (pattern.Calls(CodeSymbols.Tuple)) {
subPatterns = pattern.Args;
cmpExprOrBinding = null;
} else {
LNode target = pattern.Target;
if (!haveSubPatterns && pattern.IsCall && (!target.IsId || target.AttrNamed(S.TriviaInParens) != null || (!target.HasSpecialName && LesNodePrinter.IsNormalIdentifier(target.Name)))) {
haveSubPatterns = true;
subPatterns = pattern.Args;
pattern = pattern.Target;
} else
cmpExprOrBinding = pattern;
}
}
}
doneAnalysis:
if (cmpExprOrBinding != null) {
if (cmpExprOrBinding.Calls(S.Substitute, 1))
varBinding = cmpExprOrBinding[0];
else if (refExistingVar)
varBinding = cmpExprOrBinding;
else if ((varBinding ?? cmpExprOrBinding).IsIdNamed(__))
cmpExprOrBinding = varBinding = null;
if (varBinding != null) {
if (varBinding.AttrNamed(S.Ref) != null) {
refExistingVar = true;
varBinding = varBinding.WithoutAttrs();
}
if (!varBinding.IsId) {
_context.Write(Severity.Error, varBinding, "Invalid variable name in match-case: {0}", varBinding);
varBinding = null;
}
}
if (varBinding == null)
cmpExpr = cmpExprOrBinding;
}
if (refExistingVar && varBinding == null) {
refExistingVar = false;
var got = cmpExprOrBinding ?? pattern;
_context.Write(Severity.Warning, got, "'ref' expected a variable name (got `{0}`)", got);
}
}
示例2: GetPatternComponents
void GetPatternComponents(LNode pattern, out LNode varBinding, out bool refExistingVar, out LNode cmpExpr, out LNode isType, out LNode inRange, out VList<LNode> subPatterns, out VList<LNode> conditions)
{
// Here's a typical pattern (case expr):
// is Shape(ShapeType.Circle, ref size, Location: p is Point<int>(x, y)):
// When there is an arg list, we decode its Target and return the args.
//
// The caller is in charge of stripping out "Property:" prefix, if any,
// so the most complex pattern that this method considers is something
// like `(expr is Type in Range)(subPatterns) && conds` where `expr` is
// a varName or $varName to deconstruct, or some expression to test for
// equality. Assuming it's an equality test, the output will be
//
// varBinding = null
// refExistingVar = false
// cmpExpr = quote(expr);
// isType = quote(Type);
// inRange = quote(Range);
// conds will have "conds" pushed to the front.
//
bool haveSubPatterns = false;
subPatterns = VList<LNode>.Empty;
refExistingVar = pattern.AttrNamed(S.Ref) != null;
// First, look for "pattern && condition"
conditions = VList<LNode>.Empty;
while (pattern.Calls(S.And, 2)) {
conditions.Add(pattern.Args.Last);
pattern = pattern.Args[0];
}
LNode cmpExprOrBinding = null;
varBinding = cmpExpr = isType = inRange = null;
// Now decode the expression. Use three passes, each of which decodes
// an "outer" layer such as A is B, A in B, or expr(args). Since you
// can combine these operators, we may need multiple passes (e.g.
// "X is T in R" and "X in R is T" are equivalent), and keep in mind
// that operator trees like "A in B" are nearly identical to prefix-
// calls like "foo(A, B)" except for the call target and the `BaseStyle`.
for (int pass = 1; pass <= 3; pass++) {
LNode inRange2 = inRange, isType2 = isType;
{
LNode patternL;
if (pattern.Calls(CodeSymbols.In, 2) && (patternL = pattern.Args[0]) != null && (inRange = pattern.Args[1]) != null || pattern.Calls((Symbol) "in", 2) && (patternL = pattern.Args[0]) != null && (inRange = pattern.Args[1]) != null) {
pattern = patternL;
if (inRange2 != null)
_context.Sink.Error(inRange2, "match-case does not support multiple 'in' operators");
} else if (pattern.Calls(CodeSymbols.Is, 2) && (cmpExprOrBinding = pattern.Args[0]) != null && (isType = pattern.Args[1]) != null || pattern.Calls((Symbol) "is", 2) && (cmpExprOrBinding = pattern.Args[0]) != null && (isType = pattern.Args[1]) != null) {
pattern = cmpExprOrBinding;
if (isType2 != null)
_context.Sink.Error(isType2, "match-case does not support multiple 'is' operators");
} else if (pattern.Calls(CodeSymbols.Is, 1) && (isType = pattern.Args[0]) != null || pattern.Calls((Symbol) "is", 1) && (isType = pattern.Args[0]) != null) {
if (isType2 != null)
_context.Sink.Error(isType2, "match-case does not support multiple 'is' operators");
goto doneAnalysis;
} else if (pattern.Calls(CodeSymbols.DotDotDot, 2) || pattern.Calls(CodeSymbols.DotDot, 2) || pattern.Calls(CodeSymbols.DotDotDot, 1) || pattern.Calls(CodeSymbols.DotDot, 1)) {
inRange = pattern;
goto doneAnalysis;
} else if (pattern.Calls(CodeSymbols.Tuple)) {
subPatterns = pattern.Args;
cmpExprOrBinding = null;
} else {
// It's very tempting to detect NodeStyle.PrefixNotation to distinguish,
// say, A.B<C> from id(A, B, C), but I'm reluctant to do so. BaseStyle
// is by convention "unsemantic" and not guaranteed to be preserved
// across serializations or supported the same way by different parsers.
// So instead of asking "is this in PrefixNotation?" I ask "does the
// target appear to be a normal identifier?"
LNode target = pattern.Target;
if (!haveSubPatterns && pattern.IsCall && (!target.IsId || target.AttrNamed(S.TriviaInParens) != null || (!target.HasSpecialName && Les2Printer.IsNormalIdentifier(target.Name)))
)
{
haveSubPatterns = true;
subPatterns = pattern.Args;
pattern = pattern.Target;
} else
cmpExprOrBinding = pattern;
}
}
}
doneAnalysis:
if (cmpExprOrBinding != null) {
if (cmpExprOrBinding.Calls(S.Substitute, 1))
varBinding = cmpExprOrBinding[0];
else if (refExistingVar)
varBinding = cmpExprOrBinding;
else if ((varBinding ?? cmpExprOrBinding).IsIdNamed(__))
cmpExprOrBinding = varBinding = null;
// Originally a plain identifier would be a binding, like $identifier
//if (cmpExprOrBinding.IsId && cmpExprOrBinding.AttrNamed(S.TriviaInParens) == null)
// varBinding = cmpExprOrBinding;
if (varBinding != null) {
if (varBinding.AttrNamed(S.Ref) != null) {
refExistingVar = true;
varBinding = varBinding.WithoutAttrs();
}
if (!varBinding.IsId) {
_context.Sink.Error(varBinding, "Invalid variable name in match-case: {0}", varBinding);
//.........这里部分代码省略.........