public static Symbol NextTempName(IMacroContext ctx, LNode value) { string prefix = value.Name.Name; prefix = LNode.IsSpecialName(prefix) ? "tmp_" : prefix + "_"; return(NextTempName(ctx, prefix)); }
/// <summary>Returns true if the specified child of the specified node /// can be an implicit child statement, i.e. a child statement that is /// not necessarily a braced block, e.g. the second child of a while /// loop.</summary> /// <remarks> /// This method helps the printer decide when a newline should be added /// before an unbraced child statement when there are no attributes /// dictating whether to add a newline or not. /// <para/> /// This method only cares about executable parent nodes. It returns /// false for class/space and function/property bodies, which are always /// braced blocks and therefore get a newline before every child statement /// automatically. /// </remarks> public static bool MayBeImplicitChildStatement(LNode node, int childIndex) { CheckParam.IsNotNull("node", node); if (childIndex < 0) // target or attributes { return(false); } var n = node.Name; if (!LNode.IsSpecialName(n.Name)) { return(false); } if (n == S.Braces) { return(true); } if (n == S.Try) { return(childIndex == 0); } switch (node.ArgCount) { case 1: if (n == S.Finally) { return(true); } break; case 2: if (childIndex == 0 ? n == S.DoWhile : n == S.If || n == S.While || n == S.UsingStmt || n == S.Lock || n == S.Switch || n == S.Fixed) { return(true); } break; case 3: if (childIndex != 0 && n == S.If) { return(true); } if (childIndex == 2 && n == S.ForEach) { return(true); } break; case 4: if (childIndex == 3 && (n == S.For || n == S.Catch)) { return(true); } break; } return(false); }
protected override LesColorCode ColorCodeForId(UString name) { if (LNode.IsSpecialName(name.ToString()) || Continuators.ContainsKey((Symbol)name.ToString())) { return(LesColorCode.SpecialId); } else { return(LesColorCode.Id); } }
protected override LesColorCode ColorCodeForId(Symbol name) { if (LNode.IsSpecialName(name.Name) || Continuators.ContainsKey(name)) { return(LesColorCode.SpecialId); } else { return(LesColorCode.Id); } }
protected override bool IsSpecialIdentifier(object value) { return(CommonKeywords.Contains(value) || (value is Symbol) && LNode.IsSpecialName((Symbol)value)); }
public static bool HasSpecialName(this ILNode node) { return(LNode.IsSpecialName(node.Name)); }
/// <summary>Expresses an EC# token as a string.</summary> /// <remarks>Note that some Tokens do not contain enough information to /// reconstruct a useful token string, e.g. comment tokens do not store the /// comment but merely contain the location of the comment in the source code. /// For performance reasons, a <see cref="Token"/> does not have a reference /// to its source file, so this method cannot return the original string. /// <para/> /// The results are undefined if the token was not produced by <see cref="EcsLexer"/>. /// </remarks> public static string ToString(Token t, ICharSource sourceCode) { if (sourceCode != null && t.EndIndex <= sourceCode.Count) { return(sourceCode.Slice(t.StartIndex, t.Length).ToString()); } StringBuilder sb = new StringBuilder(); if (t.Kind == TokenKind.Operator || t.Kind == TokenKind.Assignment || t.Kind == TokenKind.Dot) { if (t.Type() == TT.BQString) { return(EcsNodePrinter.PrintString((t.Value ?? "").ToString(), '`', false)); } string value = (t.Value ?? "(null)").ToString(); return(value); } switch (t.Type()) { case TT.EOF: return("/*EOF*/"); case TT.Spaces: return(" "); case TT.Newline: return("\n"); case TT.SLComment: return("//\n"); case TT.MLComment: return("/**/"); case TT.Shebang: return("#!" + (t.Value ?? "").ToString() + "\n"); case TT.Id: case TT.ContextualKeyword: case TT.LinqKeyword: var mode = (t.Style & NodeStyle.Operator) != 0 ? EcsNodePrinter.IdPrintMode.Operator : (t.Style & NodeStyle.VerbatimId) != 0 ? EcsNodePrinter.IdPrintMode.Verbatim : EcsNodePrinter.IdPrintMode.Normal; return(EcsNodePrinter.PrintId(t.Value as Symbol ?? GSymbol.Empty, mode)); case TT.Base: return("base"); case TT.This: return("this"); case TT.Literal: return(EcsNodePrinter.PrintLiteral(t.Value, t.Style)); case TT.Comma: return(","); case TT.Semicolon: return(";"); case TT.LParen: return("("); case TT.RParen: return(")"); case TT.LBrack: return("["); case TT.RBrack: return("]"); case TT.LBrace: return("{"); case TT.RBrace: return("}"); case TT.AttrKeyword: string value = (t.Value ?? "(null)").ToString(); return(value); case TT.TypeKeyword: Symbol valueSym = (t.Value as Symbol) ?? GSymbol.Empty; string result; if (EcsFacts.TypeKeywords.TryGetValue(valueSym, out result)) { return(result); } else { Debug.Fail("Unexpected value for " + t.Type()); return((t.Value ?? "(null)").ToString()); } case TT.CheckedOrUnchecked: Debug.Assert(LNode.IsSpecialName((Symbol)t.Value)); return(((Symbol)t.Value).Name.Substring(1)); case TT.Break: return("break"); case TT.Case: return("case"); case TT.Class: return("class"); case TT.Continue: return("continue"); case TT.Default: return("default"); case TT.Delegate: return("delegate"); case TT.Do: return("do"); case TT.Enum: return("enum"); case TT.Event: return("event"); case TT.Fixed: return("fixed"); case TT.For: return("for"); case TT.Foreach: return("foreach"); case TT.Goto: return("goto"); case TT.If: return("if"); case TT.Interface: return("interface"); case TT.Lock: return("lock"); case TT.Namespace: return("namespace"); case TT.Return: return("return"); case TT.Struct: return("struct"); case TT.Switch: return("switch"); case TT.Throw: return("throw"); case TT.Try: return("try"); case TT.Using: return("using"); case TT.While: return("while"); case TT.Operator: return("operator"); case TT.Sizeof: return("sizeof"); case TT.Typeof: return("typeof"); case TT.Else: return("else"); case TT.Catch: return("catch"); case TT.Finally: return("finally"); case TT.In: return("in"); case TT.As: return("as"); case TT.Is: return("is"); case TT.New: return("new"); case TT.Out: return("out"); case TT.Stackalloc: return("stackalloc"); case TT.PPif: return("#if"); case TT.PPelse: return("#else"); case TT.PPelif: return("#elif"); case TT.PPendif: return("#endif"); case TT.PPdefine: return("#define"); case TT.PPundef: return("#undef"); case TT.PPwarning: return("#warning" + t.Value); case TT.PPerror: return("#error" + t.Value); case TT.PPnote: return("#note" + t.Value); case TT.PPline: return("#line"); case TT.PPregion: return("#region" + t.Value); case TT.PPendregion: return("#endregion"); case TT.PPpragma: return("#pragma"); case TT.PPignored: return((t.Value ?? "").ToString()); default: return(string.Format("@`unknown token 0x{0:X4}`", t.TypeInt)); } }