Skip to content

Commit

Permalink
Added support for CFScript (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjclemente authored Feb 19, 2021
1 parent f79b0ee commit b0a6ec8
Show file tree
Hide file tree
Showing 15 changed files with 467 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
"require": "c",
"owner": "zeitgeist87"
},
"cfscript": {
"title": "CFScript",
"require": "clike",
"alias": "cfc",
"owner": "mjclemente"
},
"chaiscript": {
"title": "ChaiScript",
"require": ["clike", "cpp"],
Expand Down
44 changes: 44 additions & 0 deletions components/prism-cfscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// https://cfdocs.org/script
Prism.languages.cfscript = Prism.languages.extend('clike', {
'comment': [
{
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
lookbehind: true,
inside: {
'annotation': {
pattern: /(?:^|[^.])@[\w\.]+/,
alias: 'punctuation'
}
}
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'keyword': /\b(?:abstract|break|catch|component|continue|default|do|else|extends|final|finally|for|function|if|in|include|package|private|property|public|remote|required|rethrow|return|static|switch|throw|try|var|while|xml)\b(?!\s*\=)/,
'operator': [
/\+\+|--|&&|\|\||::|=>|[!=]==|<=?|>=?|[-+*/%&|^!=<>]=?|\?(?:\.|:)?|[?:]/,
/\b(?:and|contains|eq|equal|eqv|gt|gte|imp|is|lt|lte|mod|not|or|xor)\b/
],
'scope': {
pattern: /\b(?:application|arguments|cgi|client|cookie|local|session|super|this|variables)\b/,
alias: 'global'
},
'type': {
pattern: /\b(?:any|array|binary|boolean|date|guid|numeric|query|string|struct|uuid|void|xml)\b/,
alias: 'builtin'
}
});

Prism.languages.insertBefore('cfscript', 'keyword', {
// This must be declared before keyword because we use "function" inside the lookahead
'function-variable': {
pattern: /[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
alias: 'function'
}
});

delete Prism.languages.cfscript['class-name'];
Prism.languages.cfc = Prism.languages['cfscript'];
1 change: 1 addition & 0 deletions components/prism-cfscript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions examples/prism-cfscript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<h2>Comments</h2>
<pre><code>// This is a comment

/* This is a comment
on multiple lines */

/**
* This is a Javadoc style comment
*
* @hint This is an annotation
*/
</code></pre>

<h2>Functions</h2>
<pre><code>public boolean function myFunc(required any arg) {
return true;
}</code></pre>

<h2>Full example</h2>
<pre><code>component accessors="true" {
property type="string" name="prop1" default="";
property string prop2;
function init(){
this.prop3 = 12;
return this;
}

/**
* @hint Annotations supported
* @foo.hint
*/
public any function build( required foo, color="blue", boolean bar=true ){
arguments.foo = {
'name' : "something",
test = true
}
var foobar = function( required string baz, x=true, y=false ){
return "bar!";
};
return foo;
}
}
</code></pre>
2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"c": "clike",
"csharp": "clike",
"cpp": "c",
"cfscript": "clike",
"chaiscript": [
"clike",
"cpp"
Expand Down Expand Up @@ -173,6 +174,7 @@
"oscript": "bsl",
"cs": "csharp",
"dotnet": "csharp",
"cfc": "cfscript",
"coffee": "coffeescript",
"conc": "concurnas",
"jinja2": "django",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"cs": "C#",
"dotnet": "C#",
"cpp": "C++",
"cfscript": "CFScript",
"cfc": "CFScript",
"cil": "CIL",
"cmake": "CMake",
"coffee": "CoffeeScript",
Expand Down
Loading

0 comments on commit b0a6ec8

Please sign in to comment.