-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
10 changed files
with
316 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Prism.languages.n4js = Prism.languages.extend('javascript', { | ||
// Keywords from N4JS language spec: https://numberfour.github.io/n4js/spec/N4JSSpec.html | ||
'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/ | ||
}); | ||
|
||
Prism.languages.insertBefore('n4js', 'function', { | ||
// Annotations in N4JS spec: https://numberfour.github.io/n4js/spec/N4JSSpec.html#_annotations | ||
'annotation': { | ||
pattern: /(@+\w+)/, | ||
alias: 'operator' | ||
} | ||
}); | ||
|
||
Prism.languages.n4jsd=Prism.languages.n4js; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<h1>N4JS</h1> | ||
<p>To use this language, use the class "language-n4js".</p> | ||
|
||
|
||
<h2>Keywords</h2> | ||
<pre><code> | ||
class C {..} | ||
interface I {..} | ||
|
||
foo(c: C, i: I) { | ||
c instanceof C; // ok | ||
c instanceof I; // ok | ||
} | ||
</code></pre> | ||
|
||
<h2>Annotations</h2> | ||
<pre><code> | ||
// Final Methods | ||
@Final | ||
private tasks = new Map<string,Task>(); | ||
|
||
// Redefinition of Members | ||
@Override | ||
public async size(): int { | ||
… | ||
} | ||
|
||
// Dependency Injection | ||
@Binder | ||
@Bind(Storage,StorageInMemory) | ||
class InMemoryBinder {} | ||
|
||
@GenerateInjector @UseBinder(InMemoryBinder) | ||
export public class TaskManagerTest { | ||
… | ||
} | ||
</code></pre> | ||
|
||
<h2>Full example</h2> | ||
<pre><code> | ||
// A Web User Interface in HTML | ||
// NOTE: requires full example project bundled with N4JS IDE to run. | ||
|
||
import { TaskManager } from "TaskManager"; | ||
import {Application, Response } from "express"; | ||
import express from "express"; | ||
import { Todo } from "model"; | ||
|
||
|
||
export class WebUI { | ||
|
||
private app: Application; | ||
|
||
@Inject | ||
private manager: TaskManager; | ||
|
||
public start() { | ||
|
||
this.app = express(); | ||
|
||
this.app.get('/', async (req, res) => { | ||
let page = await this.renderHomePage(); | ||
res.send(page); | ||
}); | ||
|
||
this.app.get("/clear", async (req, res) => { | ||
await this.manager.clear(); | ||
redirect(res, '/'); | ||
}); | ||
|
||
this.app.get("/create", async (req, res) => { | ||
let values = req.query as ~Object with {type: string, label: string}; | ||
if (values && values.type === 'Todo' && values.label && values.label.length > 0) { | ||
await this.manager.createTodo(values.label); | ||
} | ||
redirect(res, '/'); | ||
}); | ||
|
||
this.app.listen(4000, '0.0.0.0', 511, function() { | ||
console.log("HTML server listening on http://localhost:4000/"); | ||
}); | ||
} | ||
|
||
protected async renderHomePage(): string { | ||
let tasks = await this.manager.getTasks(); | ||
let todos = tasks.filter((task) => task instanceof Todo); | ||
return ` | ||
|
||
<html> | ||
<body> | ||
Your to-do's: | ||
<ul> | ||
${ | ||
todos.length === 0 ? '<li><em>none</em></li>\n' | ||
: todos.map((task) => | ||
'<li>' + task.label + ' <small>(id: ' + task.id + ')</small></li>' | ||
).join('\n') | ||
} | ||
</ul> | ||
<hr/> | ||
<form action="/create" method="get"> | ||
<input type="hidden" name="type" value="Todo"> | ||
Label: <input type="text" name="label"><br> | ||
<input type="submit" value="Create Todo"> | ||
</form> | ||
<hr/> | ||
<a href="/clear">[Clear All]</a> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
} | ||
|
||
function redirect(res: Response, url: string) { | ||
res.header('Cache-Control', 'no-cache'); | ||
res.redirect(301, url); | ||
} | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@Inject | ||
@Internal | ||
@Undefined | ||
@StringBased | ||
@Final | ||
@GenerateInjector | ||
@WithParentInjector | ||
@Spec | ||
@Override | ||
@Promisifiable | ||
@Promisify | ||
@This | ||
@N4JS | ||
@IgnoreImplementation | ||
@Global | ||
@ProvidedByRuntime | ||
@TestAPI | ||
@Polyfill | ||
@StaticPolyfill | ||
@StaticPolyfillAware | ||
@StaticPolyfillModule | ||
@Transient | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["annotation", "@Inject"], | ||
["annotation", "@Internal"], | ||
["annotation", "@Undefined"], | ||
["annotation", "@StringBased"], | ||
["annotation", "@Final"], | ||
["annotation", "@GenerateInjector"], | ||
["annotation", "@WithParentInjector"], | ||
["annotation", "@Spec"], | ||
["annotation", "@Override"], | ||
["annotation", "@Promisifiable"], | ||
["annotation", "@Promisify"], | ||
["annotation", "@This"], | ||
["annotation", "@N4JS"], | ||
["annotation", "@IgnoreImplementation"], | ||
["annotation", "@Global"], | ||
["annotation", "@ProvidedByRuntime"], | ||
["annotation", "@TestAPI"], | ||
["annotation", "@Polyfill"], | ||
["annotation", "@StaticPolyfill"], | ||
["annotation", "@StaticPolyfillAware"], | ||
["annotation", "@StaticPolyfillModule"], | ||
["annotation", "@Transient"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Test for annotations. |
Oops, something went wrong.