本文整理汇总了C#中LNode.Calls方法的典型用法代码示例。如果您正苦于以下问题:C# LNode.Calls方法的具体用法?C# LNode.Calls怎么用?C# LNode.Calls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LNode
的用法示例。
在下文中一共展示了LNode.Calls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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) || expr.Calls(S.DotDotDot, 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);
}
示例2: GetName
internal static LNode GetName(LNode type)
{
{
LNode name;
if (type.Calls(CodeSymbols.Class, 3) && (name = type.Args[0]) != null && type.Args[1].Calls(CodeSymbols.AltList) && type.Args[2].Calls(CodeSymbols.Braces) || type.Calls(CodeSymbols.Struct, 3) && (name = type.Args[0]) != null && type.Args[1].Calls(CodeSymbols.AltList) && type.Args[2].Calls(CodeSymbols.Braces) || type.Calls(CodeSymbols.Enum, 3) && (name = type.Args[0]) != null && type.Args[1].Calls(CodeSymbols.AltList) && type.Args[2].Calls(CodeSymbols.Braces))
return name;
else
return null;
}
}
示例3: 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());
}
示例4: GetNamespaces
static IEnumerable<LNode> GetNamespaces(LNode multiName)
{
{
LNode outerNamespace;
VList<LNode> args;
if (multiName.Calls(CodeSymbols.Dot) || multiName.Calls(CodeSymbols.Of)) {
} else if (multiName.IsCall && (outerNamespace = multiName.Target) != null) {
args = multiName.Args;
if (args.Count == 1 && args[0].Calls(S.Braces))
args = args[0].Args;
return args.SelectMany(arg => GetNamespaces(arg) ?? ListExt.Single(arg)).Select(subNS => MergeIdentifiers(outerNamespace, subNS));
}
}
return null;
}
示例5: WithSpliced
public static RVList<LNode> WithSpliced(this RVList<LNode> list, LNode node, Symbol listName)
{
if (node.Calls(listName))
return list.AddRange(node.Args);
else
return list.Add(node);
}
示例6: In
public static LNode In(LNode node, IMacroContext context)
{
{
LNode range, x;
if (node.Calls(CodeSymbols.In, 2) && (x = node.Args[0]) != null && (range = node.Args[1]) != null) {
LNode parens;
range = range.WithoutAttrNamed(S.TriviaInParens, out parens);
if (parens == null) {
{
LNode hi, lo;
if (range.Calls(CodeSymbols.DotDot, 2) && (lo = range.Args[0]) != null && (hi = range.Args[1]) != null)
if (lo.IsIdNamed(__))
return LNode.Call(CodeSymbols.LT, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (hi.IsIdNamed(__))
return LNode.Call(CodeSymbols.GE, LNode.List(x, lo)).SetStyle(NodeStyle.Operator);
else
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(x, LNode.Id((Symbol) "IsInRangeExcludeHi"))).SetStyle(NodeStyle.Operator), LNode.List(lo, hi));
else if (range.Calls(CodeSymbols.DotDot, 1) && (hi = range.Args[0]) != null)
return LNode.Call(CodeSymbols.LT, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (range.Calls(CodeSymbols.DotDotDot, 2) && (lo = range.Args[0]) != null && (hi = range.Args[1]) != null)
if (lo.IsIdNamed(__))
return LNode.Call(CodeSymbols.LE, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (hi.IsIdNamed(__))
return LNode.Call(CodeSymbols.GE, LNode.List(x, lo)).SetStyle(NodeStyle.Operator);
else
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(x, LNode.Id((Symbol) "IsInRange"))).SetStyle(NodeStyle.Operator), LNode.List(lo, hi));
else if (range.Calls(CodeSymbols.DotDotDot, 1) && (hi = range.Args[0]) != null)
return LNode.Call(CodeSymbols.LE, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
}
}
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(range, LNode.Id((Symbol) "Contains"))).SetStyle(NodeStyle.Operator), LNode.List(x));
}
}
return null;
}
示例7: 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));`");
}
}
示例8: SpliceInsert
public static void SpliceInsert(this RWList<LNode> list, int index, LNode node, Symbol listName)
{
if (node.Calls(listName))
list.InsertRange(index, node.Args);
else
list.Insert(index, node);
}
示例9: SpliceAdd
public static void SpliceAdd(this RWList<LNode> list, LNode node, Symbol listName)
{
if (node.Calls(listName))
list.AddRange(node.Args);
else
list.Add(node);
}
示例10: NullDot
public static LNode NullDot(LNode node, IMacroContext context)
{
if (!node.Calls(S.NullDot, 2))
return null;
var a = node.Args;
LNode leftSide = a[0], rightSide = a[1];
// So our input will be something like a.b?.c().d<x>, which is parsed
// (a.b) ?. (c().d<x>)
// in EC# we would transform this to
// a.b::tmp != null ? tmp.c().d<x> : null
// but there's no EC# compiler yet, so instead use code that plain C#
// can support:
// a.b != null ? (a.b).c().d<x> : null
LNode condition, thenExpr;
if (StandardMacros.LooksLikeSimpleValue(leftSide))
{
condition = F.Call(S.Neq, leftSide, [email protected]);
thenExpr = ConvertToNormalDot(leftSide, rightSide);
}
else
{
LNode tempVar = F.Id(StandardMacros.NextTempName(context, leftSide));
condition = F.Call(S.Neq, F.Var(F.Missing, tempVar, leftSide), [email protected]);
thenExpr = ConvertToNormalDot(tempVar, rightSide);
}
return F.InParens(F.Call(S.QuestionMark, condition, thenExpr, F.Null));
}
示例11: In
[LexicalMacro("x in lo..hi; x in lo...hi; x in ..hi; x in lo..._; x in range", "Converts an 'in' expression to a normal C# expression using the following rules " + "(keeping in mind that the EC# parser treats `..<` as an alias for `..`):\n" + "1. `x in _..hi` and `x in ..hi` become `x.IsInRangeExcl(hi)`\n" + "2. `x in _...hi` and `x in ...hi` become `x.IsInRangeIncl(hi)`\n" + "3. `x in lo.._` and `x in lo..._` become simply `x >= lo`\n" + "4. `x in lo..hi` becomes `x.IsInRangeExcludeHi(lo, hi)`\n" + "5. `x in lo...hi` becomes `x.IsInRange(lo, hi)`\n" + "6. `x in range` becomes `range.Contains(x)`\n" + "The first applicable rule is used.", "#in")] public static LNode In(LNode node, IMacroContext context)
{
{
LNode range, x;
if (node.Calls(CodeSymbols.In, 2) && (x = node.Args[0]) != null && (range = node.Args[1]) != null) {
LNode parens;
range = range.WithoutAttrNamed(S.TriviaInParens, out parens);
if (parens == null) {
{
LNode hi, lo;
if (range.Calls(CodeSymbols.DotDot, 2) && (lo = range.Args[0]) != null && (hi = range.Args[1]) != null)
if (lo.IsIdNamed(__))
return LNode.Call(CodeSymbols.LT, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (hi.IsIdNamed(__))
return LNode.Call(CodeSymbols.GE, LNode.List(x, lo)).SetStyle(NodeStyle.Operator);
else
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(x, LNode.Id((Symbol) "IsInRangeExcludeHi"))), LNode.List(lo, hi));
else if (range.Calls(CodeSymbols.DotDot, 1) && (hi = range.Args[0]) != null)
return LNode.Call(CodeSymbols.LT, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (range.Calls(CodeSymbols.DotDotDot, 2) && (lo = range.Args[0]) != null && (hi = range.Args[1]) != null)
if (lo.IsIdNamed(__))
return LNode.Call(CodeSymbols.LE, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
else if (hi.IsIdNamed(__))
return LNode.Call(CodeSymbols.GE, LNode.List(x, lo)).SetStyle(NodeStyle.Operator);
else
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(x, LNode.Id((Symbol) "IsInRange"))), LNode.List(lo, hi));
else if (range.Calls(CodeSymbols.DotDotDot, 1) && (hi = range.Args[0]) != null)
return LNode.Call(CodeSymbols.LE, LNode.List(x, hi)).SetStyle(NodeStyle.Operator);
}
}
return LNode.Call(LNode.Call(CodeSymbols.Dot, LNode.List(range, LNode.Id((Symbol) "Contains"))), LNode.List(x));
}
}
return null;
}
示例12: Rule
public Rule(LNode basis, Symbol name, Pred pred, bool isStartingRule = true)
{
Basis = basis; Pred = pred; Name = name;
IsStartingRule = isStartingRule;
EndOfRule = new EndOfRule(this);
if (basis != null && basis.Calls(S.Fn) && basis.ArgCount >= 3)
ReturnType = basis.Args[0];
}
示例13: SetListInitializer
/// <summary>Sets ListType and/or ListInitializer based on an expression.
/// A statement like <c>Type x = expr</c> sets <c>ListType = Type</c> and <c>ListInitializer = expr</c>;
/// A statement like <c>Type x</c> just sets <c>ListType = Type</c>; and any other
/// expression <c>expr</c> sets <c>ListInitializer = expr</c>.</summary>
public void SetListInitializer(LNode varDecl)
{
if (varDecl.Calls(S.Var, 2)) {
ListType = varDecl.Args[0];
if (varDecl.Args[1].Calls(S.Assign, 2))
ListInitializer = varDecl.Args[1].Args[1];
} else {
ListInitializer = varDecl;
}
}
示例14: GetForwardingTarget
static LNode GetForwardingTarget(LNode fwd, LNode methodName)
{
if (fwd.Calls(S.Forward, 1)) {
LNode target = fwd.Args[0];
if (target.Calls(S.Dot, 2) && target.Args[1].IsIdNamed(_hash))
return target.WithArgChanged(1, target.Args[1].WithName(
Ecs.EcsNodePrinter.KeyNameComponentOf(methodName)));
return target;
} else
return null;
}
示例15: DoDeconstruct
private static void DoDeconstruct(LNode arg, IMacroContext context, bool printErrorOnFailure)
{
LNode patternSpec = arg.Args[0, LNode.Missing], input = arg.Args[1, LNode.Missing];
if (!arg.Calls(S.Assign, 2))
{
if (arg.Calls(S.Lambda, 2))
G.Swap(ref patternSpec, ref input);
else {
context.Sink.Error(arg, "expected an assignment (`patterns = input`)");
return;
}
}
// Build list of patterns out of the binary operator series p1 | p2 | p3
var patterns = new FVList<LNode>();
while (patternSpec.Calls(S.OrBits, 2) && !patternSpec.IsParenthesizedExpr()) {
patterns.Add(patternSpec[1]);
patternSpec = patternSpec[0];
}
patterns.Add(patternSpec);
// Remove outer braces, then run macros
patterns = patterns.SmartSelect(p => p.Calls(S.Braces, 1) ? p[0] : p);
input = input.Calls(S.Braces, 1) ? input[0] : input;
input = context.PreProcess(input);
// Perform matching & capturing
foreach (var pattern in patterns) {
IDictionary<Symbol, LNode> captures;
if (LNodeExt.MatchesPattern(input, pattern, out captures)) {
if (captures.Count == 0)
context.Write(printErrorOnFailure ? Severity.Warning : Severity.Error, pattern,
"This pattern has no effect, since it does not use `$` to capture any variables.");
SetSyntaxVariables(captures, context);
return;
}
}
if (printErrorOnFailure)
context.Sink.Error(arg, "Deconstruction failed.");
}