diff options
author | Joop Kiefte <ikojba@gmail.com> | 2018-12-31 21:40:58 +0100 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2018-12-31 21:40:58 +0100 |
commit | 17e35aa8dbc5ddb5e3542a57f14dd16627d37d64 (patch) | |
tree | 54c4905d49cc5abfa9f63e2d402b035ac147a459 /lex/parse.go | |
parent | 32b146fc5411f8db35824c82e9cafc4cdb6f1d41 (diff) |
First working version. Fountain support is still very bad.
Diffstat (limited to 'lex/parse.go')
-rw-r--r-- | lex/parse.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lex/parse.go b/lex/parse.go new file mode 100644 index 0000000..ebd4dda --- /dev/null +++ b/lex/parse.go @@ -0,0 +1,29 @@ +package lex + +import ( + "io" + "bufio" + "strings" +) + +func Parse(file io.Reader) (out Screenplay) { + f := bufio.NewReader(file) + var err error + var s string + for err == nil { + var line Line + s, err = f.ReadString('\n') + split := strings.SplitN(s, ":", 2) + switch len(split){ + case 0,1: + line.Type = strings.Trim(s,": \n\r") + case 2: + line.Type = split[0] + line.Contents = strings.TrimSpace(split[1]) + } + if strings.TrimSpace(split[0]) != "" { + out = append(out, line) + } + } + return out +} |