Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Created May 22, 2013 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying-sheep/5628390 to your computer and use it in GitHub Desktop.
Save flying-sheep/5628390 to your computer and use it in GitHub Desktop.
Iterator-based code
function parseTable(title, lines) {
let options = new TableOptions(lines.next());
...
yield '<table>';
for (let line of lines) {
if (line.startsWith(macros.tableEnd))
break;
...
let buffer = line;
while(true) {
let open = buffer.match(openRE).length;
let close = buffer.match(closeRE).length;
if (close >= open) break;
buffer += lines.next();
}
...
}
...
yield '</table>';
}
function parse(lines) {
...
for (let line of lines) {
...
if (macro === macros.tableStart)
for (let l of parseTable(line, lines))
yield l;
...
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment