'use strict' ; import { Parser , Composer , Document , LineCounter , ParseOptions , DocumentOptions , SchemaOptions } from 'yaml' ; import { YAMLDocument , SingleYAMLDocument } from './yaml-documents' ; import { getCustomTags } from './custom-tag-provider' ; export { YAMLDocument , SingleYAMLDocument } ; export type YamlVersion = '1.1' | '1.2' ; export interface ParserOptions { customTags : string [ ] ; yamlVersion : YamlVersion ; } export const defaultOptions = { customTags : [ ] , yamlVersion : '1.2' , } ; /**
 * `yaml-ast-parser-custom-tags` parses the AST and
 * returns YAML AST nodes, which are then formatted
 * for consumption via the language server.
 */ export function parse ( text , parserOptions = defaultOptions ) { const options = { strict : false , customTags : getCustomTags ( parserOptions . customTags ) , version : parserOptions . yamlVersion , } ; const composer = new Composer ( options ) ; const lineCounter = new LineCounter ( ) ; const parser = new Parser ( lineCounter . addNewLine ) ; const tokens = parser . parse ( text ) ; const tokensArr = Array . from ( tokens ) ; const docs = composer . compose ( tokensArr , true , text . length ) ; const yamlDocs = Array . from ( docs , ( doc ) => parsedDocToSingleYAMLDocument ( doc , lineCounter ) ) ; return new YAMLDocument ( yamlDocs , tokensArr ) ; } function parsedDocToSingleYAMLDocument ( parsedDoc , lineCounter ) { const syd = new SingleYAMLDocument ( lineCounter ) ; syd . internalDocument = parsedDoc ; return syd ; }