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)
| 680 | // CollectMetadata records the source position information of a given YAML node, and returns |
| 681 | // the id associated with the source metadata which is returned in the Policy SourceInfo object. |
| 682 | func (p *parserImpl) CollectMetadata(node *yaml.Node) int64 { |
| 683 | id := p.NextID() |
| 684 | line := node.Line |
| 685 | col := int32(node.Column) |
| 686 | switch node.Style { |
| 687 | case yaml.DoubleQuotedStyle, yaml.SingleQuotedStyle: |
| 688 | col++ |
| 689 | } |
| 690 | offsetStart := int32(0) |
| 691 | if line > 1 { |
| 692 | offsetStart = p.info.LineOffsets()[line-2] |
| 693 | } |
| 694 | p.info.SetOffsetRange(id, ast.OffsetRange{Start: offsetStart + col - 1, Stop: offsetStart + col - 1}) |
| 695 | return id |
| 696 | } |
| 697 | |
| 698 | // ParsePolicy will parse the target yaml node as though it is the top-level policy. |
| 699 | func (p *parserImpl) ParsePolicy(ctx ParserContext, node *yaml.Node) *Policy { |
no test coverage detected