github.com/hashicorp/hcl/v2@v2.20.0/json/ast.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package json
     5  
     6  import (
     7  	"math/big"
     8  
     9  	"github.com/hashicorp/hcl/v2"
    10  )
    11  
    12  type node interface {
    13  	Range() hcl.Range
    14  	StartRange() hcl.Range
    15  }
    16  
    17  type objectVal struct {
    18  	Attrs      []*objectAttr
    19  	SrcRange   hcl.Range // range of the entire object, brace-to-brace
    20  	OpenRange  hcl.Range // range of the opening brace
    21  	CloseRange hcl.Range // range of the closing brace
    22  }
    23  
    24  func (n *objectVal) Range() hcl.Range {
    25  	return n.SrcRange
    26  }
    27  
    28  func (n *objectVal) StartRange() hcl.Range {
    29  	return n.OpenRange
    30  }
    31  
    32  type objectAttr struct {
    33  	Name      string
    34  	Value     node
    35  	NameRange hcl.Range // range of the name string
    36  }
    37  
    38  func (n *objectAttr) Range() hcl.Range {
    39  	return n.NameRange
    40  }
    41  
    42  func (n *objectAttr) StartRange() hcl.Range {
    43  	return n.NameRange
    44  }
    45  
    46  type arrayVal struct {
    47  	Values    []node
    48  	SrcRange  hcl.Range // range of the entire object, bracket-to-bracket
    49  	OpenRange hcl.Range // range of the opening bracket
    50  }
    51  
    52  func (n *arrayVal) Range() hcl.Range {
    53  	return n.SrcRange
    54  }
    55  
    56  func (n *arrayVal) StartRange() hcl.Range {
    57  	return n.OpenRange
    58  }
    59  
    60  type booleanVal struct {
    61  	Value    bool
    62  	SrcRange hcl.Range
    63  }
    64  
    65  func (n *booleanVal) Range() hcl.Range {
    66  	return n.SrcRange
    67  }
    68  
    69  func (n *booleanVal) StartRange() hcl.Range {
    70  	return n.SrcRange
    71  }
    72  
    73  type numberVal struct {
    74  	Value    *big.Float
    75  	SrcRange hcl.Range
    76  }
    77  
    78  func (n *numberVal) Range() hcl.Range {
    79  	return n.SrcRange
    80  }
    81  
    82  func (n *numberVal) StartRange() hcl.Range {
    83  	return n.SrcRange
    84  }
    85  
    86  type stringVal struct {
    87  	Value    string
    88  	SrcRange hcl.Range
    89  }
    90  
    91  func (n *stringVal) Range() hcl.Range {
    92  	return n.SrcRange
    93  }
    94  
    95  func (n *stringVal) StartRange() hcl.Range {
    96  	return n.SrcRange
    97  }
    98  
    99  type nullVal struct {
   100  	SrcRange hcl.Range
   101  }
   102  
   103  func (n *nullVal) Range() hcl.Range {
   104  	return n.SrcRange
   105  }
   106  
   107  func (n *nullVal) StartRange() hcl.Range {
   108  	return n.SrcRange
   109  }
   110  
   111  // invalidVal is used as a placeholder where a value is needed for a valid
   112  // parse tree but the input was invalid enough to prevent one from being
   113  // created.
   114  type invalidVal struct {
   115  	SrcRange hcl.Range
   116  }
   117  
   118  func (n invalidVal) Range() hcl.Range {
   119  	return n.SrcRange
   120  }
   121  
   122  func (n invalidVal) StartRange() hcl.Range {
   123  	return n.SrcRange
   124  }