Syntax & Symbols

仕組み

NoShift.js は ^(キャレット)をプレフィックスとして Shift 記号を表現します。マッピングは日本語 JIS キーボード配列に基づいています。

記号マップ

この変換表は NoShift.js 開発者のキーボード(JIS 配列)が基準です。

開発者のキーボード
Shift 記号 NoShift.js
! ^1
" ^2
# ^3
$ ^4
% ^5
Capitalize ^6
' ^7
( ^8
) ^9
^ (Caret/XOR) ^0
= ^-
Shift 記号 NoShift.js
~ ^^
_ ^\
` ^@
{ ^[
} ^]
+ ^;
* ^:
< ^,
> ^.
? ^/

テンプレート式: ^4^[${

大文字化修飾子

^6 は次の文字を大文字にします。クラス名や定数に便利です:

class ^6animal ^[
  constructor^8name^9 ^[
    this.name ^- name;
  ^]
^]

コンパイル後:

class Animal {
  constructor(name) {
    this.name = name;
  }
}

コメント

行コメントは通常通り // を使います。ブロックコメントは /^: で開始、^:/ で終了します:

// line comment

/^: block comment ^:/

/^:
  multi-line
  block comment
^:/

コンパイル後:

// line comment

/* block comment */

/*
  multi-line
  block comment
*/

文字列内のエスケープ

文字列リテラル(^2...^2^7...^7^@...^@)内では、^ シーケンスは Shift 記号に変換されません。これにより、リテラルの ^ 文字を含めることができます:

^2^5^2
^7^5^7
^@^5^@

コンパイル後:

"^5"
'^5'
`^5`

テンプレートリテラル

テンプレートリテラルは ^@(バッククォート)を使い、テンプレート式は ^4^[${)で開始し、^]})で終了します:

^@^5^4^[^2Hello World!^2^]^@

コンパイル後:

`^5${"Hello World!"}`

Shebang

先頭行の shebang には #! の代わりに #^1 を使います。^1 は通常通り ! に変換されます:

#^1/usr/bin/env node
console.log^8^2^6hello^2^9;

コンパイル後:

#!/usr/bin/env node
console.log("Hello");

ビット演算・シフト演算

JavaScript のビット演算子は NoShift.js の既存の ^ シーケンスで記述できます。XOR 演算子(^)は ^0 を使います(キャレットは NoShift.js のプレフィックスであるため):

// XOR: ^0 --> ^
const a ^- 5 ^0 3;

// XOR assignment: ^0^- --> ^=
let b ^- 7;
b ^0^- 3;

// AND: @and, OR: @or, NOT: ^^
const c ^- 5 @and 3;
const d ^- 5 @or 3;
const e ^- ^^5;

// Left shift: ^,^,  Right shift: ^.^.
const f ^- 1 ^,^, 3;
const g ^- 8 ^.^. 1;
const h ^- -1 ^.^.^. 0;

コンパイル後:

// XOR: ^0 --> ^
const a = 5 ^ 3;

// XOR assignment: ^0^- --> ^=
let b = 7;
b ^= 3;

// AND: @and, OR: @or, NOT: ^^
const c = 5 & 3;
const d = 5 | 3;
const e = ~5;

// Left shift: ^,^,  Right shift: ^.^.
const f = 1 << 3;
const g = 8 >> 1;
const h = -1 >>> 0;

Hello World

入力:

console.log^8^2^6hello ^6world!^2^9;

出力:

console.log("Hello World!");

キーワードエイリアス

NoShift.js は論理演算子とビット演算子にキーワードエイリアスを提供します。これらのキーワードはコード内のみ置換されます(文字列やコメント内では置換されません):

NoShift JS 説明
or||論理 OR
and&&論理 AND
@or|ビット OR
@and&ビット AND

複合代入演算子

複合代入演算子もキーワードエイリアスとして利用できます:

NoShift JS
or^-||=
and^-&&=
@or^-|=
@and^-&=
const a ^- true or false;\nconst b ^- 5 @and 3;\nlet c ^- null;\nc or^- ^2default^2;

コンパイル後:

const a = true || false;\nconst b = 5 & 3;\nlet c = null;\nc ||= "default";

⚠ 破壊的変更

v0.15.0 以降、構文が大幅に変更されました。^3#(private)に、^6 は大文字化(以前は &)に、^\\_(以前は |)に変更され、キーワードエイリアス(orand@or@and)が導入されました。.nsjs ファイルを更新してください。