diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-05-04 10:58:06 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-05-04 10:58:06 +0100 |
| commit | a78d8242d2be4377accfb95447d549828f08dbd0 (patch) | |
| tree | d6909620c20ffb0fc6e613afde31c033515a9a49 /lib/style-reader.js | |
| parent | 4da89717caa2ae0ab28f7e50aa56031e39dcdf9b (diff) | |
Add parsing for unordered lists
Diffstat (limited to 'lib/style-reader.js')
| -rw-r--r-- | lib/style-reader.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/style-reader.js b/lib/style-reader.js index 210e2ed..c18cf00 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -35,35 +35,43 @@ function readDocumentMatcher(string) { function documentMatcherRule() { var sequence = lop.rules.sequence; - var paragraphRule = lop.rules.then( - lop.rules.token("identifier", "p"), - function() { - return documentMatchers.paragraph; - } - ); + var identifierToConstant = function(identifier, constant) { + return lop.rules.then( + lop.rules.token("identifier", identifier), + function() { + return constant; + } + ); + }; - var runRule = lop.rules.then( - lop.rules.token("identifier", "r"), - function() { - return documentMatchers.run; - } - ); + var paragraphRule = identifierToConstant("p", documentMatchers.paragraph); + var runRule = identifierToConstant("r", documentMatchers.run); var elementTypeRule = lop.rules.firstOf("p or r", paragraphRule, runRule ); + + var listTypeRule = lop.rules.firstOf("list type", + identifierToConstant("ordered-list", {isOrdered: true}), + identifierToConstant("unordered-list", {isOrdered: false}) + ); + var listRule = sequence( lop.rules.tokenOfType("colon"), - lop.rules.token("identifier", "ordered-list"), + sequence.capture(listTypeRule), sequence.cut(), lop.rules.tokenOfType("open-paren"), sequence.capture(integerRule), lop.rules.tokenOfType("close-paren") - ).map(function(levelNumber) { + ).map(function(listType, levelNumber) { return function(matcher) { - return matcher.orderedList(levelNumber - 1); + if (listType.isOrdered) { + return matcher.orderedList(levelNumber - 1); + } else { + return matcher.unorderedList(levelNumber - 1); + } }; }); |
