From 2bca5ef4f69b8f33e76660dfd784fa2b3e2251c4 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Tue, 5 Nov 2019 22:16:46 +0700 Subject: lib/parser: a general parser library --- lib/parser/parser_example_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/parser/parser_example_test.go (limited to 'lib/parser/parser_example_test.go') 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 . 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' +} -- cgit v1.3