private bool WriteAttrs(LNode node, Precedence context) { var a = node.Attrs; if (a.Count == 0) { return(false); } bool extraParen = false; if (!ContinueExpr.CanAppearIn(context)) { extraParen = true; _out.Write('(', true); } _out.Write('[', true); for (int i = 0;;) { Print(a[i], Mode.InParens, StartExpr); if (++i >= a.Count) { break; } _out.Write(',', true); _out.Space(); } _out.Write(']', true); return(extraParen); }
// Checks if an operator with precedence 'prec' can appear in this context. bool CanAppearIn(Precedence prec, Precedence context, out bool extraParens, bool prefix = false) { extraParens = false; if (prec.CanAppearIn(context, prefix) && (prefix || MixImmiscibleOperators || prec.CanMixWith(context))) { return(true); } if (_n.IsParenthesizedExpr()) { return(true); } if (AllowChangeParenthesis || !EP.Primary.CanAppearIn(context)) { Trace.WriteLineIf(!AllowChangeParenthesis, "Forced to write node in parens"); return(extraParens = true); } return(false); }
private bool WriteAttrs(LNode node, Precedence context) { var A = node.Attrs; if (A.Count == 0) { return(false); } bool wroteBrack = false, extraParen = false; for (int i = 0; i < A.Count; i++) { var a = A[i]; if (a.ArgCount <= 1 && !ShouldPrintAttribute(a.Name)) { continue; } if (!wroteBrack) { wroteBrack = true; if (!ContinueExpr.CanAppearIn(context)) { extraParen = true; _out.Write('(', true); } _out.Write('[', true); } else { _out.Write(',', true); _out.Space(); } Print(A[i], Mode.InParens, StartExpr); } if (wroteBrack) { _out.Write("] ", true); } return(extraParen); }
// Checks if an operator with precedence 'prec' can appear in this context. bool CanAppearHere(Precedence prec, out bool extraParens, bool prefix = false) { extraParens = false; if (prec.CanAppearIn(_context, prefix) && (prefix || _o.MixImmiscibleOperators || prec.CanMixWith(_context))) return true; if (_n.IsParenthesizedExpr()) return true; if (_o.AllowChangeParentheses || !EP.Primary.CanAppearIn(_context)) { Trace.WriteLineIf(!_o.AllowChangeParentheses, "Forced to write node in parens"); return extraParens = true; } return false; }