typescratch 1.6.2__tar.gz → 1.6.8__tar.gz

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.
Files changed (55) hide show
  1. typescratch-1.6.8/PKG-INFO +494 -0
  2. typescratch-1.6.8/README.md +466 -0
  3. {typescratch-1.6.2 → typescratch-1.6.8}/pyproject.toml +5 -5
  4. typescratch-1.6.8/typescratch/MASCOT_LICENSE +23 -0
  5. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/__init__.py +1 -1
  6. typescratch-1.6.8/typescratch/assets.py +69 -0
  7. typescratch-1.6.8/typescratch/autocomplete.py +301 -0
  8. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/codegen.py +371 -27
  9. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/decompiler.py +0 -0
  10. {typescratch-1.6.2/typescratch_pypi_release/typescratch_src → typescratch-1.6.8/typescratch}/ide.py +43 -2
  11. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/lexer.py +1 -0
  12. typescratch-1.6.8/typescratch/lint_zippy.svg +1 -0
  13. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/meow.txt +0 -0
  14. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/package_manager.py +0 -0
  15. {typescratch-1.6.2/typescratch_pypi_release/typescratch_src → typescratch-1.6.8/typescratch}/parser.py +137 -14
  16. typescratch-1.6.8/typescratch.egg-info/PKG-INFO +494 -0
  17. typescratch-1.6.8/typescratch.egg-info/SOURCES.txt +30 -0
  18. typescratch-1.6.8/typescratch.egg-info/top_level.txt +1 -0
  19. typescratch-1.6.2/PKG-INFO +0 -655
  20. typescratch-1.6.2/README.md +0 -627
  21. typescratch-1.6.2/tests/test_basic.py +0 -172
  22. typescratch-1.6.2/typescratch/assets.py +0 -69
  23. typescratch-1.6.2/typescratch/ide.py +0 -515
  24. typescratch-1.6.2/typescratch/parser.py +0 -1201
  25. typescratch-1.6.2/typescratch/scratchcat_official.svg +0 -42
  26. typescratch-1.6.2/typescratch.egg-info/PKG-INFO +0 -655
  27. typescratch-1.6.2/typescratch.egg-info/SOURCES.txt +0 -44
  28. typescratch-1.6.2/typescratch.egg-info/top_level.txt +0 -2
  29. typescratch-1.6.2/typescratch_pypi_release/setup.py +0 -2
  30. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/__init__.py +0 -195
  31. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/__main__.py +0 -10
  32. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/assets.py +0 -69
  33. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/ast_nodes.py +0 -399
  34. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/blocks.py +0 -969
  35. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/cli.py +0 -171
  36. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/codegen.py +0 -1967
  37. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/decompiler.py +0 -868
  38. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/errors.py +0 -123
  39. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/lexer.py +0 -335
  40. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/package_manager.py +0 -127
  41. typescratch-1.6.2/typescratch_pypi_release/typescratch_src/sb3.py +0 -60
  42. {typescratch-1.6.2 → typescratch-1.6.8}/LICENSE +0 -0
  43. {typescratch-1.6.2 → typescratch-1.6.8}/setup.cfg +0 -0
  44. {typescratch-1.6.2 → typescratch-1.6.8}/setup.py +0 -0
  45. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/__main__.py +0 -0
  46. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/ast_nodes.py +0 -0
  47. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/blocks.py +0 -0
  48. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/cli.py +0 -0
  49. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/errors.py +0 -0
  50. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/logo.svg +0 -0
  51. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/logo_ascii.txt +0 -0
  52. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch/sb3.py +0 -0
  53. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch.egg-info/dependency_links.txt +0 -0
  54. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch.egg-info/entry_points.txt +0 -0
  55. {typescratch-1.6.2 → typescratch-1.6.8}/typescratch.egg-info/requires.txt +0 -0
