Skip to content

Instantly share code, notes, and snippets.

@evan-brass
Created December 25, 2020 22:06
Show Gist options
  • Select an option

  • Save evan-brass/8a699aee089ea64ee0d11e82587b6b57 to your computer and use it in GitHub Desktop.

Select an option

Save evan-brass/8a699aee089ea64ee0d11e82587b6b57 to your computer and use it in GitHub Desktop.
Step 1: Harness for a regex based recursive descent HTML parser.
export default function parse_html(input) {
const root = { children: [] };
function pull(regex, handler = () => {}) {
const match = regex.exec(input);
if (match !== null) {
const [full_match, ...captures] = match;
input = input.substr(full_match.length);
handler(...captures);
return true;
} else {
return false;
}
}
function parse_content(cursor) {
}
parse_content(root);
return root.children;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment