mirror of
https://github.com/pichsenmeister/WienerScript.git
synced 2024-11-04 22:09:57 +00:00
initial commit
This commit is contained in:
commit
a58243464d
7 changed files with 343 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
node_modules/
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
.vscode
|
||||
.vscode/*
|
||||
dist/
|
124
README.md
Normal file
124
README.md
Normal file
|
@ -0,0 +1,124 @@
|
|||
WienerScript
|
||||
==============
|
||||
|
||||
HACKL AMOI WOS calc(operator, left, right) {
|
||||
WOS IS MIT DIR (operator) {
|
||||
I SCHAU NUR '+':
|
||||
DRAH DI HAM left AUFI right
|
||||
I SCHAU NUR '-':
|
||||
DRAH DI HAM left OWI right
|
||||
I SCHAU NUR '*':
|
||||
DRAH DI HAM left HAUTS EICH ZAM right
|
||||
I SCHAU NUR '/':
|
||||
DRAH DI HAM left BRÖCKERL right
|
||||
NA GEH:
|
||||
GEH SCHEISSN ('invalid operator')
|
||||
}
|
||||
}
|
||||
|
||||
SCHAU MA MOL {
|
||||
I MAN JA NUR (calc('+', 1, 2))
|
||||
} LECK OASCH (err) {
|
||||
GSCHISSN GRISSN ('invalid operation')
|
||||
}
|
||||
|
||||
WienerScript adds syntactic sugar to JavaScript that makes it less forgiving, more emotional, and even painful to write, allowing you to do less with more code.
|
||||
|
||||
Common Viennese phrases and words act as intuitive replacements for common JavaScript keywords, operators, and more. You can continue to use raw JavaScript inside WienerScript, and the `wienerscript` transpiler will convert WienerScript code into raw JavaScript.
|
||||
|
||||
Installation
|
||||
----------------
|
||||
|
||||
WienerScript requires [Node.js and npm](https://nodejs.org/en/).
|
||||
|
||||
```
|
||||
npm install -g wienerscript
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```
|
||||
wienerscript
|
||||
```
|
||||
|
||||
All files in that directory (and any subdirectories) that have a valid WienerScript file extensions (`.ws`) will be replaced by the transpiled contents of in the `/dist` directory.
|
||||
Input files conventionally use the `.ws` extension and output files conventionally use the `.js` extension.s
|
||||
|
||||
Example Program
|
||||
----------------
|
||||
|
||||
An implementation of [FizzBuzz](http://c2.com/cgi/wiki?FizzBuzzTest) using a mix of ArnoldJS syntax and raw JavaScript:
|
||||
|
||||
LET'S KICK SOME ICE
|
||||
GIVE THESE PEOPLE AIR
|
||||
YOU SET US UP n STICK AROUND 1;
|
||||
n <= 100;
|
||||
n STICK AROUND n GET UP 1
|
||||
ENOUGH TALK
|
||||
IT'S SHOWTIME
|
||||
YOU SET US UP out STICK AROUND ;
|
||||
BECAUSE I'M GOING TO SAY PLEASE
|
||||
(I LIED (n I LET HIM GO 3))
|
||||
out STICK AROUND out GET UP Fizz;
|
||||
BECAUSE I'M GOING TO SAY PLEASE
|
||||
(I LIED (n I LET HIM GO 5))
|
||||
out STICK AROUND out GET UP Buzz;
|
||||
TALK TO THE HAND (out
|
||||
WHAT'S WRONG WITH YOUR EYES out
|
||||
I NOW KNOW WHY YOU CRY n);
|
||||
HASTA LA VISTA BABY
|
||||
|
||||
This program can be found in `samples/fizzbuzz.ajs`. Its transpiled version can be found in `samples/fizzbuzz.js`.
|
||||
Additional examples can be found in the `samples` directory.
|
||||
|
||||
Usage
|
||||
|
||||
| WienerScript | JavaScript |
|
||||
| ----- | ----- |
|
||||
| FIX OIDA | const |
|
||||
| OIDA | let |
|
||||
| ALSO DES IS AMOI NIX | null |
|
||||
| HAWIDERE | new |
|
||||
| I BIMS | this |
|
||||
| HACKL AMOI WOS | function |
|
||||
| DRAH DI HAM | return |
|
||||
| WAS WÜSTN | if |
|
||||
| WOA NUA A SCHMÄH | else if |
|
||||
| AH SCHO WUASCHT | else |
|
||||
| for | for |
|
||||
| DAMMA WOS | do |
|
||||
| GEMMA | while |
|
||||
| GUSCH | continue |
|
||||
| in | in |
|
||||
| WOS IS MIT DIR | switch |
|
||||
| I SCHAU NUR | case |
|
||||
| PASST SCHO | break |
|
||||
| NA GEH | default |
|
||||
| GEH SCHEISSN | throw |
|
||||
| SCHAU MA MOL | try |
|
||||
| LECK OASCH | catch |
|
||||
| SAMMAS ENDLICH | finally |
|
||||
| SCHLEICH DI | delete |
|
||||
| SICHA NET | false |
|
||||
| NA NO NA NET | true |
|
||||
| instanceOf | instanceof |
|
||||
| typeof | typeof |
|
||||
| JO GLEI | await |
|
||||
| OWIZAHRER | async |
|
||||
| I MAN JA NUR | console.log |
|
||||
| DO IS DA HUND BEGROBN | console.debug |
|
||||
| GSCHISSN GRISSN | console.error |
|
||||
| DES IS MA ECHT Z'DEPPAT | process.exit |
|
||||
| KANNST DA VUASTÖHN | === |
|
||||
| DES GEHT SI SCHO AUS | == |
|
||||
| && | && |
|
||||
| GHUPFT WIE GHATSCHT | || |
|
||||
| WENNST MANST | = |
|
||||
| AUFI | + |
|
||||
| OWI | - |
|
||||
| HAUTS EICH ZAM | * |
|
||||
| BRÖCKERL | / |
|
||||
| S'RESTL | % |
|
||||
| JO EH | ! |
|
||||
| HOST MI | ? |
|
||||
| DANN HOIT NET | : |
|
22
examples/calculator.ws
Normal file
22
examples/calculator.ws
Normal file
|
@ -0,0 +1,22 @@
|
|||
HACKL AMOI WOS calc(operator, left, right) {
|
||||
WOS IS MIT DIR (operator) {
|
||||
I SCHAU NUR '+':
|
||||
DRAH DI HAM left AUFI right
|
||||
I SCHAU NUR '-':
|
||||
DRAH DI HAM left OWI right
|
||||
I SCHAU NUR '*':
|
||||
DRAH DI HAM left HAUTS EICH ZAM right
|
||||
I SCHAU NUR '/':
|
||||
DRAH DI HAM left BRÖCKERL right
|
||||
NA GEH:
|
||||
GEH SCHEISSN ('invalid operator')
|
||||
}
|
||||
|
||||
DRAH DI HAM sum
|
||||
}
|
||||
|
||||
SCHAU MA MOL {
|
||||
I MAN JA NUR (calc('+', 1, 2))
|
||||
} LECK OASCH (err) {
|
||||
GSCHISSN GRISSN ('invalid operation')
|
||||
}
|
37
index.js
Normal file
37
index.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const glob = require('glob')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const mkdirp = require('mkdirp')
|
||||
const prettier = require('prettier')
|
||||
|
||||
// options is optional
|
||||
const getFiles = () => {
|
||||
return glob.sync("**/*.ws")
|
||||
}
|
||||
|
||||
const compile = (content) => {
|
||||
const keywords = JSON.parse(fs.readFileSync('keywords.json', 'utf8'))
|
||||
for (const key in keywords) {
|
||||
content = content.replace(new RegExp(key, "g"), keywords[key]);
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
const run = () => {
|
||||
const files = getFiles()
|
||||
files.forEach(file => {
|
||||
const content = fs.readFileSync(path.normalize(path.join(__dirname, file)), 'utf8')
|
||||
const dir = path.join(__dirname, 'dist')
|
||||
if (!fs.existsSync(dir)) fs.mkdirSync(dir)
|
||||
|
||||
const dirs = file.substring(0, file.lastIndexOf(path.sep))
|
||||
mkdirp.sync(path.join(__dirname, 'dist', dirs))
|
||||
|
||||
const filePath = path.join(__dirname, 'dist', file.replace('.ws', '.js'))
|
||||
fs.writeFileSync(filePath, prettier.format(compile(content), { parser: 'babel' }), (error) => console.error(error))
|
||||
})
|
||||
}
|
||||
|
||||
run()
|
49
keywords.json
Normal file
49
keywords.json
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"FIX OIDA": "const",
|
||||
"OIDA": "let",
|
||||
"ALSO DES IS AMOI NIX": "null",
|
||||
"HAWIDERE": "new",
|
||||
"I BIMS": "this",
|
||||
"HACKL AMOI WOS": "function",
|
||||
"DRAH DI HAM": "return",
|
||||
"WAS WÜSTN": "if",
|
||||
"WOA NUA A SCHMÄH": "else if",
|
||||
"AH SCHO WUASCHT": "else",
|
||||
"for": "for",
|
||||
"DAMMA WOS": "do",
|
||||
"GEMMA": "while",
|
||||
"GUSCH": "continue",
|
||||
"in": "in",
|
||||
"WOS IS MIT DIR": "switch",
|
||||
"I SCHAU NUR": "case",
|
||||
"PASST SCHO": "break",
|
||||
"NA GEH": "default",
|
||||
"GEH SCHEISSN": "throw",
|
||||
"SCHAU MA MOL": "try",
|
||||
"LECK OASCH": "catch",
|
||||
"SAMMAS ENDLICH": "finally",
|
||||
"SCHLEICH DI": "delete",
|
||||
"SICHA NET": "false",
|
||||
"NA NO NA NET": "true",
|
||||
"instanceOf": "instanceof",
|
||||
"typeof": "typeof",
|
||||
"JO GLEI": "await",
|
||||
"OWIZAHRER": "async",
|
||||
"I MAN JA NUR": "console.log",
|
||||
"DO IS DA HUND BEGROBN": "console.debug",
|
||||
"GSCHISSN GRISSN": "console.error",
|
||||
"DES IS MA ECHT Z'DEPPAT": "process.exit",
|
||||
"KANNST DA VUASTÖHN": "===",
|
||||
"DES GEHT SI SCHO AUS": "==",
|
||||
"&&": "&&",
|
||||
"GHUPFT WIE GHATSCHT": "||",
|
||||
"WENNST MANST": "=",
|
||||
"AUFI": "+",
|
||||
"OWI": "-",
|
||||
"HAUTS EICH ZAM": "*",
|
||||
"BRÖCKERL": "/",
|
||||
"S'RESTL": "%",
|
||||
"JO EH": "!",
|
||||
"HOST MI": "?",
|
||||
"DANN HOIT NET": ":"
|
||||
}
|
20
package.json
Normal file
20
package.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "wienerscript",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "./index.js",
|
||||
"bin": {
|
||||
"wienerscript": "./index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"author": "David Pichsenmeister",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"glob": "^7.1.6",
|
||||
"mkdirp": "^1.0.4",
|
||||
"prettier": "^2.0.5"
|
||||
}
|
||||
}
|
85
yarn.lock
Normal file
85
yarn.lock
Normal file
|
@ -0,0 +1,85 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
balanced-match@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
||||
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
|
||||
|
||||
brace-expansion@^1.1.7:
|
||||
version "1.1.11"
|
||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
|
||||
dependencies:
|
||||
balanced-match "^1.0.0"
|
||||
concat-map "0.0.1"
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
|
||||
|
||||
fs.realpath@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
|
||||
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
|
||||
|
||||
glob@^7.1.6:
|
||||
version "7.1.6"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
|
||||
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
inflight "^1.0.4"
|
||||
inherits "2"
|
||||
minimatch "^3.0.4"
|
||||
once "^1.3.0"
|
||||
path-is-absolute "^1.0.0"
|
||||
|
||||
inflight@^1.0.4:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
|
||||
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
|
||||
dependencies:
|
||||
once "^1.3.0"
|
||||
wrappy "1"
|
||||
|
||||
inherits@2:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
|
||||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
|
||||
|
||||
minimatch@^3.0.4:
|
||||
version "3.0.4"
|
||||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
|
||||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
|
||||
dependencies:
|
||||
brace-expansion "^1.1.7"
|
||||
|
||||
mkdirp@^1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
|
||||
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
|
||||
|
||||
once@^1.3.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
|
||||
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
|
||||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
path-is-absolute@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
|
||||
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
|
||||
|
||||
prettier@^2.0.5:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
|
||||
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
|
||||
|
||||
wrappy@1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
Loading…
Reference in a new issue