Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Web IDL language support #1102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions components.js
Expand Up @@ -560,6 +560,11 @@ var components = {
"title": "vim",
"owner": "westonganger"
},
"webidl": {
"title": "Web IDL",
"require": "clike",
"owner": "grorg"
},
"wiki": {
"title": "Wiki markup",
"require": "markup",
Expand Down
12 changes: 12 additions & 0 deletions components/prism-webidl.js
@@ -0,0 +1,12 @@
Prism.languages.webidl = Prism.languages.extend('c', {
'keyword': /\b(any|attribute|boolean|byte|ByteString|callback|const|deleter|dictionary|DOMString|double|enum|float|FrozenArray|getter|identifier|implements|Infinity|inherit|integer|interface|iterable|legacycaller|long|maplike|namespace|NaN|null|object|octet|optional|or|other|partial|readonly|required|sequence|serializer|setlike|setter|short|static|string|stringifier|typedef|unrestricted|unsigned|USVString|void)\b/,
'boolean': /\b(true|false)\b/,
'operator': /-|:|=|\?|\*|\//
});

Prism.languages.insertBefore('webidl', 'keyword', {
'class-name': {
pattern: /(class\s+)[a-z0-9_]+/i,
lookbehind: true
}
});
Copy link
Member

@LeaVerou LeaVerou Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of calling insertBefore for webidl right after you've defined webidl? insertBefore is used to modify existing languages, if you're defining a language yourself you don't need it, just put "class-name" in the object literal.

Also, your dependencies list C-like, but here you seem to be extending C. These are two different language definitions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the cpp implementation, so maybe there is something in the insertBefore code that it needed. Either way, I don't understand so I'm happy to do whatever.

As for the dependencies, you're right that it's not clear. WebIDL isn't technically C, C-like, or CPP. I figured it would be ok to extend from cpp though, since it does have fairly similar syntax.

Copy link
Member

@LeaVerou LeaVerou Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add the "class-name" token before the keyword token. There's no need for it to be separate. What the cpp language is doing is weird too, @zeitgeist87 what was the rationale?

As for the dependencies, I don't mind which one you inherit from, just be consistent between your code and the components declaration, otherwise people will get a download that doesn't work. Perhaps look over their examples to decide which of the three is closer to WebIDL?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeaVerou The c language actually deletes the class-name property from clike, so if you inherit from c and you want to put class-name at a certain position, you have to use insertBefore(). However if you inherit from clike, you can directly add class-name to the language.

Copy link
Member

@LeaVerou LeaVerou Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So the main blocker here is that @grorg needs to decide whether he's extending C, C++ or C-like. I think the latter is probably a better fit, but he knows WebIDL better.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tips @LeaVerou and @zeitgeist87. I'll update the patch soon.

he knows WebIDL better

Hahahahaha. If only.

1 change: 1 addition & 0 deletions components/prism-webidl.min.js

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

37 changes: 37 additions & 0 deletions examples/prism-webidl.html
@@ -0,0 +1,37 @@
<h1>Web IDL</h1>
<p>To use this language, use the class "language-webidl".</p>

<h2>Strings</h2>
<pre><code>"foo \"bar\" baz"
'foo \'bar\' baz'
"Multi-line strings ending with a \
are supported too."</code></pre>

<h2>Booleans</h2>
<pre><code>true;
false;</code></pre>

<h2>Full example</h2>
<pre><code>interface Paint { };

interface SolidColor : Paint {
attribute double red;
attribute double green;
attribute double blue;
};

interface Pattern : Paint {
attribute DOMString imageURL;
};

[Constructor]
interface GraphicalWindow {
readonly attribute unsigned long width;
readonly attribute unsigned long height;

attribute Paint currentPaint;

void drawRectangle(double x, double y, double width, double height);

void drawText(double x, double y, DOMString text);
};</code></pre>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","wiki":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","aspnet":"markup","bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","fsharp":"clike","glsl":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup","haxe":"clike","jade":"javascript","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","nginx":"clike","objectivec":"c","parser":"markup","php":"clike","php-extras":"php","processing":"clike","protobuf":"clike","qore":"clike","jsx":["markup","javascript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup","swift":"clike","textile":"markup","twig":"markup","typescript":"javascript","webidl":"clike","wiki":"markup"}/*]*/;

var lang_data = {};

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: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Expand Up @@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","webidl":"Web IDL","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

13 changes: 13 additions & 0 deletions tests/languages/webidl/boolean_feature.test
@@ -0,0 +1,13 @@
true
false

----------------------------------------------------

[
["boolean", "true"],
["boolean", "false"]
]

----------------------------------------------------

Checks for booleans.
107 changes: 107 additions & 0 deletions tests/languages/webidl/keyword_feature.test
@@ -0,0 +1,107 @@
any
attribute
boolean
byte
ByteString
callback
const
deleter
dictionary
DOMString
double
enum
float
FrozenArray
getter
identifier
implements
Infinity
inherit
integer
interface
iterable
legacycaller
long
maplike
namespace
NaN
null
object
octet
optional
or
other
partial
readonly
required
sequence
serializer
setlike
setter
short
static
string
stringifier
typedef
unrestricted
unsigned
USVString
void

----------------------------------------------------

[
["keyword", "any"],
["keyword", "attribute"],
["keyword", "boolean"],
["keyword", "byte"],
["keyword", "ByteString"],
["keyword", "callback"],
["keyword", "const"],
["keyword", "deleter"],
["keyword", "dictionary"],
["keyword", "DOMString"],
["keyword", "double"],
["keyword", "enum"],
["keyword", "float"],
["keyword", "FrozenArray"],
["keyword", "getter"],
["keyword", "identifier"],
["keyword", "implements"],
["keyword", "Infinity"],
["keyword", "inherit"],
["keyword", "integer"],
["keyword", "interface"],
["keyword", "iterable"],
["keyword", "legacycaller"],
["keyword", "long"],
["keyword", "maplike"],
["keyword", "namespace"],
["keyword", "NaN"],
["keyword", "null"],
["keyword", "object"],
["keyword", "octet"],
["keyword", "optional"],
["keyword", "or"],
["keyword", "other"],
["keyword", "partial"],
["keyword", "readonly"],
["keyword", "required"],
["keyword", "sequence"],
["keyword", "serializer"],
["keyword", "setlike"],
["keyword", "setter"],
["keyword", "short"],
["keyword", "static"],
["keyword", "string"],
["keyword", "stringifier"],
["keyword", "typedef"],
["keyword", "unrestricted"],
["keyword", "unsigned"],
["keyword", "USVString"],
["keyword", "void"],
]

----------------------------------------------------

Checks for all keywords