summaryrefslogtreecommitdiff
path: root/json/public.go
diff options
context:
space:
mode:
authorwata_mac <watassbass@gmail.com>2020-05-24 21:56:16 +0900
committerMartin Atkins <mart@degeneration.co.uk>2020-09-04 14:12:01 -0700
commit636e660fac2a9ee31de5346b96e314a9ef6500b0 (patch)
tree039e423e6d5ac093af82e884213b91832c33a96d /json/public.go
parent90676d47a0ce038f02596e2aa5894bf0c57fad56 (diff)
json: Add ParseExpression function
Diffstat (limited to 'json/public.go')
-rw-r--r--json/public.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/json/public.go b/json/public.go
index d3bc9a0..d1e4faf 100644
--- a/json/public.go
+++ b/json/public.go
@@ -71,6 +71,20 @@ func ParseWithStartPos(src []byte, filename string, start hcl.Pos) (*hcl.File, h
return file, diags
}
+// ParseExpression parses the given buffer as a standalone JSON expression,
+// returning it as an instance of Expression.
+func ParseExpression(src []byte, filename string) (hcl.Expression, hcl.Diagnostics) {
+ return ParseExpressionWithStartPos(src, filename, hcl.Pos{Byte: 0, Line: 1, Column: 1})
+}
+
+// ParseExpressionWithStartPos parses like json.ParseExpression, but unlike
+// json.ParseExpression you can pass a start position of the given JSON
+// expression as a hcl.Pos.
+func ParseExpressionWithStartPos(src []byte, filename string, start hcl.Pos) (hcl.Expression, hcl.Diagnostics) {
+ node, diags := parseExpression(src, filename, start)
+ return &expression{src: node}, diags
+}
+
// ParseFile is a convenience wrapper around Parse that first attempts to load
// data from the given filename, passing the result to Parse if successful.
//