aradzie / keybr.com

The smartest way to learn touch typing and improve your typing speed.
https://www.keybr.com/
GNU Affero General Public License v3.0
1.77k stars 156 forks source link

feat: add python source code syntax #252

Closed fbosshard closed 2 months ago

fbosshard commented 2 months ago

Overview

This PR adds a Python option to the "Source Code" Syntax dropdown.

Output of example.ts:

=== Python ===
class Attention: return (inverse(result=(insert(img={0.01: serialize(key=({"""*""": (256), 'C:\\': ~reverse(B=60})})) # ``H x W`` class JDBC(Node): def __len__(out, y): # ; inputs = 'int'
class TestSuite(Rows): class MyModel: class Rows: # ? def update_state(count) -> int | None: def remove(name) -> bool | str: # noqa key["""C:\\"""] = 200 class Variable(Create):
# ``H x W`` def pop(img: list[float]): i[255] = [{"tensorflow": ({512: """, """, 9: [(shape(n=[__repr__(j=['''int''', (512)], expected=~__new__(output=(not (__setitem__(f="""valid""")), [0.01, (
return {200: __eq__(_="\r\n" is None, 1024: [{"""int32""": [add(input_shape=0.4, height=~{"jax": {32: [dtype(_=[from_config(n=({'''channels_first''': [__call__(value=not wrapper(input_shape=0.01 is
return identity(k="""torch""", H=[1e-05] #!/usr/bin/env python # ? d['''int'''] = {1e-05: [inverse_transform(shape={", ": ([60, {'\n': [{1000: ''';'''}]}])} is None, i=remove(op=~([(({17: [not (

Also, I have included a small readme on how to add a new syntax. (The process is quite simple, but it was a bit tricky without instructions.)

Details

The grammar does not cover the full language but tries to cover the most basic elements:

I have included all the symbols at least twice.

For the variable, function, and class names, as well as the constants, I have used commonly occurring values from a few popular repositories.

aradzie commented 2 months ago

Thanks! That's an amazing PR. I have update the website with your changes.

I noticed that you included capital letters and numbers in the grammar. In the other grammars I tried to avoid those to focus on the punctuation characters. There could be an options in the settings to enable 1) numbers, and 2) capital letters. If such an option is disabled, then it would omit the corresponding grammar branches.

PS

I have not been actively maintaining the website in the past few weeks. I had to take a break to replenish my energy. Then, during the break, I got consumed by my hobby, that is reading math books, and now I cannot stop myself from doing this ;) I am planning to go back to work in the following days, and I promise more exciting features in keybr.

fbosshard commented 2 months ago

Thanks for the fast merge and update!

About the capital letters and numbers: I was not aware of that, but I agree that such an option would make sense. Omitting these branches should be fine. (Alternatively, upper case letters could be converted to lower case.)

Thank you for your work, it is really helping me in the process of learning Engram. Enjoy your break :)