From e72341df8ac7e995c125b20d4f05b4198587e2e6 Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Tue, 25 Aug 2020 02:53:10 +0900 Subject: json: Add json.ParseWithStartPos function This is like json.Parse but allows specifying a non-default start position, in case the caller is parsing a fragment from a larger JSON document. --- json/parser.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'json/parser.go') diff --git a/json/parser.go b/json/parser.go index 7a54c51..4e40068 100644 --- a/json/parser.go +++ b/json/parser.go @@ -8,15 +8,8 @@ import ( "github.com/zclconf/go-cty/cty" ) -func parseFileContent(buf []byte, filename string) (node, hcl.Diagnostics) { - tokens := scan(buf, pos{ - Filename: filename, - Pos: hcl.Pos{ - Byte: 0, - Line: 1, - Column: 1, - }, - }) +func parseFileContent(buf []byte, filename string, start hcl.Pos) (node, hcl.Diagnostics) { + tokens := scan(buf, pos{Filename: filename, Pos: start}) p := newPeeker(tokens) node, diags := parseValue(p) if len(diags) == 0 && p.Peek().Type != tokenEOF { -- cgit v1.2.3