Overview
Comment: | sync tbd |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
87e5dc43ffd3500a384c6a0f244d52f3 |
User & Date: | spaskalev on 2015-04-06 19:20:42 |
Other Links: | manifest | tags |
Context
2015-09-09
| ||
22:22 | initial imgui api ideas check-in: bc1a46b4d9 user: spaskalev tags: trunk | |
2015-04-06
| ||
19:20 | sync tbd check-in: 87e5dc43ff user: spaskalev tags: trunk | |
2015-03-19
| ||
20:51 | Added parse.Digit and a test check-in: 61937abf4c user: spaskalev tags: trunk | |
Changes
Modified src/0dev.org/commands/tbd/tbd.go from [2547f40cdb] to [015d525e31].
1 2 3 4 5 6 7 8 .. 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 .. 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 ... 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 ... 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
// tbd, a #tag-based dependency tool for low ceremony task tracking package main import ( "bufio" "bytes" "fmt" "io" ................................................................................ extract = regexp.MustCompile("(#)([^\\s]+?)(?:[,\\.\\s]|$)") } func main() { var ( exitCode int handlers []handler = []handler{counting(), tracing()} ) // Parse command line elements and register handlers if len(os.Args) == 1 { handlers = append(handlers, cutoff()) } else { handlers = append(handlers, matching(os.Args[1:])) ................................................................................ exitCode = 1 } os.Exit(exitCode) } // Processes input through the provided handlers func process(input io.Reader, handlers []handler) int { reader := bufio.NewReader(input) for { line, err := reader.ReadString('\n') line = strings.TrimSpace(line) if len(line) > 0 { handle(handlers, &task{tags: parse(line), value: line}) } // Process errors after handling as ReadString can return both data and error f if err != nil { if err == io.EOF { return 0 } ................................................................................ // Stop further processing of the task stop bool } // An alias interface for all task handler functions type handler func(*task) action // Execute handlers against a task func handle(handlers []handler, t *task) { for _, h := range handlers { act := h(t) if act.stop { return } } } // Returns a counting handler closure that sets the tasks' nth field ................................................................................ return action{} } } return action{stop: true} } } // Returns a handler that stores every seen task and an ancillary function to retrieve those func collecting() (handler, func() tasks) { var seen = make(map[*task]bool) return func(t *task) action { depth := tasks{t} for i := 0; i < len(depth); i++ { if !seen[depth[i]] { seen[depth[i]] = true |
| | | | > > > < > | | | > |
1 2 3 4 5 6 7 8 .. 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 .. 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 ... 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 ... 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
// tbd, a #tag-based dependency tool for task tracking package main import ( "bufio" "bytes" "fmt" "io" ................................................................................ extract = regexp.MustCompile("(#)([^\\s]+?)(?:[,\\.\\s]|$)") } func main() { var ( exitCode int handlers = handlerChain{counting(), tracing()} ) // Parse command line elements and register handlers if len(os.Args) == 1 { handlers = append(handlers, cutoff()) } else { handlers = append(handlers, matching(os.Args[1:])) ................................................................................ exitCode = 1 } os.Exit(exitCode) } // Processes input through the provided handlers func process(input io.Reader, handlers handlerChain) int { reader := bufio.NewReader(input) for { line, err := reader.ReadString('\n') line = strings.TrimSpace(line) if len(line) > 0 { handlers.do(&task{tags: parse(line), value: line, depends: make(tasks, 0, 8)}) } // Process errors after handling as ReadString can return both data and error f if err != nil { if err == io.EOF { return 0 } ................................................................................ // Stop further processing of the task stop bool } // An alias interface for all task handler functions type handler func(*task) action // A slice of handlers type handlerChain []handler // Execute handlers against a task func (handlers handlerChain) do(t *task) { for _, current := range handlers { act := current(t) if act.stop { return } } } // Returns a counting handler closure that sets the tasks' nth field ................................................................................ return action{} } } return action{stop: true} } } // Returns a handler that stores every seen task and its dependencies // along with an ancillary function to retrieve those in a sorted order func collecting() (handler, func() tasks) { var seen = make(map[*task]bool) return func(t *task) action { depth := tasks{t} for i := 0; i < len(depth); i++ { if !seen[depth[i]] { seen[depth[i]] = true |