width = 30 input = "this is a test, i am trying to implement word wrapping for a paragraph editor. hopefully it will work and make people happy." ometa W { word = spaces (~space anything)+:w -> w.join(''), words = word* } input = W.matchAll(input, "words") ometa L { line = anything:w ![w]:l lineRest(width - w.length, l) -> l.join(' '), lineRest :wl :l = anything:w ?(wl >= w.length + 1) !l.push(w) lineRest(wl - w.length - 1, l) | -> l, lines = line* } input = L.matchAll(input, "lines") input.join('\n') this is a test, i am trying to implement word wrapping for a paragraph editor. hopefully it will work and make people happy.