]> git.wincent.com - docvim.git/commitdiff
Add basic list item parsing
authorGreg Hurrell <greg@hurrell.net>
Sat, 26 Mar 2016 00:23:20 +0000 (17:23 -0700)
committerGreg Hurrell <greg@hurrell.net>
Sat, 26 Mar 2016 00:23:20 +0000 (17:23 -0700)
Single-line items only for now, and no parsing of nested nodes (like
links and such).

lib/Docvim/Parse.hs
tests/fixtures/parser/list-items.golden [new file with mode: 0644]
tests/fixtures/parser/list-items.vim [new file with mode: 0644]

index 33dc2b28fd20fe285ac2a35d467d732e70600502..3d33a603abf43a752a0fd4a97da9ddda5cb5a9b4 100644 (file)
@@ -77,6 +77,7 @@ data Node
           | Paragraph [Node]
           | Plaintext [String]
           | LinkTargets [String]
+          | ListItem String
 
           -- annotations
           | PluginAnnotation Name Description
@@ -172,7 +173,11 @@ quote = string "\"" <?> "quote"
 -- blockquote    = string ">" >> return Blockquote
 commentStart  = quote <* (notFollowedBy quote >> optional ws)
 docBlockStart = (string "\"\"" <* optional ws) <?> "\"\""
--- listItem = string "-" >> return ListItem
+listItem = char '-'
+         >> optional ws
+         >> ListItem <$> listItemBody
+  where
+    listItemBody = restOfLine
 
 -- | Newline (and slurps up following horizontal whitespace as well).
 newline = char '\n' >> optional ws
@@ -214,6 +219,7 @@ docBlock = lookAhead docBlockStart
                            , try subheading -- must come before heading
                            , heading
                            , linkTargets
+                           , listItem
                            , paragraph -- must come last
                            ]
                  <* next
diff --git a/tests/fixtures/parser/list-items.golden b/tests/fixtures/parser/list-items.golden
new file mode 100644 (file)
index 0000000..282a3be
--- /dev/null
@@ -0,0 +1,9 @@
+Unit
+  [ DocBlock
+      [ ListItem "Item 1."
+      , ListItem "Item with trailing space."
+      , ListItem "Another item."
+      , ListItem "Note that we parse nested lists."
+      , ListItem "But don't do anything special with them."
+      ]
+  ]
diff --git a/tests/fixtures/parser/list-items.vim b/tests/fixtures/parser/list-items.vim
new file mode 100644 (file)
index 0000000..de92428
--- /dev/null
@@ -0,0 +1,7 @@
+""
+" - Item 1.
+" - Item with trailing space.    
+" -     Another item.
+"    - Note that we parse nested lists.
+"    - But don't do anything special with them.
+"