basant307/AI_Governance_Project
048
1/*2Language: YAML3Description: Yet Another Markdown Language4Author: Stefan Wienert <stwienert@gmail.com>5Contributors: Carl Baxter <carl@cbax.tech>6Requires: ruby.js7Website: https://yaml.org8Category: common, config9*/10function yaml(hljs) {11 const LITERALS = 'true false yes no null';12 13 // YAML spec allows non-reserved URI characters in tags.14 const URI_CHARACTERS = '[\\w#;/?:@&=+$,.~*\'()[\\]]+';15 16 // Define keys as starting with a word character17 // ...containing word chars, spaces, colons, forward-slashes, hyphens and periods18 // ...and ending with a colon followed immediately by a space, tab or newline.19 // The YAML spec allows for much more than this, but this covers most use-cases.20 const KEY = {21 className: 'attr',22 variants: [23 // added brackets support and special char support24 { begin: /[\w*@][\w*@ :()\./-]*:(?=[ \t]|$)/ },25 { // double quoted keys - with brackets and special char support26 begin: /"[\w*@][\w*@ :()\./-]*":(?=[ \t]|$)/ },27 { // single quoted keys - with brackets and special char support28 begin: /'[\w*@][\w*@ :()\./-]*':(?=[ \t]|$)/ },29 ]30 };31 32 const TEMPLATE_VARIABLES = {33 className: 'template-variable',34 variants: [35 { // jinja templates Ansible36 begin: /\{\{/,37 end: /\}\}/38 },39 { // Ruby i18n40 begin: /%\{/,41 end: /\}/42 }43 ]44 };45 46 const SINGLE_QUOTE_STRING = {47 className: 'string',48 relevance: 0,49 begin: /'/,50 end: /'/,51 contains: [52 {53 match: /''/,54 scope: 'char.escape',55 relevance: 056 }57 ]58 };59 60 const STRING = {61 className: 'string',62 relevance: 0,63 variants: [64 {65 begin: /"/,66 end: /"/67 },68 { begin: /\S+/ }69 ],70 contains: [71 hljs.BACKSLASH_ESCAPE,72 TEMPLATE_VARIABLES73 ]74 };75 76 // Strings inside of value containers (objects) can't contain braces,77 // brackets, or commas78 const CONTAINER_STRING = hljs.inherit(STRING, { variants: [79 {80 begin: /'/,81 end: /'/,82 contains: [83 {84 begin: /''/,85 relevance: 086 }87 ]88 },89 {90 begin: /"/,91 end: /"/92 },93 { begin: /[^\s,{}[\]]+/ }94 ] });95 96 const DATE_RE = '[0-9]{4}(-[0-9][0-9]){0,2}';97 const TIME_RE = '([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?';98 const FRACTION_RE = '(\\.[0-9]*)?';99 const ZONE_RE = '([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?';100 const TIMESTAMP = {101 className: 'number',102 begin: '\\b' + DATE_RE + TIME_RE + FRACTION_RE + ZONE_RE + '\\b'103 };104 105 const VALUE_CONTAINER = {106 end: ',',107 endsWithParent: true,108 excludeEnd: true,109 keywords: LITERALS,110 relevance: 0111 };112 const OBJECT = {113 begin: /\{/,114 end: /\}/,115 contains: [ VALUE_CONTAINER ],116 illegal: '\\n',117 relevance: 0118 };119 const ARRAY = {120 begin: '\\[',121 end: '\\]',122 contains: [ VALUE_CONTAINER ],123 illegal: '\\n',124 relevance: 0125 };126 127 const MODES = [128 KEY,129 {130 className: 'meta',131 begin: '^---\\s*$',132 relevance: 10133 },134 { // multi line string135 // Blocks start with a | or > followed by a newline136 //137 // Indentation of subsequent lines must be the same to138 // be considered part of the block139 className: 'string',140 begin: '[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*'141 },142 { // Ruby/Rails erb143 begin: '<%[%=-]?',144 end: '[%-]?%>',145 subLanguage: 'ruby',146 excludeBegin: true,147 excludeEnd: true,148 relevance: 0149 },150 { // named tags151 className: 'type',152 begin: '!\\w+!' + URI_CHARACTERS153 },154 // https://yaml.org/spec/1.2/spec.html#id2784064155 { // verbatim tags156 className: 'type',157 begin: '!<' + URI_CHARACTERS + ">"158 },159 { // primary tags160 className: 'type',161 begin: '!' + URI_CHARACTERS162 },163 { // secondary tags164 className: 'type',165 begin: '!!' + URI_CHARACTERS166 },167 { // fragment id &ref168 className: 'meta',169 begin: '&' + hljs.UNDERSCORE_IDENT_RE + '$'170 },171 { // fragment reference *ref172 className: 'meta',173 begin: '\\*' + hljs.UNDERSCORE_IDENT_RE + '$'174 },175 { // array listing176 className: 'bullet',177 // TODO: remove |$ hack when we have proper look-ahead support178 begin: '-(?=[ ]|$)',179 relevance: 0180 },181 hljs.HASH_COMMENT_MODE,182 {183 beginKeywords: LITERALS,184 keywords: { literal: LITERALS }185 },186 TIMESTAMP,187 // numbers are any valid C-style number that188 // sit isolated from other words189 {190 className: 'number',191 begin: hljs.C_NUMBER_RE + '\\b',192 relevance: 0193 },194 OBJECT,195 ARRAY,196 SINGLE_QUOTE_STRING,197 STRING198 ];199 200 const VALUE_MODES = [ ...MODES ];201 VALUE_MODES.pop();202 VALUE_MODES.push(CONTAINER_STRING);203 VALUE_CONTAINER.contains = VALUE_MODES;204 205 return {206 name: 'YAML',207 case_insensitive: true,208 aliases: [ 'yml' ],209 contains: MODES210 };211}212 213export { yaml as default };214 