drakongen 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/.vscode/launch.json +18 -0
- package/LICENSE +24 -0
- package/README.md +80 -0
- package/browser/drakongen.js +1303 -0
- package/browsertest.html +84 -0
- package/buildbrowser +4 -0
- package/buildexamples.js +61 -0
- package/examples/00.Empty.drakon +1 -0
- package/examples/00.Empty.txt +5 -0
- package/examples/01. /320/221/320/265/320/273/321/213/320/270/314/206.drakon" +13 -0
- package/examples/01. /320/221/320/265/320/273/321/213/320/271.json" +16 -0
- package/examples/01. /320/221/320/265/320/273/321/213/320/271.txt" +4 -0
- package/examples/02. /320/247/320/265/314/210/321/200/320/275/321/213/320/270/314/206.drakon" +28 -0
- package/examples/02. /320/247/321/221/321/200/320/275/321/213/320/271.json" +31 -0
- package/examples/02. /320/247/321/221/321/200/320/275/321/213/320/271.txt" +10 -0
- package/examples/03. /320/241/320/265/321/200/321/213/320/270/314/206.drakon" +20 -0
- package/examples/03. /320/241/320/265/321/200/321/213/320/271.json" +23 -0
- package/examples/03. /320/241/320/265/321/200/321/213/320/271.txt" +6 -0
- package/examples/04. /320/221/321/203/321/200/321/213/320/270/314/206.drakon" +25 -0
- package/examples/04. /320/221/321/203/321/200/321/213/320/271.json" +29 -0
- package/examples/04. /320/221/321/203/321/200/321/213/320/271.txt" +7 -0
- package/examples/05. /320/226/320/265/314/210/320/273/321/202/321/213/320/270/314/206.drakon" +25 -0
- package/examples/05. /320/226/321/221/320/273/321/202/321/213/320/271.json" +29 -0
- package/examples/05. /320/226/321/221/320/273/321/202/321/213/320/271.txt" +7 -0
- package/examples/06. /320/221/320/260/320/263/321/200/320/276/320/262/321/213/320/270/314/206.drakon" +30 -0
- package/examples/06. /320/221/320/260/320/263/321/200/320/276/320/262/321/213/320/271.json" +35 -0
- package/examples/06. /320/221/320/260/320/263/321/200/320/276/320/262/321/213/320/271.txt" +10 -0
- package/examples/07. /320/244/320/270/320/276/320/273/320/265/321/202/320/276/320/262/321/213/320/270/314/206.drakon" +42 -0
- package/examples/07. /320/244/320/270/320/276/320/273/320/265/321/202/320/276/320/262/321/213/320/271.json" +49 -0
- package/examples/07. /320/244/320/270/320/276/320/273/320/265/321/202/320/276/320/262/321/213/320/271.txt" +14 -0
- package/examples/08. /320/221/320/270/321/200/321/216/320/267/320/276/320/262/321/213/320/270/314/206.drakon" +27 -0
- package/examples/08. /320/221/320/270/321/200/321/216/320/267/320/276/320/262/321/213/320/271.json" +27 -0
- package/examples/08. /320/221/320/270/321/200/321/216/320/267/320/276/320/262/321/213/320/271.txt" +6 -0
- package/examples/09. /320/236/321/200/320/260/320/275/320/266/320/265/320/262/321/213/320/270/314/206.drakon" +37 -0
- package/examples/09. /320/236/321/200/320/260/320/275/320/266/320/265/320/262/321/213/320/271.json" +39 -0
- package/examples/09. /320/236/321/200/320/260/320/275/320/266/320/265/320/262/321/213/320/271.txt" +10 -0
- package/examples/10. /320/240/320/276/320/267/320/276/320/262/321/213/320/270/314/206.drakon" +42 -0
- package/examples/10. /320/240/320/276/320/267/320/276/320/262/321/213/320/271.json" +54 -0
- package/examples/10. /320/240/320/276/320/267/320/276/320/262/321/213/320/271.txt" +16 -0
- package/examples/11. /320/227/320/260/321/211/320/270/321/202/320/275/321/213/320/270/314/206.drakon" +37 -0
- package/examples/11. /320/227/320/260/321/211/320/270/321/202/320/275/321/213/320/271.json" +39 -0
- package/examples/11. /320/227/320/260/321/211/320/270/321/202/320/275/321/213/320/271.txt" +10 -0
- package/examples/12. /320/221/320/276/320/273/320/276/321/202/320/275/321/213/320/270/314/206.drakon" +44 -0
- package/examples/12. /320/221/320/276/320/273/320/276/321/202/320/275/321/213/320/271.json" +43 -0
- package/examples/12. /320/221/320/276/320/273/320/276/321/202/320/275/321/213/320/271.txt" +10 -0
- package/examples/13. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/270/314/206.drakon" +54 -0
- package/examples/13. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/271.json" +63 -0
- package/examples/13. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/271.txt" +18 -0
- package/examples/14. /320/227/320/276/320/273/320/276/321/202/320/276/320/270/314/206.drakon" +64 -0
- package/examples/14. /320/227/320/276/320/273/320/276/321/202/320/276/320/271.json" +73 -0
- package/examples/14. /320/227/320/276/320/273/320/276/321/202/320/276/320/271.txt" +22 -0
- package/examples/15. /320/241/320/270/320/275/320/270/320/270/314/206.drakon" +54 -0
- package/examples/15. /320/241/320/270/320/275/320/270/320/271.json" +87 -0
- package/examples/15. /320/241/320/270/320/275/320/270/320/271.txt" +26 -0
- package/examples/16. /320/223/320/276/320/273/321/203/320/261/320/276/320/270/314/206.drakon" +37 -0
- package/examples/16. /320/223/320/276/320/273/321/203/320/261/320/276/320/271.json" +48 -0
- package/examples/16. /320/223/320/276/320/273/321/203/320/261/320/276/320/271.txt" +13 -0
- package/examples/17. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/270/314/206.drakon" +39 -0
- package/examples/17. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/271.json" +41 -0
- package/examples/17. /320/241/320/260/320/273/320/260/321/202/320/276/320/262/321/213/320/271.txt" +10 -0
- package/examples/18. /320/241/321/202/320/260/320/273/321/214/320/275/320/276/320/270/314/206.drakon" +49 -0
- package/examples/18. /320/241/321/202/320/260/320/273/321/214/320/275/320/276/320/271.json" +67 -0
- package/examples/18. /320/241/321/202/320/260/320/273/321/214/320/275/320/276/320/271.txt" +19 -0
- package/examples/19. Lilla.drakon +39 -0
- package/examples/19. Lilla.json +45 -0
- package/examples/19. Lilla.txt +11 -0
- package/examples/Adaptive design.drakon +116 -0
- package/examples/Adaptive design.json +153 -0
- package/examples/Adaptive design.txt +47 -0
- package/examples/And test.drakon +46 -0
- package/examples/And test.json +46 -0
- package/examples/And test.txt +10 -0
- package/examples/Arrow - double exit.drakon +41 -0
- package/examples/Arrow - double exit.json +62 -0
- package/examples/Arrow - double exit.txt +14 -0
- package/examples/Complex arrow.drakon +93 -0
- package/examples/Complex arrow.json +162 -0
- package/examples/Complex arrow.txt +43 -0
- package/examples/DoubleArrow.drakon +53 -0
- package/examples/DoubleArrow.json +86 -0
- package/examples/DoubleArrow.txt +18 -0
- package/examples/Find pointing nodes.drakon +104 -0
- package/examples/Find pointing nodes.json +137 -0
- package/examples/Find pointing nodes.txt +29 -0
- package/examples/How to tune PID on a quadcopter.drakon +488 -0
- package/examples/How to tune PID on a quadcopter.json +734 -0
- package/examples/How to tune PID on a quadcopter.txt +169 -0
- package/examples/Or test.drakon +47 -0
- package/examples/Or test.json +46 -0
- package/examples/Or test.txt +10 -0
- package/examples/Silhouette test 1.drakon +47 -0
- package/examples/Silhouette test 1.json +82 -0
- package/examples/Silhouette test 1.txt +24 -0
- package/examples/Work out action-check.drakon +30 -0
- package/examples/Work out action-check.json +45 -0
- package/examples/Work out action-check.txt +9 -0
- package/examples/Workout foreach.drakon +63 -0
- package/examples/Workout foreach.json +62 -0
- package/examples/Workout foreach.txt +14 -0
- package/examples/ar01.drakon +25 -0
- package/examples/ar01.json +40 -0
- package/examples/ar01.txt +7 -0
- package/examples/ar02.drakon +30 -0
- package/examples/ar02.json +45 -0
- package/examples/ar02.txt +10 -0
- package/examples/ar03.drakon +32 -0
- package/examples/ar03.json +44 -0
- package/examples/ar03.txt +7 -0
- package/examples/ar04.drakon +37 -0
- package/examples/ar04.json +49 -0
- package/examples/ar04.txt +10 -0
- package/examples/ar05.drakon +37 -0
- package/examples/ar05.json +59 -0
- package/examples/ar05.txt +11 -0
- package/examples/ar06.drakon +40 -0
- package/examples/ar06.json +70 -0
- package/examples/ar06.txt +13 -0
- package/examples/ar07.drakon +40 -0
- package/examples/ar07.json +70 -0
- package/examples/ar07.txt +13 -0
- package/examples/ar08.drakon +47 -0
- package/examples/ar08.json +81 -0
- package/examples/ar08.txt +16 -0
- package/examples/ar09.drakon +52 -0
- package/examples/ar09.json +87 -0
- package/examples/ar09.txt +17 -0
- package/examples/ar10.drakon +52 -0
- package/examples/ar10.json +88 -0
- package/examples/ar10.txt +18 -0
- package/examples/ar11.drakon +47 -0
- package/examples/ar11.json +82 -0
- package/examples/ar11.txt +17 -0
- package/examples/ar12.drakon +37 -0
- package/examples/ar12.json +49 -0
- package/examples/ar12.txt +10 -0
- package/examples/getToken.drakon +76 -0
- package/examples/getToken.json +88 -0
- package/examples/getToken.txt +41 -0
- package/examples/tmp.drakon +49 -0
- package/examples/tmp.json +82 -0
- package/examples/tmp.txt +37 -0
- package/package.json +21 -0
- package/prompts/drakonToPrompt.txt +139 -0
- package/prompts/index.txt +17 -0
- package/prompts/printPseudo.txt +116 -0
- package/src/browserTools.js +39 -0
- package/src/drakonToPromptStruct.js +44 -0
- package/src/drakonToStruct.js +416 -0
- package/src/drakongen.js +16 -0
- package/src/index.js +17 -0
- package/src/main.js +157 -0
- package/src/nodeTools.js +38 -0
- package/src/printPseudo.js +167 -0
- package/src/structFlow.js +382 -0
- package/src/technicalTree.js +84 -0
- package/src/tools.js +36 -0
- package/src/translate.js +108 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ar12",
|
|
3
|
+
"params": "",
|
|
4
|
+
"branches": [
|
|
5
|
+
{
|
|
6
|
+
"branchId": 0,
|
|
7
|
+
"start": "74",
|
|
8
|
+
"body": [
|
|
9
|
+
{
|
|
10
|
+
"id": "74",
|
|
11
|
+
"type": "loop",
|
|
12
|
+
"content": "",
|
|
13
|
+
"body": [
|
|
14
|
+
{
|
|
15
|
+
"type": "question",
|
|
16
|
+
"id": "4",
|
|
17
|
+
"content": {
|
|
18
|
+
"operator": "or",
|
|
19
|
+
"left": "3",
|
|
20
|
+
"right": "5"
|
|
21
|
+
},
|
|
22
|
+
"yes": [
|
|
23
|
+
{
|
|
24
|
+
"type": "break"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"no": [
|
|
28
|
+
{
|
|
29
|
+
"id": "68",
|
|
30
|
+
"type": "action",
|
|
31
|
+
"content": "4"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "arrow-stub-74",
|
|
35
|
+
"type": "loopend",
|
|
36
|
+
"start": "74"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "2",
|
|
44
|
+
"type": "end"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"items": {
|
|
3
|
+
"1": {
|
|
4
|
+
"type": "end"
|
|
5
|
+
},
|
|
6
|
+
"2": {
|
|
7
|
+
"type": "branch",
|
|
8
|
+
"branchId": 0,
|
|
9
|
+
"one": "3"
|
|
10
|
+
},
|
|
11
|
+
"3": {
|
|
12
|
+
"type": "action",
|
|
13
|
+
"content": "<p>Find an existing connection in context.connections by URL</p>",
|
|
14
|
+
"one": "4"
|
|
15
|
+
},
|
|
16
|
+
"4": {
|
|
17
|
+
"type": "question",
|
|
18
|
+
"content": "<p>Connection found?</p>",
|
|
19
|
+
"one": "13",
|
|
20
|
+
"two": "6",
|
|
21
|
+
"flag1": 1
|
|
22
|
+
},
|
|
23
|
+
"5": {
|
|
24
|
+
"type": "action",
|
|
25
|
+
"content": "<p>Try to get an access token using the connection in non-interactive mode.</p>",
|
|
26
|
+
"one": "8"
|
|
27
|
+
},
|
|
28
|
+
"6": {
|
|
29
|
+
"type": "action",
|
|
30
|
+
"content": "<p>Create a new MSAL connection object.</p><p>Use the following information to initialize the object:</p><ul><li>context.config.redirectUri is the redirect URI</li><li>context.config.authority is the authority</li><li>context.config.clientId is the client id</li></ul>",
|
|
31
|
+
"one": "7"
|
|
32
|
+
},
|
|
33
|
+
"7": {
|
|
34
|
+
"type": "action",
|
|
35
|
+
"content": "<p>Put the connection in context.connections using the URL as the key.</p>",
|
|
36
|
+
"one": "5"
|
|
37
|
+
},
|
|
38
|
+
"8": {
|
|
39
|
+
"type": "question",
|
|
40
|
+
"content": "<p>Got exception?</p>",
|
|
41
|
+
"one": "12",
|
|
42
|
+
"two": "9",
|
|
43
|
+
"flag1": 0
|
|
44
|
+
},
|
|
45
|
+
"9": {
|
|
46
|
+
"type": "action",
|
|
47
|
+
"content": "<p>Get a token in interactive mode.</p>",
|
|
48
|
+
"one": "10"
|
|
49
|
+
},
|
|
50
|
+
"10": {
|
|
51
|
+
"type": "question",
|
|
52
|
+
"content": "<p>Did the user cancel the logon?</p>",
|
|
53
|
+
"one": "12",
|
|
54
|
+
"two": "11",
|
|
55
|
+
"flag1": 0
|
|
56
|
+
},
|
|
57
|
+
"11": {
|
|
58
|
+
"type": "action",
|
|
59
|
+
"content": "<p>Return an empty string</p>",
|
|
60
|
+
"one": "1"
|
|
61
|
+
},
|
|
62
|
+
"12": {
|
|
63
|
+
"type": "action",
|
|
64
|
+
"content": "<p>Return the access token</p>",
|
|
65
|
+
"one": "1"
|
|
66
|
+
},
|
|
67
|
+
"13": {
|
|
68
|
+
"type": "comment",
|
|
69
|
+
"content": "<p>Some comment</p>",
|
|
70
|
+
"one": "5"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"params": "<p>Obtains an access token. Connects to the dataverse if necessary.</p><p>Returns a JWT token as a string.</p><p>An empty return value means the user has cancelled the logon.</p><p><br /></p><p>Parameters:</p><ul><li>context: ServerContext</li><li>url: a string with the address of the dataverse instance</li></ul>",
|
|
74
|
+
"type": "drakon",
|
|
75
|
+
"id": "getToken.drakon"
|
|
76
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "getToken",
|
|
3
|
+
"params": "<p>Obtains an access token. Connects to the dataverse if necessary.</p><p>Returns a JWT token as a string.</p><p>An empty return value means the user has cancelled the logon.</p><p><br /></p><p>Parameters:</p><ul><li>context: ServerContext</li><li>url: a string with the address of the dataverse instance</li></ul>",
|
|
4
|
+
"branches": [
|
|
5
|
+
{
|
|
6
|
+
"branchId": 0,
|
|
7
|
+
"start": "3",
|
|
8
|
+
"body": [
|
|
9
|
+
{
|
|
10
|
+
"id": "3",
|
|
11
|
+
"type": "action",
|
|
12
|
+
"content": "<p>Find an existing connection in context.connections by URL</p>"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"type": "question",
|
|
16
|
+
"id": "4",
|
|
17
|
+
"content": "<p>Connection found?</p>",
|
|
18
|
+
"yes": [
|
|
19
|
+
{
|
|
20
|
+
"id": "13",
|
|
21
|
+
"type": "comment",
|
|
22
|
+
"content": "<p>Some comment</p>"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"no": [
|
|
26
|
+
{
|
|
27
|
+
"id": "6",
|
|
28
|
+
"type": "action",
|
|
29
|
+
"content": "<p>Create a new MSAL connection object.</p><p>Use the following information to initialize the object:</p><ul><li>context.config.redirectUri is the redirect URI</li><li>context.config.authority is the authority</li><li>context.config.clientId is the client id</li></ul>"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "7",
|
|
33
|
+
"type": "action",
|
|
34
|
+
"content": "<p>Put the connection in context.connections using the URL as the key.</p>"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "5",
|
|
40
|
+
"type": "action",
|
|
41
|
+
"content": "<p>Try to get an access token using the connection in non-interactive mode.</p>"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"type": "question",
|
|
45
|
+
"id": "8",
|
|
46
|
+
"content": "<p>Got exception?</p>",
|
|
47
|
+
"yes": [
|
|
48
|
+
{
|
|
49
|
+
"id": "9",
|
|
50
|
+
"type": "action",
|
|
51
|
+
"content": "<p>Get a token in interactive mode.</p>"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"type": "question",
|
|
55
|
+
"id": "10",
|
|
56
|
+
"content": "<p>Did the user cancel the logon?</p>",
|
|
57
|
+
"yes": [
|
|
58
|
+
{
|
|
59
|
+
"id": "11",
|
|
60
|
+
"type": "action",
|
|
61
|
+
"content": "<p>Return an empty string</p>"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"no": [
|
|
65
|
+
{
|
|
66
|
+
"id": "12",
|
|
67
|
+
"type": "action",
|
|
68
|
+
"content": "<p>Return the access token</p>"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"no": [
|
|
74
|
+
{
|
|
75
|
+
"id": "12",
|
|
76
|
+
"type": "action",
|
|
77
|
+
"content": "<p>Return the access token</p>"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "1",
|
|
83
|
+
"type": "end"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Obtains an access token. Connects to the dataverse if necessary.
|
|
2
|
+
Returns a JWT token as a string.
|
|
3
|
+
An empty return value means the user has cancelled the logon.
|
|
4
|
+
|
|
5
|
+
Parameters:
|
|
6
|
+
|
|
7
|
+
- context: ServerContext
|
|
8
|
+
- url: a string with the address of the dataverse instance
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Procedure "getToken"
|
|
12
|
+
|
|
13
|
+
Algorithm:
|
|
14
|
+
Find an existing connection in context.connections by URL
|
|
15
|
+
|
|
16
|
+
If not (Connection found?)
|
|
17
|
+
Create a new MSAL connection object.
|
|
18
|
+
Use the following information to initialize the object:
|
|
19
|
+
|
|
20
|
+
- context.config.redirectUri is the redirect URI
|
|
21
|
+
- context.config.authority is the authority
|
|
22
|
+
- context.config.clientId is the client id
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Put the connection in context.connections using the URL as the key.
|
|
26
|
+
|
|
27
|
+
Try to get an access token using the connection in non-interactive mode.
|
|
28
|
+
|
|
29
|
+
If Got exception?
|
|
30
|
+
Get a token in interactive mode.
|
|
31
|
+
|
|
32
|
+
If Did the user cancel the logon?
|
|
33
|
+
Return an empty string
|
|
34
|
+
|
|
35
|
+
Else
|
|
36
|
+
Return the access token
|
|
37
|
+
|
|
38
|
+
Else
|
|
39
|
+
Return the access token
|
|
40
|
+
|
|
41
|
+
End of procedure
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"items": {
|
|
3
|
+
"1": {
|
|
4
|
+
"type": "end"
|
|
5
|
+
},
|
|
6
|
+
"2": {
|
|
7
|
+
"type": "branch",
|
|
8
|
+
"branchId": 1,
|
|
9
|
+
"one": "5",
|
|
10
|
+
"content": "Branch1"
|
|
11
|
+
},
|
|
12
|
+
"3": {
|
|
13
|
+
"type": "branch",
|
|
14
|
+
"content": "Exit",
|
|
15
|
+
"one": "1",
|
|
16
|
+
"branchId": 3
|
|
17
|
+
},
|
|
18
|
+
"4": {
|
|
19
|
+
"type": "branch",
|
|
20
|
+
"content": "Branch2",
|
|
21
|
+
"one": "6",
|
|
22
|
+
"branchId": 2
|
|
23
|
+
},
|
|
24
|
+
"5": {
|
|
25
|
+
"type": "question",
|
|
26
|
+
"content": "<p>AAAAAAA</p>",
|
|
27
|
+
"one": "4",
|
|
28
|
+
"two": "3",
|
|
29
|
+
"flag1": 1
|
|
30
|
+
},
|
|
31
|
+
"6": {
|
|
32
|
+
"type": "question",
|
|
33
|
+
"content": "<p>BBBB</p>",
|
|
34
|
+
"one": "7",
|
|
35
|
+
"two": "3",
|
|
36
|
+
"flag1": 1
|
|
37
|
+
},
|
|
38
|
+
"7": {
|
|
39
|
+
"type": "action",
|
|
40
|
+
"content": "<p>CCCC</p>",
|
|
41
|
+
"one": "3"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"type": "drakon",
|
|
45
|
+
"style": "{\"maxWidth\":160}",
|
|
46
|
+
"id": "tmp.drakon",
|
|
47
|
+
"params": "<p>It's a nice function</p><p><br /></p><p>Parameters:</p><ul><li>hello</li><li>bye</li><li>foo</li></ul>",
|
|
48
|
+
"description": "<p>line one</p><p>line two</p><p>line three</p>"
|
|
49
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tmp",
|
|
3
|
+
"params": "<p>It's a nice function</p><p><br /></p><p>Parameters:</p><ul><li>hello</li><li>bye</li><li>foo</li></ul>",
|
|
4
|
+
"branches": [
|
|
5
|
+
{
|
|
6
|
+
"name": "Branch1",
|
|
7
|
+
"branchId": 1,
|
|
8
|
+
"start": "5",
|
|
9
|
+
"body": [
|
|
10
|
+
{
|
|
11
|
+
"type": "question",
|
|
12
|
+
"id": "5",
|
|
13
|
+
"content": "<p>AAAAAAA</p>",
|
|
14
|
+
"yes": [
|
|
15
|
+
{
|
|
16
|
+
"id": "ad-1000",
|
|
17
|
+
"type": "address",
|
|
18
|
+
"content": "Branch2"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"no": [
|
|
22
|
+
{
|
|
23
|
+
"id": "ad-1001",
|
|
24
|
+
"type": "address",
|
|
25
|
+
"content": "Exit"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "2-end",
|
|
31
|
+
"type": "end"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "Branch2",
|
|
37
|
+
"branchId": 2,
|
|
38
|
+
"start": "6",
|
|
39
|
+
"body": [
|
|
40
|
+
{
|
|
41
|
+
"type": "question",
|
|
42
|
+
"id": "6",
|
|
43
|
+
"content": "<p>BBBB</p>",
|
|
44
|
+
"yes": [
|
|
45
|
+
{
|
|
46
|
+
"id": "7",
|
|
47
|
+
"type": "action",
|
|
48
|
+
"content": "<p>CCCC</p>"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "ad-1002",
|
|
52
|
+
"type": "address",
|
|
53
|
+
"content": "Exit"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"no": [
|
|
57
|
+
{
|
|
58
|
+
"id": "ad-1002",
|
|
59
|
+
"type": "address",
|
|
60
|
+
"content": "Exit"
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "4-end",
|
|
66
|
+
"type": "end"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "Exit",
|
|
72
|
+
"branchId": 3,
|
|
73
|
+
"start": "1",
|
|
74
|
+
"body": [
|
|
75
|
+
{
|
|
76
|
+
"id": "1",
|
|
77
|
+
"type": "end"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
package/examples/tmp.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
It's a nice function
|
|
2
|
+
|
|
3
|
+
Parameters:
|
|
4
|
+
|
|
5
|
+
- hello
|
|
6
|
+
- bye
|
|
7
|
+
- foo
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Procedure "tmp"
|
|
11
|
+
|
|
12
|
+
Algorithm:
|
|
13
|
+
Call subroutine: "Branch1"
|
|
14
|
+
|
|
15
|
+
Subroutine: "Branch1"
|
|
16
|
+
If AAAAAAA
|
|
17
|
+
Call subroutine "Branch2"
|
|
18
|
+
Else
|
|
19
|
+
Call subroutine "Exit"
|
|
20
|
+
End of subroutine
|
|
21
|
+
|
|
22
|
+
Subroutine: "Branch2"
|
|
23
|
+
If BBBB
|
|
24
|
+
CCCC
|
|
25
|
+
|
|
26
|
+
Call subroutine "Exit"
|
|
27
|
+
Else
|
|
28
|
+
Call subroutine "Exit"
|
|
29
|
+
End of subroutine
|
|
30
|
+
|
|
31
|
+
Subroutine: "Exit"
|
|
32
|
+
End of subroutine
|
|
33
|
+
End of procedure
|
|
34
|
+
|
|
35
|
+
line one
|
|
36
|
+
line two
|
|
37
|
+
line three
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "drakongen",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generates pseudocode and AST from drakon flowcharts built with DrakonWidget or DrakonHub.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"drakongen": "./src/main.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/stepan-mitkin/drakongen.git"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"author": "Stepan Mitkin",
|
|
17
|
+
"license": "UNLICENSED",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"node-html-parser": "^6.1.13"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Write a JavaScript module in CommonJs format that impements function drakonToPrompt.
|
|
2
|
+
Export the function.
|
|
3
|
+
|
|
4
|
+
The function arguments:
|
|
5
|
+
|
|
6
|
+
- drakonJson: a JSON string that contains a drakon-graph.
|
|
7
|
+
- filename: the full filename where drakonJson was read from.
|
|
8
|
+
|
|
9
|
+
The function returns a textual representation of the drakon-graph.
|
|
10
|
+
|
|
11
|
+
Here is the structure of the drakon-graph.
|
|
12
|
+
|
|
13
|
+
The "items" property contains a map. The keys are node ids. The values are nodes themselves.
|
|
14
|
+
The first node is the one that has its "type" property equal to "branch" with the lowest "branchId".
|
|
15
|
+
|
|
16
|
+
The function's algorithm:
|
|
17
|
+
|
|
18
|
+
- Parse the JSON in drakonJson. If there is an error, add the filename to the description.
|
|
19
|
+
- Start with an empty output list of strings.
|
|
20
|
+
- Add a string: Procedure "<name>". The <name> is the base filename without extension.
|
|
21
|
+
- Add an empty string.
|
|
22
|
+
- If the drakon-graph object has "params" property, add a string: Description:
|
|
23
|
+
Then, convert the HTML value of the "params" property into a string and add that string to the list.
|
|
24
|
+
Add an empty string.
|
|
25
|
+
- Build the array of work nodes.
|
|
26
|
+
- Add a string: The algorithm of the procedure is expressed as a graph of steps.
|
|
27
|
+
- Add a string: The id of the first step is <the id of the first node in the array of work nodes>
|
|
28
|
+
- Add an empty string.
|
|
29
|
+
- For each work node, print it to the output list.
|
|
30
|
+
- Add a string: End of procedure.
|
|
31
|
+
- Join the list of strings with the end-of-line separator.
|
|
32
|
+
- Return the result string.
|
|
33
|
+
|
|
34
|
+
How to build the array of work nodes.
|
|
35
|
+
- Preprocess the select nodes
|
|
36
|
+
- Preprocess the insertion nodes
|
|
37
|
+
- Create an empty set of visited nodes.
|
|
38
|
+
- Create an empty array of work nodes.
|
|
39
|
+
- Call the processBranch procedure with this set, the first node, and the output nodes.
|
|
40
|
+
|
|
41
|
+
How to preprocess the insertion nodes:
|
|
42
|
+
- For each node in the drakon-graph where node.type === "insertion"
|
|
43
|
+
Set node.type = "action"
|
|
44
|
+
|
|
45
|
+
How to preprocess the select nodes:
|
|
46
|
+
- For each node in the drakon-graph where node.type === "select"
|
|
47
|
+
- build the array of cases and save it in the "cases" property of the node.
|
|
48
|
+
|
|
49
|
+
How to build the array of cases of a "select" node:
|
|
50
|
+
- Create an empty array
|
|
51
|
+
- Call the visitSelect procedure with the this array and the id stored in the node.one property.
|
|
52
|
+
|
|
53
|
+
visitSelect procedure takes a node id and the output array as arguments.
|
|
54
|
+
Algorithm of visitSelect procedure:
|
|
55
|
+
- if node id is empty, exit
|
|
56
|
+
- get the node by id
|
|
57
|
+
- add an object to the output array: {value:node.content, next:node.one}
|
|
58
|
+
- recursively call visitSelect with node.two
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
The processBranch procedure traverses the drakon-graph this way:
|
|
62
|
+
- processBranch re-uses the set of visited nodes in recursion
|
|
63
|
+
- If node is in the set of visited nodes, exit.
|
|
64
|
+
- Add the node to the visited nodes.
|
|
65
|
+
- Write the node id in "id" property of the node object.
|
|
66
|
+
- If node.type === "branch", go to the next node.
|
|
67
|
+
- If node.type === "end", exit.
|
|
68
|
+
- If node.type === "comment", go to the next node.
|
|
69
|
+
- If node.type === "arrow-loop":
|
|
70
|
+
- add the node to the array of work nodes
|
|
71
|
+
- Go to the next node.
|
|
72
|
+
- If node.type === "action":
|
|
73
|
+
- if node.content does not have a value, go to the next node.
|
|
74
|
+
- add the node to the array of work nodes
|
|
75
|
+
- Go to the next node.
|
|
76
|
+
- if node.type === "question"
|
|
77
|
+
- If node.content does not have a value, throw an error: A Question icon must have content.
|
|
78
|
+
- add the node to the array of work nodes
|
|
79
|
+
- Run processBranch with the node specified in node.one
|
|
80
|
+
- Run processBranch with the node specified in node.two
|
|
81
|
+
- if node.type === "select"
|
|
82
|
+
- If node.content does not have a value, throw an error: A Select icon must have content.
|
|
83
|
+
- add the node to the array of work
|
|
84
|
+
- for each item in node.items:
|
|
85
|
+
- Run processBranch with the node specified in item.next
|
|
86
|
+
- The id of the next node is in the property "one".
|
|
87
|
+
|
|
88
|
+
How to print a node to the output list of string:
|
|
89
|
+
- If node.type === "action":
|
|
90
|
+
- if node.content does not have a value, go to the next node.
|
|
91
|
+
- Add a string: Step id: <node.id>
|
|
92
|
+
- Convert HTML in node.content into a string and add it to the output list.
|
|
93
|
+
- Add a string: Next step: <node.one>
|
|
94
|
+
- Add a string: End of step.
|
|
95
|
+
- Add an empty string.
|
|
96
|
+
- if node.type === "question"
|
|
97
|
+
- Add a string: Step id: <node.id>
|
|
98
|
+
- Convert HTML in node.content into a string and add it to the output list.
|
|
99
|
+
- Add a string: If yes, next step: the id of the "yes" node.
|
|
100
|
+
- Add a string: If no, next step: the id of the "no" node.
|
|
101
|
+
- Add a string: End of step.
|
|
102
|
+
- Add an empty string.
|
|
103
|
+
- if node.type === "select"
|
|
104
|
+
- Add a string: Step id: <node.id>
|
|
105
|
+
- For each item in node.cases
|
|
106
|
+
- If item.value is not empty,
|
|
107
|
+
leftValue = Convert HTML in node.content into a string
|
|
108
|
+
rightValue = Convert HTML in item.content into a string
|
|
109
|
+
then, add a string: If <leftValue> = <rightValue>, next step: <item.next>
|
|
110
|
+
- Otherwise, add a string: Else, next step: <item.next>
|
|
111
|
+
- If item.value is empty and item is not the last element, throw an error: Only last Case icon can be empty.
|
|
112
|
+
- Add a string: End of step.
|
|
113
|
+
- Add an empty string.
|
|
114
|
+
- if node.type === "arrow-loop"
|
|
115
|
+
- Add a string: Step id: <node.id>
|
|
116
|
+
- Add a string: Next step: <node.one>
|
|
117
|
+
- Add a string: End of step.
|
|
118
|
+
- Add an empty string.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
In a "question" node, the id of the "yes" node is in "one" property if node.flag1 === 1.
|
|
122
|
+
Otherwise it is in the "two" property.
|
|
123
|
+
|
|
124
|
+
In a "question" node, the id of the "no" node is in "two" property if node.flag1 === 1.
|
|
125
|
+
Otherwise it is in the "one" property.
|
|
126
|
+
|
|
127
|
+
When throwing an error, add the filename to the description and the node id if available.
|
|
128
|
+
|
|
129
|
+
Here is how to convert HTML into string.
|
|
130
|
+
- If the input string is falsish, return an empty string.
|
|
131
|
+
- If the input string does not start and end with HTML tags, return it as it is.
|
|
132
|
+
- Take the text content of each <p> tag into a separate line.
|
|
133
|
+
- Take the text content of each unnumbered list item into a separate line, preceded with a hyphen.
|
|
134
|
+
- Take the text content of each unnumbered list item into a separate line, preceded with the item number.
|
|
135
|
+
- Put an empty line before and after the list.
|
|
136
|
+
- Ignore all other tags.
|
|
137
|
+
|
|
138
|
+
When generating code, avoid too deeply nested expressions.
|
|
139
|
+
Choose an extra variable over compactness. Prefer readability.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Write JavaScript code for a NodeJs application.
|
|
2
|
+
The application is a command line tool that accepts one required command line parameter - the path to a file.
|
|
3
|
+
|
|
4
|
+
Here is the algorithm of the application:
|
|
5
|
+
|
|
6
|
+
- Read the content of the file into a string. The file is in UTF-8 encoding.
|
|
7
|
+
- Call the function drakonToPrompt(content, filename). Send the content and the full path to that function. The function will return a string.
|
|
8
|
+
- Write the string to disc in UTF-8 encoding. The filename is like the path to the file from the command line,
|
|
9
|
+
but replace its extension to .txt
|
|
10
|
+
|
|
11
|
+
Use await for async operations.
|
|
12
|
+
Import drakonToPrompt function from ./drakonToPrompt
|
|
13
|
+
|
|
14
|
+
The format of application is CommonJs.
|
|
15
|
+
If there is an uncaught exception, print both the message and the stacktrace.
|
|
16
|
+
|
|
17
|
+
If the application has completed its task without errors, do not print anything in the console.
|