Skip to content

Commit

Permalink
Add -lines flag
Browse files Browse the repository at this point in the history
  • Loading branch information
clipperhouse committed Apr 9, 2020
1 parent b72b412 commit 943ca7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cmd/jargon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func main() {

lemmas := flag.Bool("lemmas", false, "only return tokens that have been changed by a filter (lemmatized)")
count := flag.Bool("count", false, "count the tokens")
lines := flag.Bool("lines", false, "add a line break between all tokens")

flag.Parse()

Expand All @@ -51,6 +52,7 @@ func main() {
HTML: *html,
Lemmas: *lemmas,
Count: *count,
Lines: *lines,
}

//
Expand Down Expand Up @@ -112,6 +114,7 @@ type config struct {

HTML bool
Count bool
Lines bool
Lemmas bool
Filters []jargon.Filter

Expand Down Expand Up @@ -273,6 +276,7 @@ func execute(c *config) error {
}

for _, f := range c.Filters {
fmt.Println(f)
tokens = f(tokens)
}

Expand All @@ -289,9 +293,25 @@ func execute(c *config) error {
return nil
}

if _, err := tokens.WriteTo(c.Writer); err != nil {
// Write all
for tokens.Scan() {
token := tokens.Token()
_, err := c.Writer.WriteString(token.String())
if err != nil {
return err
}

if c.Lines {
_, err := c.Writer.WriteRune('\n')
if err != nil {
return err
}
}
}
if err := tokens.Err(); err != nil {
return err
}

if err := c.Writer.Flush(); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tokenstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (stream *TokenStream) WriteTo(w io.Writer) (int64, error) {
}

if err := stream.Err(); err != nil {
return written, stream.Err()
return written, err
}

return written, nil
Expand Down

0 comments on commit 943ca7e

Please sign in to comment.