(p *peeker)
| 42 | } |
| 43 | |
| 44 | func parseValue(p *peeker) (node, hcl.Diagnostics) { |
| 45 | tok := p.Peek() |
| 46 | |
| 47 | wrapInvalid := func(n node, diags hcl.Diagnostics) (node, hcl.Diagnostics) { |
| 48 | if n != nil { |
| 49 | return n, diags |
| 50 | } |
| 51 | return invalidVal{tok.Range}, diags |
| 52 | } |
| 53 | |
| 54 | switch tok.Type { |
| 55 | case tokenBraceO: |
| 56 | return wrapInvalid(parseObject(p)) |
| 57 | case tokenBrackO: |
| 58 | return wrapInvalid(parseArray(p)) |
| 59 | case tokenNumber: |
| 60 | return wrapInvalid(parseNumber(p)) |
| 61 | case tokenString: |
| 62 | return wrapInvalid(parseString(p)) |
| 63 | case tokenKeyword: |
| 64 | return wrapInvalid(parseKeyword(p)) |
| 65 | case tokenBraceC: |
| 66 | return wrapInvalid(nil, hcl.Diagnostics{ |
| 67 | { |
| 68 | Severity: hcl.DiagError, |
| 69 | Summary: "Missing JSON value", |
| 70 | Detail: "A JSON value must start with a brace, a bracket, a number, a string, or a keyword.", |
| 71 | Subject: &tok.Range, |
| 72 | }, |
| 73 | }) |
| 74 | case tokenBrackC: |
| 75 | return wrapInvalid(nil, hcl.Diagnostics{ |
| 76 | { |
| 77 | Severity: hcl.DiagError, |
| 78 | Summary: "Missing array element value", |
| 79 | Detail: "A JSON value must start with a brace, a bracket, a number, a string, or a keyword.", |
| 80 | Subject: &tok.Range, |
| 81 | }, |
| 82 | }) |
| 83 | case tokenEOF: |
| 84 | return wrapInvalid(nil, hcl.Diagnostics{ |
| 85 | { |
| 86 | Severity: hcl.DiagError, |
| 87 | Summary: "Missing value", |
| 88 | Detail: "The JSON data ends prematurely.", |
| 89 | Subject: &tok.Range, |
| 90 | }, |
| 91 | }) |
| 92 | default: |
| 93 | return wrapInvalid(nil, hcl.Diagnostics{ |
| 94 | { |
| 95 | Severity: hcl.DiagError, |
| 96 | Summary: "Invalid start of value", |
| 97 | Detail: "A JSON value must start with a brace, a bracket, a number, a string, or a keyword.", |
| 98 | Subject: &tok.Range, |
| 99 | }, |
| 100 | }) |
| 101 | } |
no test coverage detected