Created
December 25, 2020 22:06
-
-
Save evan-brass/8a699aee089ea64ee0d11e82587b6b57 to your computer and use it in GitHub Desktop.
Step 1: Harness for a regex based recursive descent HTML parser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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