NextSegment returns a copy of the tokens from the current token until the end of the line or block that starts at the end of the line.
()
| 356 | // token until the end of the line or block that starts at |
| 357 | // the end of the line. |
| 358 | func (d *Dispenser) NextSegment() Segment { |
| 359 | tkns := Segment{d.Token()} |
| 360 | for d.NextArg() { |
| 361 | tkns = append(tkns, d.Token()) |
| 362 | } |
| 363 | var openedBlock bool |
| 364 | for nesting := d.Nesting(); d.NextBlock(nesting); { |
| 365 | if !openedBlock { |
| 366 | // because NextBlock() consumes the initial open |
| 367 | // curly brace, we rewind here to append it, since |
| 368 | // our case is special in that we want the new |
| 369 | // dispenser to have all the tokens including |
| 370 | // surrounding curly braces |
| 371 | d.Prev() |
| 372 | tkns = append(tkns, d.Token()) |
| 373 | d.Next() |
| 374 | openedBlock = true |
| 375 | } |
| 376 | tkns = append(tkns, d.Token()) |
| 377 | } |
| 378 | if openedBlock { |
| 379 | // include closing brace |
| 380 | tkns = append(tkns, d.Token()) |
| 381 | |
| 382 | // do not consume the closing curly brace; the |
| 383 | // next iteration of the enclosing loop will |
| 384 | // call Next() and consume it |
| 385 | } |
| 386 | return tkns |
| 387 | } |
| 388 | |
| 389 | // Token returns the current token. |
| 390 | func (d *Dispenser) Token() Token { |
no test coverage detected