Exemplo n.º 1
0
 private void PrintPrefixTrivia(ILNode _n)
 {
     foreach (var attr in _n.Attrs())
     {
         MaybePrintTrivia(attr, needSpace: false);
     }
 }
Exemplo n.º 2
0
 public static IListSource <ILNode> GetTrailingTrivia(this ILNode node)
 {
     if (node is LNode)
     {
         LNodeList list = GetTrailingTrivia((LNode)node);
         if (list.IsEmpty)
         {
             return(EmptyList <ILNode> .Value);                  // avoid boxing in the common case
         }
         return(list);
     }
     else
     {
         VList <ILNode> list = VList <ILNode> .Empty;
         foreach (ILNode a in node.Attrs())
         {
             if (a.Calls(S.TriviaTrailing))
             {
                 list.AddRange(a.Args());
             }
         }
         if (list.IsEmpty)
         {
             return(EmptyList <ILNode> .Value);                  // avoid boxing in the common case
         }
         return(list);
     }
 }
Exemplo n.º 3
0
 bool HasPAttrs(ILNode node)
 {
     foreach (var attr in node.Attrs())
     {
         if (!IsConsumedTrivia(attr))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
        private int WriteAttrs(ILNode node, ref Precedence context)
        {
            bool wroteBrack = false, needParen = (context != StartStmt);
            int  parenCount = 0;

            foreach (var attr in node.Attrs())
            {
                if (attr.IsIdNamed(S.TriviaInParens))
                {
                    MaybeCloseBrack(ref wroteBrack);
                    parenCount++;
                    _out.Write('(', true);
                    // need extra paren when writing @[..] because (@[..] ...) doesn't count as #trivia_inParens
                    needParen = true;
                    continue;
                }
                if (MaybePrintTrivia(attr, needSpace: false, testOnly: wroteBrack))
                {
                    if (wroteBrack)
                    {
                        MaybeCloseBrack(ref wroteBrack);
                        MaybePrintTrivia(attr, needSpace: false);
                    }
                    continue;
                }
                if (!wroteBrack)
                {
                    wroteBrack = true;
                    if (needParen)
                    {
                        needParen = false;
                        parenCount++;
                        _out.Write('(', true);
                    }
                    _out.Write("@[", true);
                }
                else
                {
                    _out.Write(',', true);
                    _out.Space();
                }
                Print(attr, StartStmt);
            }
            MaybeCloseBrack(ref wroteBrack);
            if (parenCount != 0)
            {
                context = StartStmt;
            }
            return(parenCount);
        }
Exemplo n.º 5
0
 public static ILNode AttrNamed(this ILNode node, Symbol name)
 {
     return(node.Attrs().NodeNamed(name));
 }
Exemplo n.º 6
0
 public static bool IsParenthesizedExpr(this ILNode node)
 {
     return(node.Attrs().NodeNamed(CodeSymbols.TriviaInParens) != null);
 }