()
| 985 | } |
| 986 | |
| 987 | func ExampleParser() { |
| 988 | doc := ` |
| 989 | hello = "world" |
| 990 | value = 42 |
| 991 | ` |
| 992 | p := Parser{} |
| 993 | p.Reset([]byte(doc)) |
| 994 | for p.NextExpression() { |
| 995 | e := p.Expression() |
| 996 | fmt.Printf("Expression: %s\n", e.Kind) |
| 997 | value := e.Value() |
| 998 | it := e.Key() |
| 999 | k := it.Node() // shortcut: we know there is no dotted key in the example |
| 1000 | fmt.Printf("%s -> (%s) %s\n", k.Data, value.Kind, value.Data) |
| 1001 | } |
| 1002 | |
| 1003 | // Output: |
| 1004 | // Expression: KeyValue |
| 1005 | // hello -> (String) world |
| 1006 | // Expression: KeyValue |
| 1007 | // value -> (Integer) 42 |
| 1008 | } |
| 1009 | |
| 1010 | func TestParserErrorPosition(t *testing.T) { |
| 1011 | examples := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…