Skip to content

Commit eaa8ebb

Browse files
committed
Merge branch 'n4js' of https://github.com/bsmith-n4/prism into bsmith-n4-n4js
# Conflicts: # plugins/show-language/prism-show-language.js # plugins/show-language/prism-show-language.min.js
2 parents 4341265 + af937cf commit eaa8ebb

10 files changed

+316
-4
lines changed

components.js

+5
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ var components = {
345345
"title": "Monkey",
346346
"owner": "Golmote"
347347
},
348+
"n4js":{
349+
"title": "N4JS",
350+
"require": "javascript",
351+
"owner": "bsmith-n4"
352+
},
348353
"nasm": {
349354
"title": "NASM",
350355
"owner": "rbmj"

components/prism-n4js.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Prism.languages.n4js = Prism.languages.extend('javascript', {
2+
// Keywords from N4JS language spec: https://numberfour.github.io/n4js/spec/N4JSSpec.html
3+
'keyword': /\b(any|Array|boolean|break|case|catch|class|const|constructor|continue|debugger|declare|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|module|new|null|number|package|private|protected|public|return|set|static|string|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/
4+
});
5+
6+
Prism.languages.insertBefore('n4js', 'function', {
7+
// Annotations in N4JS spec: https://numberfour.github.io/n4js/spec/N4JSSpec.html#_annotations
8+
'annotation': {
9+
pattern: /(@+\w+)/,
10+
alias: 'operator'
11+
}
12+
});
13+
14+
Prism.languages.n4jsd=Prism.languages.n4js;

components/prism-n4js.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-n4js.html

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<h1>N4JS</h1>
2+
<p>To use this language, use the class "language-n4js".</p>
3+
4+
5+
<h2>Keywords</h2>
6+
<pre><code>
7+
class C {..}
8+
interface I {..}
9+
10+
foo(c: C, i: I) {
11+
c instanceof C; // ok
12+
c instanceof I; // ok
13+
}
14+
</code></pre>
15+
16+
<h2>Annotations</h2>
17+
<pre><code>
18+
// Final Methods
19+
@Final
20+
private tasks = new Map&lt;string,Task&gt;();
21+
22+
// Redefinition of Members
23+
@Override
24+
public async size(): int {
25+
26+
}
27+
28+
// Dependency Injection
29+
@Binder
30+
@Bind(Storage,StorageInMemory)
31+
class InMemoryBinder {}
32+
33+
@GenerateInjector @UseBinder(InMemoryBinder)
34+
export public class TaskManagerTest {
35+
36+
}
37+
</code></pre>
38+
39+
<h2>Full example</h2>
40+
<pre><code>
41+
// A Web User Interface in HTML
42+
// NOTE: requires full example project bundled with N4JS IDE to run.
43+
44+
import { TaskManager } from "TaskManager";
45+
import {Application, Response } from "express";
46+
import express from "express";
47+
import { Todo } from "model";
48+
49+
50+
export class WebUI {
51+
52+
private app: Application;
53+
54+
@Inject
55+
private manager: TaskManager;
56+
57+
public start() {
58+
59+
this.app = express();
60+
61+
this.app.get('/', async (req, res) => {
62+
let page = await this.renderHomePage();
63+
res.send(page);
64+
});
65+
66+
this.app.get("/clear", async (req, res) => {
67+
await this.manager.clear();
68+
redirect(res, '/');
69+
});
70+
71+
this.app.get("/create", async (req, res) => {
72+
let values = req.query as ~Object with {type: string, label: string};
73+
if (values && values.type === 'Todo' && values.label && values.label.length > 0) {
74+
await this.manager.createTodo(values.label);
75+
}
76+
redirect(res, '/');
77+
});
78+
79+
this.app.listen(4000, '0.0.0.0', 511, function() {
80+
console.log("HTML server listening on http://localhost:4000/");
81+
});
82+
}
83+
84+
protected async renderHomePage(): string {
85+
let tasks = await this.manager.getTasks();
86+
let todos = tasks.filter((task) => task instanceof Todo);
87+
return `
88+
89+
&lt;html&gt;
90+
&lt;body&gt;
91+
Your to-do's:
92+
&lt;ul&gt;
93+
${
94+
todos.length === 0 ? '&lt;li&gt;&lt;em&gt;none&lt;/em&gt;&lt;/li&gt;\n'
95+
: todos.map((task) =>
96+
'&lt;li&gt;' + task.label + ' &lt;small&gt;(id: ' + task.id + ')&lt;/small&gt;&lt;/li&gt;'
97+
).join('\n')
98+
}
99+
&lt;/ul&gt;
100+
&lt;hr/&gt;
101+
&lt;form action="/create" method="get"&gt;
102+
&lt;input type="hidden" name="type" value="Todo"&gt;
103+
Label: &lt;input type="text" name="label"&gt;&lt;br&gt;
104+
&lt;input type="submit" value="Create Todo"&gt;
105+
&lt;/form&gt;
106+
&lt;hr/&gt;
107+
&lt;a href="/clear"&gt;[Clear All]&lt;/a&gt;
108+
&lt;/body&gt;
109+
&lt;/html&gt;
110+
`;
111+
}
112+
}
113+
114+
function redirect(res: Response, url: string) {
115+
res.header('Cache-Control', 'no-cache');
116+
res.redirect(301, url);
117+
}
118+
</code></pre>

plugins/autoloader/prism-autoloader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

66
// The dependencies map is built automatically with gulp
7-
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","vbnet":"basic","wiki":"markup"}/*]*/;
7+
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","n4js":"javascript","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","vbnet":"basic","wiki":"markup"}/*]*/;
88

99
var lang_data = {};
1010

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
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","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
14+
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","n4js":"N4JS","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","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@Inject
2+
@Internal
3+
@Undefined
4+
@StringBased
5+
@Final
6+
@GenerateInjector
7+
@WithParentInjector
8+
@Spec
9+
@Override
10+
@Promisifiable
11+
@Promisify
12+
@This
13+
@N4JS
14+
@IgnoreImplementation
15+
@Global
16+
@ProvidedByRuntime
17+
@TestAPI
18+
@Polyfill
19+
@StaticPolyfill
20+
@StaticPolyfillAware
21+
@StaticPolyfillModule
22+
@Transient
23+
24+
----------------------------------------------------
25+
26+
[
27+
["annotation", "@Inject"],
28+
["annotation", "@Internal"],
29+
["annotation", "@Undefined"],
30+
["annotation", "@StringBased"],
31+
["annotation", "@Final"],
32+
["annotation", "@GenerateInjector"],
33+
["annotation", "@WithParentInjector"],
34+
["annotation", "@Spec"],
35+
["annotation", "@Override"],
36+
["annotation", "@Promisifiable"],
37+
["annotation", "@Promisify"],
38+
["annotation", "@This"],
39+
["annotation", "@N4JS"],
40+
["annotation", "@IgnoreImplementation"],
41+
["annotation", "@Global"],
42+
["annotation", "@ProvidedByRuntime"],
43+
["annotation", "@TestAPI"],
44+
["annotation", "@Polyfill"],
45+
["annotation", "@StaticPolyfill"],
46+
["annotation", "@StaticPolyfillAware"],
47+
["annotation", "@StaticPolyfillModule"],
48+
["annotation", "@Transient"]
49+
]
50+
51+
----------------------------------------------------
52+
53+
Test for annotations.

0 commit comments

Comments
 (0)