()
| 214 | } |
| 215 | |
| 216 | func (p *parser) parseBlock() *Block { |
| 217 | block := &Block{} |
| 218 | block.Include, block.Exclude, block.NoCommonFilter = p.collectPatterns() |
| 219 | nxt := p.next() |
| 220 | if nxt.typ != itemLeftParen { |
| 221 | p.errorf("expected block open parentheses, got %q", nxt.val) |
| 222 | } |
| 223 | Loop: |
| 224 | for { |
| 225 | nxt = p.next() |
| 226 | switch nxt.typ { |
| 227 | case itemInDir: |
| 228 | options := p.collectValues(itemBareString) |
| 229 | if len(options) > 0 { |
| 230 | p.errorf("indir takes no options") |
| 231 | } |
| 232 | p.mustNext(itemColon) |
| 233 | dir := prepValue(p.mustNext(itemBareString, itemQuotedString)) |
| 234 | if block.InDir != "" { |
| 235 | p.errorf("indir can only be used once per block") |
| 236 | } |
| 237 | block.InDir = dir |
| 238 | case itemDaemon: |
| 239 | options := p.collectValues(itemBareString) |
| 240 | p.mustNext(itemColon) |
| 241 | err := block.addDaemon( |
| 242 | prepValue(p.mustNext(itemBareString, itemQuotedString)), |
| 243 | options, |
| 244 | ) |
| 245 | if err != nil { |
| 246 | p.errorf("%s", err) |
| 247 | } |
| 248 | case itemPrep: |
| 249 | options := p.collectValues(itemBareString) |
| 250 | p.mustNext(itemColon) |
| 251 | err := block.addPrep( |
| 252 | prepValue(p.mustNext(itemBareString, itemQuotedString)), |
| 253 | options, |
| 254 | ) |
| 255 | if err != nil { |
| 256 | p.errorf("%s", err) |
| 257 | } |
| 258 | case itemRightParen: |
| 259 | break Loop |
| 260 | default: |
| 261 | p.errorf("unexpected input: %s", nxt.val) |
| 262 | } |
| 263 | } |
| 264 | return block |
| 265 | } |
| 266 | |
| 267 | // Parse parses a string, and returns a completed Config |
| 268 | func Parse(name string, text string) (*Config, error) { |
no test coverage detected