OK, not sure why this was even a struggle for me, but this refactored nicely as follows (and could probably be improved beyond that:
attributes
= a:( attributesAtLeastID
/ attributesAtLeastClass
/ attributesAtFullAttr )
{
var id = a[0];
var classes = a[1];
var attrs = a[2];
var ret = [];
if(id) { ret.push(['id', id]); }
for(var i = 0; i < classes.length; ++i ) {
ret.push(['class', classes[i]]);
}
for(var i = 0; i < attrs.length; ++i ) {
ret.push(attrs[i]);
}
}
attributesAtLeastID = id:idShortcut classes:classShortcut* attrs:fullAttribute* { return [id, classes, attrs]; }
attributesAtLeastClass = classes:classShortcut+ attrs:fullAttribute* { return [null, classes, attrs]; }
attributesAtFullAttr = attrs:fullAttribute+ { return [null, [], attrs]; }