public static string Format(Argument argument) { var f = new WebIDLFormatter(); f.Visit(argument); return f._sb.ToString(); }
private Argument Resolve(Argument argument) { return(argument.DecomposeWithResult( required => { var t = Resolve(required.Type, required.ExtendedAttributes); return Argument.Required(required.Name, t.Item1, t.Item2.Select(Resolve)); }, optional => { var t = Resolve(optional.Type, optional.ExtendedAttributes); return Argument.Optional(optional.Name, t.Item1, optional.DefaultValue, t.Item2.Select(Resolve)); }, ellipsis => { var t = Resolve(ellipsis.Type, ellipsis.ExtendedAttributes); return Argument.Ellipsis(ellipsis.Name, t.Item1, t.Item2.Select(Resolve)); } )); }
private void Visit(Argument argument) { argument.Decompose( required => { Visit(required.ExtendedAttributes, ExtendedAttributeMode.Argument); Visit(required.Type); _sb.Append(" " + required.Name); }, optional => { Visit(optional.ExtendedAttributes, ExtendedAttributeMode.Argument); _sb.Append("optional "); Visit(optional.Type); _sb.Append(" " + optional.Name); if (optional.DefaultValue != null) { _sb.Append(" = "); Visit(optional.DefaultValue); } }, ellipsis => { Visit(ellipsis.ExtendedAttributes, ExtendedAttributeMode.Argument); Visit(ellipsis.Type); _sb.Append("... " + ellipsis.Name); } ); }