0.2.1 • Published 9 years ago
commonform-new-markup v0.2.1
Parse Common Form markup, returning an object containing a form and an array of path-to-blank mappings.
var parse = require('commonform-markup-parse')
parse(stringOfMarkup); // => { form: Object, directions: Array }
The parser is made of several components:
- a hand-coded context-tracking tokenizer (or lexer) that emits tokens for indentation and outdentation, in addition to content tokens
- an LALR(1) parser generated by Jison from a Bison-like BNF grammar
- commonform-fix-strings to convert the parser's AST to a valid common form by fixing various string-related validation issues, like extra space
- a tiny algorithm that removes the hints text from fill-in-the-blanks within the form, and emits path-to-hint mappings instead
The parser passes the commonform-markup-tests test suite.
If you'd like to write a parser in a different language, the test suite and this package are best places to start. Your language probably already has a Bison clone or a BNF-compatible parser combinators library.