dal-ast-js 0.0.3-dev → 0.0.5-dev

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/dist/index.cjs CHANGED
@@ -8,7 +8,8 @@ let TOKENS = {
8
8
  "LBRACE": "{",
9
9
  "RBRACE": "}",
10
10
  "LBRACKET": "[",
11
- "RBRACKET": "]"
11
+ "RBRACKET": "]",
12
+ "HASH": "#"
12
13
  };
13
14
  TOKENS = Object.freeze(TOKENS);
14
15
 
@@ -84,6 +85,10 @@ class DalLexer {
84
85
 
85
86
  const token = this.getToken(character);
86
87
  if (token) {
88
+ if (token === "HASH") {
89
+ this.scanToNewLine();
90
+ return;
91
+ }
87
92
  this.addAccumulatedIdentifierToken();
88
93
  this.addToken(token);
89
94
  if (token === "QUOTE") {
@@ -94,6 +99,19 @@ class DalLexer {
94
99
  this.addToAccumulator(character);
95
100
  }
96
101
 
102
+ /**
103
+ * Scan to new line to ignore comment.
104
+ * @returns {null}
105
+ */
106
+ scanToNewLine () {
107
+ do {
108
+ const character = this.source[this.currPos];
109
+ if (character == "\n") {
110
+ return;
111
+ }
112
+ } while (++this.currPos < this.source.length);
113
+ }
114
+
97
115
  /**
98
116
  * Finds the identifier given the character.
99
117
  * @param {String} character Character from scan.
package/dist/index.esm.js CHANGED
@@ -6,7 +6,8 @@ let TOKENS$1 = {
6
6
  "LBRACE": "{",
7
7
  "RBRACE": "}",
8
8
  "LBRACKET": "[",
9
- "RBRACKET": "]"
9
+ "RBRACKET": "]",
10
+ "HASH": "#"
10
11
  };
11
12
  TOKENS$1 = Object.freeze(TOKENS$1);
12
13
 
@@ -82,6 +83,10 @@ class DalLexer {
82
83
 
83
84
  const token = this.getToken(character);
84
85
  if (token) {
86
+ if (token === "HASH") {
87
+ this.scanToNewLine();
88
+ return;
89
+ }
85
90
  this.addAccumulatedIdentifierToken();
86
91
  this.addToken(token);
87
92
  if (token === "QUOTE") {
@@ -92,6 +97,19 @@ class DalLexer {
92
97
  this.addToAccumulator(character);
93
98
  }
94
99
 
100
+ /**
101
+ * Scan to new line to ignore comment.
102
+ * @returns {null}
103
+ */
104
+ scanToNewLine () {
105
+ do {
106
+ const character = this.source[this.currPos];
107
+ if (character == "\n") {
108
+ return;
109
+ }
110
+ } while (++this.currPos < this.source.length);
111
+ }
112
+
95
113
  /**
96
114
  * Finds the identifier given the character.
97
115
  * @param {String} character Character from scan.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dal-ast-js",
3
- "version": "0.0.3-dev",
3
+ "version": "0.0.5-dev",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.esm.js",
6
6
  "type": "module",
package/src/Lexer.js CHANGED
@@ -70,6 +70,10 @@ export class DalLexer {
70
70
 
71
71
  const token = this.getToken(character);
72
72
  if (token) {
73
+ if (token === "HASH") {
74
+ this.scanToNewLine();
75
+ return;
76
+ }
73
77
  this.addAccumulatedIdentifierToken();
74
78
  this.addToken(token);
75
79
  if (token === "QUOTE") {
@@ -80,6 +84,19 @@ export class DalLexer {
80
84
  this.addToAccumulator(character);
81
85
  }
82
86
 
87
+ /**
88
+ * Scan to new line to ignore comment.
89
+ * @returns {null}
90
+ */
91
+ scanToNewLine () {
92
+ do {
93
+ const character = this.source[this.currPos];
94
+ if (character == "\n") {
95
+ return;
96
+ }
97
+ } while (++this.currPos < this.source.length);
98
+ }
99
+
83
100
  /**
84
101
  * Finds the identifier given the character.
85
102
  * @param {String} character Character from scan.
package/src/TOKENS.js CHANGED
@@ -6,7 +6,8 @@ let TOKENS = {
6
6
  "LBRACE": "{",
7
7
  "RBRACE": "}",
8
8
  "LBRACKET": "[",
9
- "RBRACKET": "]"
9
+ "RBRACKET": "]",
10
+ "HASH": "#"
10
11
  }
11
12
  TOKENS = Object.freeze(TOKENS);
12
13
 
@@ -9,7 +9,7 @@ import { DalAstGenerator } from "../src/DalAstGenerator";
9
9
 
10
10
  describe("Lexer", () => {
11
11
  it("basic source", async () => {
12
- const filePath = resolve(__dirname, "./designs/database_example/reverse_name_persist.dal")
12
+ const filePath = resolve(__dirname, "./designs/reverse_name_persist.dal")
13
13
  const source = await readFile(filePath)
14
14
  const lexer = new DalLexer(source.toString());
15
15
 
@@ -32,7 +32,7 @@ describe("Lexer", () => {
32
32
  });
33
33
 
34
34
  it("tests direct ast generation", async () => {
35
- const filePath = resolve(__dirname, "./designs/library_manager.dal")
35
+ const filePath = resolve(__dirname, "./designs/reverse_name_persist.dal")
36
36
  const source = await readFile(filePath)
37
37
  const ast = new DalAstGenerator().run(source.toString());
38
38
  const ast_output_path = resolve(__dirname, "./output/ast_direct_gen.json")
@@ -1,5 +1,6 @@
1
1
  design ("reverse_name_persist")
2
2
 
3
+ # Example comment that is ignored.
3
4
  behavior b_createDatabaseConnection {
4
5
  create(name=connection, type="object", role="connection")
5
6
  _connectToDatabase(connection)
@@ -6,13 +6,13 @@
6
6
  "design_name": [
7
7
  {
8
8
  "type": "string",
9
- "value": "library_manager"
9
+ "value": "reverse_name_persist"
10
10
  }
11
11
  ]
12
12
  },
13
13
  {
14
14
  "type": "behavior",
15
- "behaviorName": "createBasket",
15
+ "behaviorName": "b_createDatabaseConnection",
16
16
  "body": [
17
17
  {
18
18
  "type": "cmd",
@@ -20,37 +20,25 @@
20
20
  "args": [
21
21
  {
22
22
  "type": "name",
23
- "value": "name=basket"
23
+ "value": "name=connection"
24
24
  },
25
25
  {
26
26
  "type": "name",
27
- "value": "type=\"list\""
28
- },
29
- {
30
- "type": "name",
31
- "value": "role=\"basket\""
27
+ "value": "type=\"object\""
32
28
  },
33
29
  {
34
30
  "type": "name",
35
- "value": "accepts=\"book\""
31
+ "value": "role=\"connection\""
36
32
  }
37
33
  ]
38
34
  },
39
35
  {
40
- "type": "cmd",
41
- "command": "set",
36
+ "type": "registeredCmd",
37
+ "command": "_connectToDatabase",
42
38
  "args": [
43
39
  {
44
- "type": "string",
45
- "value": "basket"
46
- },
47
- {
48
- "type": "list",
49
- "value": []
50
- },
51
- {
52
- "type": "list",
53
- "value": []
40
+ "type": "name",
41
+ "value": "connection"
54
42
  }
55
43
  ]
56
44
  },
@@ -65,12 +53,12 @@
65
53
  {
66
54
  "type": "list",
67
55
  "value": [
68
- "basket"
56
+ "connection"
69
57
  ]
70
58
  },
71
59
  {
72
60
  "type": "name",
73
- "value": "basket"
61
+ "value": "connection"
74
62
  }
75
63
  ]
76
64
  },
@@ -80,7 +68,7 @@
80
68
  "args": [
81
69
  {
82
70
  "type": "name",
83
- "value": "getChoice"
71
+ "value": "b_createCursor"
84
72
  }
85
73
  ]
86
74
  }
@@ -88,155 +76,33 @@
88
76
  },
89
77
  {
90
78
  "type": "behavior",
91
- "behaviorName": "getChoice",
79
+ "behaviorName": "b_createCursor",
92
80
  "body": [
93
81
  {
94
82
  "type": "cmd",
95
- "command": "getInput",
96
- "args": [
97
- {
98
- "type": "name",
99
- "value": "choice"
100
- },
101
- {
102
- "type": "string",
103
- "value": "\nGet user choice (a for add book, g for get book, else exit): "
104
- }
105
- ]
106
- },
107
- {
108
- "type": "cmd",
109
- "command": "log",
110
- "args": [
111
- {
112
- "type": "string",
113
- "value": "getChoice"
114
- },
115
- {
116
- "type": "string",
117
- "value": "choice"
118
- },
119
- {
120
- "type": "string",
121
- "value": "string"
122
- },
123
- {
124
- "type": "name",
125
- "value": "choice"
126
- }
127
- ]
128
- },
129
- {
130
- "type": "cmd",
131
- "command": "isEqual",
132
- "args": [
133
- {
134
- "type": "name",
135
- "value": "choice"
136
- },
137
- {
138
- "type": "string",
139
- "value": "a"
140
- },
141
- {
142
- "type": "name",
143
- "value": "isAdd"
144
- }
145
- ]
146
- },
147
- {
148
- "type": "cmd",
149
- "command": "isEqual",
83
+ "command": "create",
150
84
  "args": [
151
85
  {
152
86
  "type": "name",
153
- "value": "choice"
154
- },
155
- {
156
- "type": "string",
157
- "value": "g"
87
+ "value": "name=cursor"
158
88
  },
159
89
  {
160
90
  "type": "name",
161
- "value": "isGet"
162
- }
163
- ]
164
- },
165
- {
166
- "type": "cmd",
167
- "command": "set",
168
- "args": [
169
- {
170
- "type": "name",
171
- "value": "worldState"
172
- },
173
- {
174
- "type": "list",
175
- "value": [
176
- "choice"
177
- ]
91
+ "value": "type=\"object\""
178
92
  },
179
93
  {
180
94
  "type": "name",
181
- "value": "choice"
182
- }
183
- ]
184
- },
185
- {
186
- "type": "if",
187
- "args": [
188
- {
189
- "type": "name",
190
- "value": "isAdd"
191
- }
192
- ],
193
- "body": [
194
- {
195
- "type": "cmd",
196
- "command": "select",
197
- "args": [
198
- {
199
- "type": "name",
200
- "value": "getName"
201
- }
202
- ]
95
+ "value": "role=\"cursor\""
203
96
  }
204
97
  ]
205
98
  },
206
- {
207
- "type": "if",
208
- "args": [
209
- {
210
- "type": "name",
211
- "value": "isGet"
212
- }
213
- ],
214
- "body": [
215
- {
216
- "type": "cmd",
217
- "command": "select",
218
- "args": [
219
- {
220
- "type": "name",
221
- "value": "getBookFromBasket"
222
- }
223
- ]
224
- }
225
- ]
226
- }
227
- ]
228
- },
229
- {
230
- "type": "behavior",
231
- "behaviorName": "getBookFromBasket",
232
- "body": [
233
99
  {
234
100
  "type": "cmd",
235
101
  "command": "get",
236
102
  "args": [
237
103
  {
238
104
  "type": "name",
239
- "value": "basket"
105
+ "value": "connection"
240
106
  },
241
107
  {
242
108
  "type": "name",
@@ -245,26 +111,22 @@
245
111
  {
246
112
  "type": "list",
247
113
  "value": [
248
- "basket"
114
+ "connection"
249
115
  ]
250
116
  }
251
117
  ]
252
118
  },
253
119
  {
254
- "type": "cmd",
255
- "command": "removeFromPos",
120
+ "type": "registeredCmd",
121
+ "command": "_createCursor",
256
122
  "args": [
257
123
  {
258
124
  "type": "name",
259
- "value": "book"
125
+ "value": "cursor"
260
126
  },
261
127
  {
262
128
  "type": "name",
263
- "value": "basket"
264
- },
265
- {
266
- "type": "number",
267
- "value": 0
129
+ "value": "connection"
268
130
  }
269
131
  ]
270
132
  },
@@ -279,12 +141,12 @@
279
141
  {
280
142
  "type": "list",
281
143
  "value": [
282
- "book"
144
+ "cursor"
283
145
  ]
284
146
  },
285
147
  {
286
148
  "type": "name",
287
- "value": "book"
149
+ "value": "cursor"
288
150
  }
289
151
  ]
290
152
  },
@@ -294,7 +156,7 @@
294
156
  "args": [
295
157
  {
296
158
  "type": "name",
297
- "value": "getFirstLetterOfBookName"
159
+ "value": "b_createTable"
298
160
  }
299
161
  ]
300
162
  }
@@ -302,7 +164,7 @@
302
164
  },
303
165
  {
304
166
  "type": "behavior",
305
- "behaviorName": "getFirstLetterOfBookName",
167
+ "behaviorName": "b_createTable",
306
168
  "body": [
307
169
  {
308
170
  "type": "cmd",
@@ -310,7 +172,7 @@
310
172
  "args": [
311
173
  {
312
174
  "type": "name",
313
- "value": "book"
175
+ "value": "cursor"
314
176
  },
315
177
  {
316
178
  "type": "name",
@@ -319,76 +181,22 @@
319
181
  {
320
182
  "type": "list",
321
183
  "value": [
322
- "book"
323
- ]
324
- }
325
- ]
326
- },
327
- {
328
- "type": "cmd",
329
- "command": "get",
330
- "args": [
331
- {
332
- "type": "name",
333
- "value": "name"
334
- },
335
- {
336
- "type": "name",
337
- "value": "book"
338
- },
339
- {
340
- "type": "list",
341
- "value": [
342
- "name"
184
+ "cursor"
343
185
  ]
344
186
  }
345
187
  ]
346
188
  },
347
189
  {
348
- "type": "cmd",
349
- "command": "getFromPos",
190
+ "type": "registeredCmd",
191
+ "command": "_createTable",
350
192
  "args": [
351
193
  {
352
- "type": "name",
353
- "value": "firstLetter"
194
+ "type": "null",
195
+ "value": null
354
196
  },
355
197
  {
356
198
  "type": "name",
357
- "value": "name"
358
- },
359
- {
360
- "type": "number",
361
- "value": 0
362
- }
363
- ]
364
- },
365
- {
366
- "type": "cmd",
367
- "command": "display",
368
- "args": [
369
- {
370
- "type": "string",
371
- "value": "f'Got book named {name} and it has first letter {firstLetter}'"
372
- }
373
- ]
374
- },
375
- {
376
- "type": "cmd",
377
- "command": "set",
378
- "args": [
379
- {
380
- "type": "name",
381
- "value": "worldState"
382
- },
383
- {
384
- "type": "list",
385
- "value": [
386
- "firstLetter"
387
- ]
388
- },
389
- {
390
- "type": "name",
391
- "value": "firstLetter"
199
+ "value": "cursor"
392
200
  }
393
201
  ]
394
202
  },
@@ -398,7 +206,7 @@
398
206
  "args": [
399
207
  {
400
208
  "type": "name",
401
- "value": "getChoice"
209
+ "value": "b_commitConnection"
402
210
  }
403
211
  ]
404
212
  }
@@ -406,7 +214,7 @@
406
214
  },
407
215
  {
408
216
  "type": "behavior",
409
- "behaviorName": "displayChoice",
217
+ "behaviorName": "b_commitConnection",
410
218
  "body": [
411
219
  {
412
220
  "type": "cmd",
@@ -414,7 +222,7 @@
414
222
  "args": [
415
223
  {
416
224
  "type": "name",
417
- "value": "choice"
225
+ "value": "connection"
418
226
  },
419
227
  {
420
228
  "type": "name",
@@ -423,18 +231,22 @@
423
231
  {
424
232
  "type": "list",
425
233
  "value": [
426
- "choice"
234
+ "connection"
427
235
  ]
428
236
  }
429
237
  ]
430
238
  },
431
239
  {
432
- "type": "cmd",
433
- "command": "display",
240
+ "type": "registeredCmd",
241
+ "command": "_commitConnection",
434
242
  "args": [
435
243
  {
436
- "type": "string",
437
- "value": "f'User Choice: {choice}'"
244
+ "type": "null",
245
+ "value": null
246
+ },
247
+ {
248
+ "type": "name",
249
+ "value": "connection"
438
250
  }
439
251
  ]
440
252
  },
@@ -444,7 +256,7 @@
444
256
  "args": [
445
257
  {
446
258
  "type": "name",
447
- "value": "getChoice"
259
+ "value": "b_receiveName"
448
260
  }
449
261
  ]
450
262
  }
@@ -452,7 +264,7 @@
452
264
  },
453
265
  {
454
266
  "type": "behavior",
455
- "behaviorName": "getName",
267
+ "behaviorName": "b_receiveName",
456
268
  "body": [
457
269
  {
458
270
  "type": "cmd",
@@ -473,35 +285,9 @@
473
285
  ]
474
286
  },
475
287
  {
476
- "type": "cmd",
477
- "command": "getInput",
288
+ "type": "registeredCmd",
289
+ "command": "_receiveName",
478
290
  "args": [
479
- {
480
- "type": "name",
481
- "value": "name"
482
- },
483
- {
484
- "type": "string",
485
- "value": "\nPlease enter book name: "
486
- }
487
- ]
488
- },
489
- {
490
- "type": "cmd",
491
- "command": "log",
492
- "args": [
493
- {
494
- "type": "string",
495
- "value": "getName"
496
- },
497
- {
498
- "type": "string",
499
- "value": "name"
500
- },
501
- {
502
- "type": "string",
503
- "value": "string"
504
- },
505
291
  {
506
292
  "type": "name",
507
293
  "value": "name"
@@ -534,7 +320,7 @@
534
320
  "args": [
535
321
  {
536
322
  "type": "name",
537
- "value": "createBook"
323
+ "value": "b_reverse"
538
324
  }
539
325
  ]
540
326
  }
@@ -542,7 +328,7 @@
542
328
  },
543
329
  {
544
330
  "type": "behavior",
545
- "behaviorName": "createBook",
331
+ "behaviorName": "b_reverse",
546
332
  "body": [
547
333
  {
548
334
  "type": "cmd",
@@ -565,54 +351,12 @@
565
351
  ]
566
352
  },
567
353
  {
568
- "type": "cmd",
569
- "command": "create",
570
- "args": [
571
- {
572
- "type": "name",
573
- "value": "name=book"
574
- },
575
- {
576
- "type": "name",
577
- "value": "type=\"object\""
578
- },
579
- {
580
- "type": "name",
581
- "value": "role=\"book\""
582
- }
583
- ]
584
- },
585
- {
586
- "type": "cmd",
587
- "command": "set",
588
- "args": [
589
- {
590
- "type": "name",
591
- "value": "book"
592
- },
593
- {
594
- "type": "list",
595
- "value": []
596
- },
597
- {
598
- "type": "object",
599
- "value": {}
600
- }
601
- ]
602
- },
603
- {
604
- "type": "cmd",
605
- "command": "set",
354
+ "type": "registeredCmd",
355
+ "command": "_reverse",
606
356
  "args": [
607
357
  {
608
358
  "type": "name",
609
- "value": "book"
610
- },
611
- {
612
- "type": "list",
613
- "value": [
614
- "name"
615
- ]
359
+ "value": "reversedName"
616
360
  },
617
361
  {
618
362
  "type": "name",
@@ -631,28 +375,12 @@
631
375
  {
632
376
  "type": "list",
633
377
  "value": [
634
- "book"
378
+ "reversedName"
635
379
  ]
636
380
  },
637
381
  {
638
382
  "type": "name",
639
- "value": "book"
640
- }
641
- ]
642
- },
643
- {
644
- "type": "cmd",
645
- "command": "remove",
646
- "args": [
647
- {
648
- "type": "name",
649
- "value": "worldState"
650
- },
651
- {
652
- "type": "list",
653
- "value": [
654
- "name"
655
- ]
383
+ "value": "reversedName"
656
384
  }
657
385
  ]
658
386
  },
@@ -662,7 +390,7 @@
662
390
  "args": [
663
391
  {
664
392
  "type": "name",
665
- "value": "addBookToBasket"
393
+ "value": "b_writeToDatabase"
666
394
  }
667
395
  ]
668
396
  }
@@ -670,7 +398,7 @@
670
398
  },
671
399
  {
672
400
  "type": "behavior",
673
- "behaviorName": "addBookToBasket",
401
+ "behaviorName": "b_writeToDatabase",
674
402
  "body": [
675
403
  {
676
404
  "type": "cmd",
@@ -678,7 +406,7 @@
678
406
  "args": [
679
407
  {
680
408
  "type": "name",
681
- "value": "book"
409
+ "value": "cursor"
682
410
  },
683
411
  {
684
412
  "type": "name",
@@ -687,7 +415,7 @@
687
415
  {
688
416
  "type": "list",
689
417
  "value": [
690
- "book"
418
+ "cursor"
691
419
  ]
692
420
  }
693
421
  ]
@@ -698,7 +426,7 @@
698
426
  "args": [
699
427
  {
700
428
  "type": "name",
701
- "value": "basket"
429
+ "value": "reversedName"
702
430
  },
703
431
  {
704
432
  "type": "name",
@@ -707,112 +435,26 @@
707
435
  {
708
436
  "type": "list",
709
437
  "value": [
710
- "basket"
438
+ "reversedName"
711
439
  ]
712
440
  }
713
441
  ]
714
442
  },
715
443
  {
716
- "type": "cmd",
717
- "command": "insert",
444
+ "type": "registeredCmd",
445
+ "command": "_writeToDatabase",
718
446
  "args": [
719
447
  {
720
- "type": "name",
721
- "value": "basket"
722
- },
723
- {
724
- "type": "list",
725
- "value": []
448
+ "type": "null",
449
+ "value": null
726
450
  },
727
451
  {
728
452
  "type": "name",
729
- "value": "book"
453
+ "value": "cursor"
730
454
  },
731
- {
732
- "type": "number",
733
- "value": 0
734
- }
735
- ]
736
- },
737
- {
738
- "type": "cmd",
739
- "command": "set",
740
- "args": [
741
455
  {
742
456
  "type": "name",
743
- "value": "worldState"
744
- },
745
- {
746
- "type": "list",
747
- "value": [
748
- "basket"
749
- ]
750
- },
751
- {
752
- "type": "name",
753
- "value": "basket"
754
- }
755
- ]
756
- },
757
- {
758
- "type": "cmd",
759
- "command": "remove",
760
- "args": [
761
- {
762
- "type": "name",
763
- "value": "worldState"
764
- },
765
- {
766
- "type": "list",
767
- "value": [
768
- "book"
769
- ]
770
- }
771
- ]
772
- },
773
- {
774
- "type": "cmd",
775
- "command": "select",
776
- "args": [
777
- {
778
- "type": "name",
779
- "value": "showBasket"
780
- }
781
- ]
782
- }
783
- ]
784
- },
785
- {
786
- "type": "behavior",
787
- "behaviorName": "showBasket",
788
- "body": [
789
- {
790
- "type": "cmd",
791
- "command": "get",
792
- "args": [
793
- {
794
- "type": "name",
795
- "value": "basket"
796
- },
797
- {
798
- "type": "name",
799
- "value": "worldState"
800
- },
801
- {
802
- "type": "list",
803
- "value": [
804
- "basket"
805
- ]
806
- }
807
- ]
808
- },
809
- {
810
- "type": "cmd",
811
- "command": "display",
812
- "args": [
813
- {
814
- "type": "string",
815
- "value": "f'Basket Contents: {basket}'"
457
+ "value": "reversedName"
816
458
  }
817
459
  ]
818
460
  },
@@ -822,7 +464,7 @@
822
464
  "args": [
823
465
  {
824
466
  "type": "name",
825
- "value": "getChoice"
467
+ "value": "b_commitConnection"
826
468
  }
827
469
  ]
828
470
  }
@@ -834,7 +476,7 @@
834
476
  "args": [
835
477
  {
836
478
  "type": "name",
837
- "value": "createBasket"
479
+ "value": "b_createDatabaseConnection"
838
480
  }
839
481
  ]
840
482
  }
@@ -47,24 +47,24 @@
47
47
  "type": "IDENTIFIER",
48
48
  "value": "behavior",
49
49
  "startLineno": 3,
50
- "startColno": 1,
50
+ "startColno": 2,
51
51
  "endLineno": 3,
52
- "endColno": 8
52
+ "endColno": 9
53
53
  },
54
54
  {
55
55
  "type": "IDENTIFIER",
56
56
  "value": "b_createDatabaseConnection",
57
57
  "startLineno": 3,
58
- "startColno": 10,
58
+ "startColno": 11,
59
59
  "endLineno": 3,
60
- "endColno": 35
60
+ "endColno": 36
61
61
  },
62
62
  {
63
63
  "type": "LBRACE",
64
64
  "startLineno": 3,
65
- "startColno": 37,
65
+ "startColno": 38,
66
66
  "endLineno": 3,
67
- "endColno": 37
67
+ "endColno": 38
68
68
  },
69
69
  {
70
70
  "type": "IDENTIFIER",
@@ -1,30 +0,0 @@
1
- import sqlite3
2
-
3
- def connectToDatabase():
4
- return sqlite3.connect("my_database.db")
5
-
6
- def createCursor(connection):
7
- return connection.cursor()
8
-
9
- def createTable(cursor):
10
- cursor.execute("""
11
- CREATE TABLE IF NOT EXISTS users (
12
- id INTEGER PRIMARY KEY AUTOINCREMENT,
13
- name TEXT NOT NULL
14
- )
15
- """)
16
-
17
- def commitConnection(connection):
18
- connection.commit()
19
-
20
- def receiveName():
21
- return input("\nAdd Name: ")
22
-
23
- def writeToDatabase(cursor, name):
24
- cursor.execute(
25
- "INSERT INTO users (name) VALUES (?)",
26
- (name,),
27
- )
28
-
29
- def reverse(name):
30
- return name[::-1]
@@ -1,46 +0,0 @@
1
- from registered import *
2
-
3
- def b_createDatabaseConnection():
4
- connection = connectToDatabase()
5
- worldState["connection"] = connection
6
- return "b_createCursor"
7
-
8
- def b_createCursor():
9
- connection = worldState["connection"]
10
- cursor = createCursor(connection)
11
- worldState["cursor"] = cursor
12
- return "b_createTable"
13
-
14
- def b_createTable():
15
- cursor = worldState["cursor"]
16
- createTable(cursor)
17
- return "b_commitConnection"
18
-
19
- def b_commitConnection():
20
- connection = worldState["connection"]
21
- commitConnection(connection)
22
- return "b_receiveName"
23
-
24
- def b_receiveName():
25
- name = receiveName()
26
- worldState["name"] = name
27
- return "b_reverse"
28
-
29
- def b_reverse():
30
- name = worldState["name"]
31
- name = reverse(name)
32
- worldState["name"] = name
33
- return "b_writeToDatabase"
34
-
35
- def b_writeToDatabase():
36
- cursor = worldState["cursor"]
37
- name = worldState["name"]
38
- writeToDatabase(cursor, name)
39
- return "b_commitConnection"
40
-
41
-
42
- if __name__ == '__main__':
43
- nextBehavior = 'b_createDatabaseConnection'
44
- worldState = {}
45
- while nextBehavior:
46
- nextBehavior = globals()[nextBehavior]()