blob: b4273d7285aa3d546c91f52cca8cd8fd32b69e03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package parse
import (
"strings"
)
func (t *Tree) ParseString(play string) {
toParse := strings.Split(play, "\n")
for i, row := range toParse {
action := "action"
if row == strings.ToUpper(row) {
action = "allcaps"
}
if row == "" {
action = "empty"
} else {
if i > 0 {
switch t.F[i-1].Format {
case "allcaps":
t.F[i-1].Format = "speaker"
if row[0] == '(' && row[len(row)-1] == ')' {
action = "paren"
} else {
action = "dialog"
}
case "paren", "dialog":
action = "dialog"
}
}
}
t.F = append(t.F, struct{ Format, Text string }{action, row})
}
}
|