diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index c0a9ae6e58..44ab34d28a 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -47,11 +47,12 @@ The table below shows the full list of languages (and corresponding classes/alia | C3 | c3 | [highlightjs-c3](https://github.com/highlightjs/highlightjs-c3) | | Cache Object Script | cos, cls | | | Candid | candid, did | [highlightjs-motoko](https://github.com/rvanasa/highlightjs-motoko) | -| Cap’n Proto | capnproto, capnp | | +| Cap'n Proto | capnproto, capnp | | +| Ceylon | ceylon | | | Chaos | chaos, kaos | [highlightjs-chaos](https://github.com/chaos-lang/highlightjs-chaos) | | Chapel | chapel, chpl | [highlightjs-chapel](https://github.com/chapel-lang/highlightjs-chapel) | | Cisco CLI | cisco | [highlightjs-cisco-cli](https://github.com/BMatheas/highlightjs-cisco-cli) | -| Clojure | clojure, clj | | +| Clojure | clojure, clj, edn | | | CMake | cmake, cmake.in | | | COBOL | cobol, standard-cobol | [highlightjs-cobol](https://github.com/otterkit/highlightjs-cobol) | | CODEOWNERS | codeowners | [highlightjs-codeowners](https://github.com/highlightjs/highlightjs-codeowners) | diff --git a/src/languages/cedar.js b/src/languages/cedar.js new file mode 100644 index 0000000000..cda582a0cd --- /dev/null +++ b/src/languages/cedar.js @@ -0,0 +1,140 @@ +/* +Language: Cedar +Description: Cedar is a language for writing authorization policies and making authorization decisions based on those policies. +Website: https://www.cedarpolicy.com/ +Category: system +*/ + +/** @type LanguageFn */ +export default function(hljs) { + const GLOBALS = { + match: /\b(?:ip|decimal|datetime|duration)(?=\()/, + scope: 'built_in', + }; + + const VARIABLES = { + match: /\b(?=', + '<=', + '>', + '<', + '\\+', + '-', + '\\*', + 'in', + 'like', + 'has', + 'is', + ].join('|') + + ')' + + /(?!\w)/.source, + scope: 'operator', + relevance: 0, + }; + + const INTEGER = { + scope: 'number', + begin: `0|\\-?[1-9](_?[0-9])*`, + relevance: 0, + }; + + const ENTITIES = { + match: /(?=\b)(([_a-zA-Z][_a-zA-Z0-9]*::)*[_a-zA-Z][_a-zA-Z0-9]*)(?=::)/, + scope: 'title.class', + }; + + const ISENTITY = { + match: [/is/, /\s+/, /([_a-zA-Z][_a-zA-Z0-9]*::)*[_a-zA-Z][_a-zA-Z0-9]*/], + scope: { + 1: 'operator', + 3: 'title.class', + }, + }; + + const METHODS = { + scope: 'title.function.invoke', + begin: `(?=\.)(contains|containsAll|containsAny|isEmpty|getTag|hasTag)(?=\\()`, + relevance: 0, + }; + + const DECIMAL_METHODS = { + scope: 'title.function.invoke', + begin: `(?=\.)(lessThan|lessThanOrEqual|greaterThan|greaterThanOrEqual)(?=\\()`, + relevance: 0, + }; + + const IP_METHODS = { + scope: 'title.function.invoke', + begin: `(?=\.)(isIpv4|isIpv6|isLoopback|isMulticast|isInRange)(?=\\()`, + relevance: 0, + }; + + const DATETIME_METHODS = { + scope: 'title.function.invoke', + begin: `(?=\.)(offset|durationSince|toDate|toTime)(?=\\()`, + relevance: 0, + }; + + const DURATION_METHODS = { + scope: 'title.function.invoke', + begin: `(?=\.)(toMilliseconds|toSeconds|toMinutes|toHours|toDays)(?=\\()`, + relevance: 0, + }; + + return { + name: 'Cedar', + aliases: ['cedar'], + case_insensitive: false, + keywords: KEYWORDS, + contains: [ + hljs.QUOTE_STRING_MODE, + hljs.C_LINE_COMMENT_MODE, + GLOBALS, + VARIABLES, + POLICY, + INTEGER, + PUNCTUATION, + ENTITIES, + ISENTITY, + OPERATORS, + METHODS, + DECIMAL_METHODS, + IP_METHODS, + DATETIME_METHODS, + DURATION_METHODS, + TEMPLATES, + ], + }; +}