@@ -0,0 +1,494 @@
1
+ Metadata-Version: 2.4
2
+ Name: typescratch
3
+ Version: 1.6.8
4
+ Summary: A programming language that compiles to Scratch 3 (.sb3) files
5
+ Author: TypeScratch
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/commit-to-the-git/typescratch
8
+ Project-URL: Source, https://github.com/commit-to-the-git/typescratch
9
+ Project-URL: Issue Tracker, https://github.com/commit-to-the-git/typescratch/issues
10
+ Keywords: scratch,compiler,programming-language,sb3,education,turbowarp
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Education
22
+ Classifier: Topic :: Software Development :: Compilers
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: windows-curses>=2.0; sys_platform == "win32"
27
+ Dynamic: license-file
28
+
29
+ # TypeScratch
30
+
31
+ A programming language that compiles to **Scratch 3 (.sb3)** files. Write text, get a runnable Scratch project you can open in [scratch.mit.edu](https://scratch.mit.edu) or [TurboWarp](https://turbowarp.org/editor).
32
+
33
+ The official mascot is **Lint Zippy**, an original character created for TypeScratch (CC BY-NC-ND 4.0).
34
+
35
+ ```tysh
36
+ extension Pen
37
+ // your average comment
38
+ s "Sprite1"
39
+ when gf clicked {
40
+ say(Hello, World!)(2)
41
+ pen.Down
42
+ goto(10, 20)
43
+ pen.Up
44
+ Points = 0
45
+ Name = Scratch Cat
46
+ Points += 1
47
+ }
48
+ when spr clicked {
49
+ if (days since 2000) > 120 {
50
+ say(idk)
51
+ }
52
+ }
53
+ ```
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ pip install typescratch
59
+ ```
60
+
61
+ On Windows, `windows-curses` is automatically installed for the IDE.
62
+
63
+ ## CLI
64
+
65
+ ```bash
66
+ typescratch build thing.tysh # compile to .sb3
67
+ typescratch build thing.tysh --out out.sb3 # specify output
68
+ typescratch build thing.tysh --debug # verbose token/AST dump
69
+ typescratch ide thing.tysh # launch the terminal IDE
70
+ typescratch decompile game.sb3 # decompile .sb3 to .tysh
71
+ typescratch decompile game.sb3 --out game.tysh # specify output
72
+ typescratch fmt game.tysh # auto-indent in place
73
+ typescratch install user/repo # install a package from GitHub
74
+ typescratch uninstall repo-name # remove a package
75
+ typescratch list # list installed packages
76
+ typescratch meow # print the Scratch Cat in ASCII art
77
+ typescratch version
78
+ ```
79
+
80
+ Or use `python -m typescratch build thing.tysh` if `typescratch` is not on PATH.
81
+
82
+ ## Library API
83
+
84
+ ```python
85
+ import typescratch
86
+
87
+ # Compile a .tysh file to .sb3 (output defaults to <input>.sb3)
88
+ typescratch.file("thing.tysh")
89
+ typescratch.file("thing.tysh", out="custom.sb3")
90
+
91
+ # Compile from a source string
92
+ sb3_bytes = typescratch.source('s "S" when gf clicked { say(hi) }')
93
+ typescratch.source(src, out="out.sb3")
94
+
95
+ # Decompile a .sb3 file to .tysh source
96
+ from typescratch.decompiler import decompile_sb3
97
+ source_code = decompile_sb3("game.sb3")
98
+ ```
99
+
100
+ ## Language reference
101
+
102
+ ### Comments
103
+
104
+ ```tysh
105
+ // line comment (only at the start of a line, after whitespace)
106
+ // this is because // is also the floor division operator
107
+ ```
108
+
109
+ ### Extensions
110
+
111
+ ```tysh
112
+ extension Pen
113
+ extension Music
114
+ extension Text to Speech
115
+ extension Translate
116
+ extension Video Sensing
117
+ extension Makey Makey
118
+ extension micro:bit
119
+ extension LEGO BOOST
120
+ extension LEGO EV3
121
+ extension LEGO WeDo 2
122
+ extension Go Direct Force
123
+ ```
124
+
125
+ ### Sprites and Backdrops
126
+
127
+ ```tysh
128
+ s "Player" xy=100, 50 dir=90 size=110 visible=true rot=all around
129
+ b "Stage 1" img=./backdrops/forest.svg
130
+ ```
131
+
132
+ If `img=` is omitted or the file doesn't exist, the sprite gets the official TypeScratch mascot, **Lint Zippy**, as its default costume.
133
+
134
+ ### Sound and Costume Imports
135
+
136
+ ```tysh
137
+ s "Player"
138
+ sound meow from "./meow.wav"
139
+ sound jump from "./jump.mp3"
140
+ costume walk1 from "./walk1.png"
141
+ costume walk2 from "./walk2.png"
142
+ when gf clicked {
143
+ playSound(meow)
144
+ switchCostumeTo(walk1)
145
+ }
146
+ ```
147
+
148
+ ### Variables
149
+
150
+ ```tysh
151
+ Score = 0
152
+ Name = Scratch Cat
153
+ Score += 10
154
+ Score -= 5
155
+ Score *= 2
156
+ Score /= 3
157
+ Score++ // increment by 1
158
+ Score-- // decrement by 1
159
+ showVariable(Score)
160
+ hideVariable(Score)
161
+ ```
162
+
163
+ ### Local Variables (inside custom blocks)
164
+
165
+ ```tysh
166
+ def Compute(base) {
167
+ private result = base * 2
168
+ say(result)
169
+ }
170
+ ```
171
+
172
+ ### Lists
173
+
174
+ ```tysh
175
+ list inventory = [sword, shield, potion]
176
+ list scores = [10, 20, 30]
177
+
178
+ inventory.add(new item)
179
+ inventory.delete(1)
180
+ inventory.delete(all)
181
+ inventory.insert(cool thing, 0)
182
+ inventory.replace(1, better sword)
183
+ inventory.show
184
+ inventory.hide
185
+
186
+ // List reporters (use in expressions):
187
+ X = inventory.item(1)
188
+ L = inventory.length
189
+ Has = inventory.contains(sword)
190
+ Pos = inventory.itemNum(sword)
191
+ All = inventory.contents
192
+ ```
193
+
194
+ ### Hats (events)
195
+
196
+ ```tysh
197
+ when gf clicked { ... }
198
+ when spr clicked { ... }
199
+ when stage clicked { ... }
200
+ when cloned { ... }
201
+ when key [space] pressed { ... }
202
+ when backdrop switches to [Stage 2] { ... }
203
+ when I receive [start game] { ... }
204
+ when [loudness] > [10] { ... }
205
+ when touching [mouse] { ... }
206
+ ```
207
+
208
+ ### Motion
209
+
210
+ ```tysh
211
+ move(10)
212
+ turnRight(15)
213
+ turnLeft(15)
214
+ goto(10, 20)
215
+ glide(1, 100, 50)
216
+ pointInDirection(90)
217
+ pointTowards(mouse)
218
+ changeX(5)
219
+ changeY(5)
220
+ setX(100)
221
+ setY(50)
222
+ ifOnEdgeBounce
223
+ setRotationStyle(left-right)
224
+ ```
225
+
226
+ ### Looks
227
+
228
+ ```tysh
229
+ say(Hello, World!)(2)
230
+ say(Just saying)
231
+ think(Hmm...)(1)
232
+ switchCostumeTo(costume2)
233
+ nextCostume
234
+ switchBackdropTo(Stage 2)
235
+ changeSize(10)
236
+ setSize(100)
237
+ show
238
+ hide
239
+ goFront // go to front layer
240
+ goBack // go to back layer
241
+ goFwdLyrs(2) // go forward 2 layers
242
+ goBwdLyrs(2) // go backward 2 layers
243
+ ```
244
+
245
+ ### Sound
246
+
247
+ ```tysh
248
+ playSound(meow)
249
+ playSoundUntilDone(meow)
250
+ stopAllSounds
251
+ changePitch(10)
252
+ setPitch(100)
253
+ changeVolume(10)
254
+ setVolume(100)
255
+ changeSoundEffect(pitch)(10)
256
+ setSoundEffect(pitch)(100)
257
+ clearSoundEffects
258
+ ```
259
+
260
+ ### Control flow
261
+
262
+ ```tysh
263
+ wait(1)
264
+ waitUntil (cond)
265
+ repeat(10) { ... }
266
+ forever { ... }
267
+ if (cond) { ... }
268
+ if (cond) { ... } elif (cond2) { ... } else { ... }
269
+ repeatUntil (cond) { ... }
270
+ while (cond) { ... }
271
+ forEach (i) in (5) { ... }
272
+ allAtOnce { ... }
273
+ stop(all)
274
+ createCloneOf(myself)
275
+ deleteThisClone
276
+ broadcast(message1)
277
+ broadcast(message1) and wait
278
+ ```
279
+
280
+ ### Operators (in expressions)
281
+
282
+ ```tysh
283
+ 5 + 3 // addition
284
+ 10 - 4 // subtraction
285
+ 6 * 7 // multiplication
286
+ 20 / 4 // division
287
+ 17 // 5 // floor division (round(17 / 5))
288
+ 17 mod 5 // modulo
289
+ "Hello" & " World" // string join
290
+ 5 != 3 // not equals
291
+ 5 >= 5 // greater than or equal
292
+ 3 <= 5 // less than or equal
293
+ pickRandom(1, 100)
294
+ join(Hello, World)
295
+ letterOf(1, Hello)
296
+ lengthOf(Hello World)
297
+ contains(Hello World, World)
298
+ round(3.7)
299
+ abs(-5)
300
+ floor(3.7) ceiling(3.2) sqrt(16)
301
+ sin(0) cos(0) tan(0) asin(1) acos(0) atan(1)
302
+ ln(2.7) log(100)
303
+ ```
304
+
305
+ Comparison: `>`, `<`, `=`, `!=`, `>=`, `<=`
306
+ Logic: `and`, `or`, `not`
307
+
308
+ ### Ternary Expressions
309
+
310
+ ```tysh
311
+ say([if (x > 5) yes else no])
312
+ X = [if (Score > 100) winner else loser]
313
+ ```
314
+
315
+ ### Sensing
316
+
317
+ ```tysh
318
+ ask(What is your name?) and wait
319
+ resetTimer
320
+
321
+ // Reporters:
322
+ answer
323
+ mouseDown
324
+ mouseX
325
+ mouseY
326
+ loudness
327
+ timer
328
+ daysSince2000
329
+ username
330
+ touching(mouse)
331
+ touchingColor(#ff0000)
332
+ colorIsTouching(#ff0000, #00ff00)
333
+ distanceTo(mouse)
334
+ keyPressed(space)
335
+ attribute(x position, Sprite1)
336
+ current(YEAR)
337
+ ```
338
+
339
+ ### Pen extension
340
+
341
+ ```tysh
342
+ pen.Clear
343
+ pen.Down
344
+ pen.Up
345
+ pen.SetColor(#ff0000)
346
+ pen.SetSize(3)
347
+ pen.Stamp
348
+ ```
349
+
350
+ ### Custom blocks (My Blocks)
351
+
352
+ ```tysh
353
+ def Greet(name) {
354
+ say(join(Hello, name))(2)
355
+ }
356
+
357
+ def FastLoop(n) warp=true {
358
+ repeat(n) { move(1) }
359
+ }
360
+
361
+ def Calc(base number, mult number, debug bool) {
362
+ Result = base * mult
363
+ if debug { say(Result) }
364
+ }
365
+
366
+ when gf clicked {
367
+ Greet(Bob)
368
+ FastLoop(100)
369
+ Calc(5, 3, true)
370
+ }
371
+ ```
372
+
373
+ ### Multi-file Projects (fuse)
374
+
375
+ ```tysh
376
+ fuse "helpers.tysh"
377
+ fuse "typescratch_packages/my-lib/main.tysh"
378
+ ```
379
+
380
+ Inline other `.tysh` files into your project. Recursive, so fused files can fuse other files.
381
+
382
+ ### Hidden / Hacked / TurboWarp Blocks
383
+
384
+ ```tysh
385
+ resetCounter
386
+ incrementCounter
387
+ Count = counter
388
+ forEach (i) in (5) { say(i) }
389
+ allAtOnce { move(10) turnRight(15) }
390
+ changeStretch(10)
391
+ setStretch(100)
392
+ hideAllSprites
393
+ switchBackdropToAndWait(Stage 2)
394
+ if isTurboWarp { say(Running in TurboWarp!) }
395
+ if isTurboWarp? { say(Running in TurboWarp!) }
396
+ ```
397
+
398
+ ### Error Types
399
+
400
+ TypeScratch has friendly error types:
401
+
402
+ - **SyntaxOops**: syntax errors (missing braces, unknown tokens)
403
+ - **ForgotOops**: using an undefined custom block, variable, or broadcast
404
+ - **ArgumentOops**: calling a custom block with the wrong number of arguments
405
+ - **TypeMismatchOops**: using a non-boolean where a boolean is expected (reserved for future use)
406
+
407
+ All errors include line numbers and "Did you mean?" suggestions.
408
+
409
+ ## Decompiler
410
+
411
+ TypeScratch includes a decompiler that converts `.sb3` files back to `.tysh` source code:
412
+
413
+ ```bash
414
+ typescratch decompile game.sb3
415
+ typescratch decompile game.sb3 --out game.tysh
416
+ ```
417
+
418
+ Tested on griffpatch's appel game (8146 lines decompiled with zero unknown blocks).
419
+
420
+ ## IDE
421
+
422
+ TypeScratch includes a terminal-based IDE with syntax highlighting, auto-indentation, and compile/verify buttons:
423
+
424
+ ```bash
425
+ typescratch ide # new file
426
+ typescratch ide game.tysh # open existing file
427
+ ```
428
+
429
+ Controls:
430
+ - **F5**: Compile to .sb3
431
+ - **F6**: Verify syntax
432
+ - **Ctrl+S**: Save
433
+ - **Ctrl+Q**: Quit
434
+ - Arrow keys, Page Up/Down, Home/End
435
+
436
+ ## Formatter
437
+
438
+ ```bash
439
+ typescratch fmt game.tysh # format in place
440
+ typescratch fmt game.tysh --out out.tysh
441
+ ```
442
+
443
+ ## Package Manager
444
+
445
+ ```bash
446
+ typescratch install user/repo # install from GitHub
447
+ typescratch install user/repo@v1.0 # install specific tag
448
+ typescratch uninstall repo-name # remove package
449
+ typescratch list # list installed packages
450
+ ```
451
+
452
+ Packages are cloned into `./typescratch_packages/`. Use `fuse` to include them:
453
+ ```tysh
454
+ fuse "typescratch_packages/my-lib/main.tysh"
455
+ ```
456
+
457
+ ## Easter Eggs
458
+
459
+ ```bash
460
+ typescratch meow # prints the TypeScratch mascot in ASCII art
461
+ ```
462
+
463
+ ## Project structure
464
+
465
+ ```
466
+ typescratch/
467
+ typescratch/
468
+ __init__.py # public API
469
+ __main__.py # python -m typescratch entry point
470
+ cli.py # CLI (build, ide, decompile, fmt, install, meow)
471
+ lexer.py # .tysh tokenizer
472
+ parser.py # tokens -> AST
473
+ ast_nodes.py # AST dataclass definitions
474
+ blocks.py # TypeScratch syntax -> Scratch opcode table
475
+ codegen.py # AST -> Scratch project.json
476
+ sb3.py # .sb3 zip packager
477
+ decompiler.py # .sb3 -> .tysh decompiler
478
+ ide.py # terminal IDE (curses)
479
+ package_manager.py # GitHub package installer
480
+ assets.py # default mascot (Lint Zippy) and backdrop
481
+ errors.py # SyntaxOops, ForgotOops, ArgumentOops
482
+ lint_zippy.svg # official mascot (CC BY-NC-ND 4.0)
483
+ logo.svg # TypeScratch logo
484
+ logo_ascii.txt # ASCII art logo for the IDE
485
+ meow.txt # ASCII art for the meow easter egg
486
+ ```
487
+
488
+ ## License
489
+
490
+ Apache License 2.0 for the TypeScratch language and compiler.
491
+
492
+ The TypeScratch mascot "Lint Zippy" (lint_zippy.svg) is licensed under CC BY-NC-ND 4.0. See MASCOT_LICENSE.
493
+
494
+ GitHub: https://github.com/commit-to-the-git/typescratch