CollectMetadata records the source position information of a given YAML node, and returns the id associated with the source metadata which is returned in the Policy SourceInfo object.
(node *yaml.Node)
| 722 | // CollectMetadata records the source position information of a given YAML node, and returns |
| 723 | // the id associated with the source metadata which is returned in the Policy SourceInfo object. |
| 724 | func (p *parserImpl) CollectMetadata(node *yaml.Node) int64 { |
| 725 | id := p.NextID() |
| 726 | line := node.Line |
| 727 | col := int32(node.Column) |
| 728 | switch node.Style { |
| 729 | case yaml.DoubleQuotedStyle, yaml.SingleQuotedStyle: |
| 730 | col++ |
| 731 | } |
| 732 | offsetStart := int32(0) |
| 733 | if line > 1 { |
| 734 | offsetStart = p.info.LineOffsets()[line-2] |
| 735 | } |
| 736 | p.info.SetOffsetRange(id, ast.OffsetRange{Start: offsetStart + col - 1, Stop: offsetStart + col - 1}) |
| 737 | return id |
| 738 | } |
| 739 | |
| 740 | // ParsePolicy will parse the target yaml node as though it is the top-level policy. |
| 741 | func (p *parserImpl) ParsePolicy(ctx ParserContext, node *yaml.Node) *Policy { |
no test coverage detected