Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Created July 6, 2015 07:01
Show Gist options
  • Select an option

  • Save StoneCypher/1f0c886dff0ea56905e3 to your computer and use it in GitHub Desktop.

Select an option

Save StoneCypher/1f0c886dff0ea56905e3 to your computer and use it in GitHub Desktop.
// http://pegjs.org/online
start = basic*
basic = (w:sentence . ws q:quote ws e:expl ws? nl) { return { word: w, quote: q, expl: e }; }
quote = qt (s:sentence) qt { return s; }
expl = phrase
phrase = sentence*
sentence = (s:(w:word sep? ws?)*) . { return s.map(function(X) { return X[0] + X[1]; }).join(' ') + '.'; }
words = (w:word+ ws) { return w.join(''); }
word = (w:char+) { return w.join(''); }
char = [a-z]i
sep = (s:[,:]*) { return s.join(''); }
qt = "\""
ws = (w:[ \t]*) { return w.join(''); }
nl = [\r\n]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment