goldstein 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/package.json +52 -0
- package/packages/goldstein/index.js +15 -0
- package/packages/keyword-fn/index.js +26 -0
- package/packages/keyword-guard/index.js +55 -0
- package/packages/operator/index.js +10 -0
- package/packages/parser/index.js +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) coderaiser
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Goldstein
|
|
2
|
+
|
|
3
|
+
JavaScript with no limits.
|
|
4
|
+
|
|
5
|
+
Language ruled by the users, create an issue with ideas of a new language construction and what is look like in JavaScript, and most likely we implement it :).
|
|
6
|
+
|
|
7
|
+
> *"You haven't a real appreciation of Newspeak, Winston,' he said almost sadly. 'Even when you write it you're still thinking in Oldspeak. I've read some of those pieces that you write in The Times occasionally. They're good enough, but they're translations. In your heart you'd prefer to stick to Oldspeak, with all its vagueness and its useless shades of meaning. You don't grasp the beauty of the destruction of words. Do you know that Newspeak is the only language in the world whose vocabulary gets smaller every year?"*
|
|
8
|
+
>
|
|
9
|
+
> *(c) “1984”, George Orwell*
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm i goldstein
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import {compile} from 'goldstein';
|
|
21
|
+
|
|
22
|
+
compile(`
|
|
23
|
+
fn hello() {
|
|
24
|
+
guard (text !== "world") else {
|
|
25
|
+
return ""
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return "Hello " + text
|
|
29
|
+
}
|
|
30
|
+
`);
|
|
31
|
+
// returns
|
|
32
|
+
`
|
|
33
|
+
function hello() {
|
|
34
|
+
if (!(text !== 'world')) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return 'Hello ' + text;
|
|
39
|
+
}
|
|
40
|
+
`
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Keywords
|
|
44
|
+
|
|
45
|
+
**Goldstein** is absolutely compatible with JavaScript, and it has extensions.
|
|
46
|
+
Here is the list.
|
|
47
|
+
|
|
48
|
+
### `fn`
|
|
49
|
+
|
|
50
|
+
You can use `fn` to declare a `function`:
|
|
51
|
+
|
|
52
|
+
```gs
|
|
53
|
+
fn hello() {
|
|
54
|
+
return 'world';
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
This is the same as:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
function hello() {
|
|
62
|
+
return 'world';
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### `guard`
|
|
67
|
+
|
|
68
|
+
Applies not to `IfCondition`:
|
|
69
|
+
|
|
70
|
+
```gs
|
|
71
|
+
fn hello() {
|
|
72
|
+
guard (text !== "world") else {
|
|
73
|
+
return ""
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return "Hello " + text
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Is the same as:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
function hello() {
|
|
84
|
+
if (!(text !== 'world')) {
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return 'Hello ' + text;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "goldstein",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
|
+
"description": "JavaScript with no limits",
|
|
7
|
+
"main": "./packages/goldstein/index.js",
|
|
8
|
+
"exports": "./packages/goldstein/index.js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/coderaiser/mock-import.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"JavaScript",
|
|
15
|
+
"parser",
|
|
16
|
+
"compiler"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "madrun test",
|
|
20
|
+
"coverage": "madrun coverage",
|
|
21
|
+
"lint": "madrun lint",
|
|
22
|
+
"fix:lint": "madrun fix:lint"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"acorn": "^8.7.1",
|
|
26
|
+
"putout": "^26.17.0"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@cloudcmd/stub": "^4.0.1",
|
|
31
|
+
"@types/acorn": "^4.0.6",
|
|
32
|
+
"c8": "^7.5.0",
|
|
33
|
+
"check-dts": "^0.6.3",
|
|
34
|
+
"escover": "^2.0.2",
|
|
35
|
+
"eslint": "^8.0.0-beta.1",
|
|
36
|
+
"eslint-plugin-node": "^11.0.0",
|
|
37
|
+
"eslint-plugin-putout": "^15.1.1",
|
|
38
|
+
"madrun": "^9.0.0",
|
|
39
|
+
"mock-require": "^3.0.3",
|
|
40
|
+
"nodemon": "^2.0.2",
|
|
41
|
+
"runsome": "^1.0.0",
|
|
42
|
+
"supertape": "^7.0.0",
|
|
43
|
+
"typescript": "^4.4.4",
|
|
44
|
+
"zenload": "^2.0.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=16"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {print} from 'putout';
|
|
2
|
+
import keywordFn from '../keyword-fn/index.js';
|
|
3
|
+
import keywordGuard from '../keyword-guard/index.js';
|
|
4
|
+
import {extendParser} from '../parser/index.js';
|
|
5
|
+
|
|
6
|
+
export const compile = (source) => {
|
|
7
|
+
const {parse} = extendParser([
|
|
8
|
+
keywordFn,
|
|
9
|
+
keywordGuard,
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const ast = parse(source);
|
|
13
|
+
|
|
14
|
+
return print(ast);
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addKeyword,
|
|
3
|
+
TokenType,
|
|
4
|
+
} from '../operator/index.js';
|
|
5
|
+
|
|
6
|
+
export default function fn(Parser) {
|
|
7
|
+
Parser.acorn.keywordTypes.fn = new TokenType('fn', {
|
|
8
|
+
keyword: 'fn',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return class extends Parser {
|
|
12
|
+
parse() {
|
|
13
|
+
this.keywords = addKeyword('fn', this.keywords);
|
|
14
|
+
|
|
15
|
+
return super.parse();
|
|
16
|
+
}
|
|
17
|
+
parseStatement(context, topLevel, exports) {
|
|
18
|
+
if (this.type === Parser.acorn.keywordTypes.fn) {
|
|
19
|
+
this.type = Parser.acorn.keywordTypes.function;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return super.parseStatement(context, topLevel, exports);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addKeyword,
|
|
3
|
+
TokenType,
|
|
4
|
+
tokTypes,
|
|
5
|
+
} from '../operator/index.js';
|
|
6
|
+
|
|
7
|
+
export default function newSpeak(Parser) {
|
|
8
|
+
const {keywordTypes} = Parser.acorn;
|
|
9
|
+
keywordTypes.guard = new TokenType('guard', {
|
|
10
|
+
keyword: 'guard',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return class extends Parser {
|
|
14
|
+
parse() {
|
|
15
|
+
this.keywords = addKeyword('guard', this.keywords);
|
|
16
|
+
return super.parse();
|
|
17
|
+
}
|
|
18
|
+
parseStatement(context, topLevel, exports) {
|
|
19
|
+
if (this.type === keywordTypes.guard) {
|
|
20
|
+
return this.parseGuard();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return super.parseStatement(context, topLevel, exports);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
parseGuard() {
|
|
27
|
+
super.next();
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
parenL,
|
|
31
|
+
parenR,
|
|
32
|
+
_else,
|
|
33
|
+
} = tokTypes;
|
|
34
|
+
|
|
35
|
+
const node = super.startNode();
|
|
36
|
+
super.expect(parenL);
|
|
37
|
+
|
|
38
|
+
node.test = {
|
|
39
|
+
type: 'UnaryExpression',
|
|
40
|
+
operator: '!',
|
|
41
|
+
prefix: true,
|
|
42
|
+
argument: super.parseExpression(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
super.expect(parenR);
|
|
46
|
+
super.expect(_else);
|
|
47
|
+
|
|
48
|
+
node.consequent = this.parseStatement();
|
|
49
|
+
node.alternate = null;
|
|
50
|
+
|
|
51
|
+
return super.finishNode(node, 'IfStatement');
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {Parser} from 'acorn';
|
|
2
|
+
|
|
3
|
+
export const extendParser = (keywords) => {
|
|
4
|
+
const parser = Parser.extend(
|
|
5
|
+
...keywords,
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
const parse = createParse(parser);
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
parse,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const createParse = (parser) => (a) => parser.parse(a, {
|
|
16
|
+
ecmaVersion: 'latest',
|
|
17
|
+
});
|