diff options
| author | Shulhan <m.shulhan@gmail.com> | 2019-11-05 22:16:46 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-03-01 22:54:24 +0700 |
| commit | 2bca5ef4f69b8f33e76660dfd784fa2b3e2251c4 (patch) | |
| tree | 89366ccf19686fc545c3871469308ecab7287ac9 /lib/parser/parser_example_test.go | |
| parent | 216584e664fc8898b13f931a582646803d8fa6fb (diff) | |
| download | pakakeh.go-2bca5ef4f69b8f33e76660dfd784fa2b3e2251c4.tar.xz | |
lib/parser: a general parser library
Diffstat (limited to 'lib/parser/parser_example_test.go')
| -rw-r--r-- | lib/parser/parser_example_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/parser/parser_example_test.go b/lib/parser/parser_example_test.go new file mode 100644 index 00000000..41e75455 --- /dev/null +++ b/lib/parser/parser_example_test.go @@ -0,0 +1,29 @@ +// Copyright 2019, Shulhan <m.shulhan@gmail.com>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package parser + +import ( + "fmt" + "strings" +) + +func ExampleNew() { + content := "[test]\nkey = value" + p := New(content, "=[]") + + for { + token, del := p.Token() + token = strings.TrimSpace(token) + fmt.Printf("%q %q\n", token, del) + if del == 0 { + break + } + } + // Output: + // "" '[' + // "test" ']' + // "key" '=' + // "value" '\x00' +} |
