Skip to content

Commit

Permalink
Added the Nand2Tetris HDL language (#1710)
Browse files Browse the repository at this point in the history
This adds support for the [Nand2Tetris](https://www.nand2tetris.org/) HDL language.
  • Loading branch information
stephanmax authored and RunDevelopment committed Jan 15, 2019
1 parent b1f8a65 commit b94b56c
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@
"alias": "n4jsd",
"owner": "bsmith-n4"
},
"nand2tetris-hdl": {
"title": "Nand To Tetris HDL",
"owner": "stephanmax"
},
"nasm": {
"title": "NASM",
"owner": "rbmj"
Expand Down
1 change: 1 addition & 0 deletions components/prism-hdl.min.js

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

9 changes: 9 additions & 0 deletions components/prism-nand2tetris-hdl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Prism.languages['nand2tetris-hdl'] = {
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'keyword': /\b(?:CHIP|IN|OUT|PARTS|BUILTIN|CLOCKED)\b/,
'boolean': /\b(?:true|false)\b/,
'function': /[A-Za-z][A-Za-z0-9]*(?=\()/,
'number': /\b\d+\b/,
'operator': /=|\.\./,
'punctuation': /[{}[\];(),:]/
};
1 change: 1 addition & 0 deletions components/prism-nand2tetris-hdl.min.js

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

23 changes: 23 additions & 0 deletions examples/prism-nand2tetris-hdl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h2>Comments</h2>
<pre><code>// Single line comment
/* Multi-line
comment */</code></pre>

<h2>Literal values</h2>
<pre><code>0
32
true
false</code></pre>

<h2>Full example</h2>
<pre><code>/*
* Checks if two input bits are equal
*/

CHIP Eq {
IN a, b;
OUT out; // True iff a=b
PARTS:
Xor(a=a, b=b, out=uneq);
Not(in=uneq, out=out);
}</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
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","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","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","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","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/nand2tetris-hdl/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
true
false

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

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

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

Checks for booleans.
20 changes: 20 additions & 0 deletions tests/languages/nand2tetris-hdl/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// foobar
/**/
/* foo
bar */
/*
* foobar
*/

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

[
["comment", "// foobar"],
["comment", "/**/"],
["comment", "/* foo\r\nbar */"],
["comment", "/*\r\n * foobar\r\n */"]
]

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

Checks for single-line and multi-line comments.
23 changes: 23 additions & 0 deletions tests/languages/nand2tetris-hdl/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
And()
not()
mux16()

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

[
["function", "And"],
["punctuation", "("],
["punctuation", ")"],

["function", "not"],
["punctuation", "("],
["punctuation", ")"],

["function", "mux16"],
["punctuation", "("],
["punctuation", ")"]
]

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

Checks for functions.
21 changes: 21 additions & 0 deletions tests/languages/nand2tetris-hdl/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CHIP
IN
OUT
PARTS
BUILTIN
CLOCKED

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

[
["keyword", "CHIP"],
["keyword", "IN"],
["keyword", "OUT"],
["keyword", "PARTS"],
["keyword", "BUILTIN"],
["keyword", "CLOCKED"]
]

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

Checks for all keywords.
15 changes: 15 additions & 0 deletions tests/languages/nand2tetris-hdl/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
0
16
32

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

[
["number", "0"],
["number", "16"],
["number", "32"]
]

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

Checks for integer numbers.
13 changes: 13 additions & 0 deletions tests/languages/nand2tetris-hdl/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=
..

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

[
["operator", "="],
["operator", ".."]
]

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

Checks for all operators.
23 changes: 23 additions & 0 deletions tests/languages/nand2tetris-hdl/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
( )
{ }
[ ]
,
;
:

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

[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", ","],
["punctuation", ";"],
["punctuation", ":"]
]
----------------------------------------------------

Checks for punctuation.

0 comments on commit b94b56c

Please sign in to comment.