[Fencommits] fenserve: friendlier path syntax: integers separated by dots (e.g. 2.3)

Benja Fallenstein benja.fallenstein at gmail.com
Fri Apr 27 21:24:23 EEST 2007


Fri Apr 27 21:24:16 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * friendlier path syntax: integers separated by dots (e.g. 2.3)
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs	2007-04-27 21:24:23.000000000 +0300
+++ new-fenserve/notetaker/Main.hs	2007-04-27 21:24:23.000000000 +0300
@@ -40,9 +40,13 @@
 renderNotes notes = "<ol>" ++ concatMap renderNote notes ++ "</ol>" where
     renderNote (Note title children) = "<li>" ++ title ++ renderNotes children
     
-readPath s n f = f (map (subtract 1) path) (dropWhile isSpace line) where
-    ((path, line):_) = reads (drop n s)
-    
+readPath :: String -> Int -> (Path -> String -> a) -> a
+readPath s n f = f (segments a) (dropWhile isSpace b) where
+    (a,b) = span (\c -> isNumber c || c == '.') $ dropWhile isSpace $ drop n s
+    segments ""      = []
+    segments ('.':s) = segments s
+    segments s       = (read x - 1) : segments y where (x,y) = span (/= '.') s
+
 readBody :: String -> Body
 readBody s | ":add "  `isPrefixOf` s = readPath s 5 $ \p l  -> Add p l
            | ":edit " `isPrefixOf` s = readPath s 6 $ \p l  -> Edit p l




More information about the Fencommits mailing list