-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow optional capital letters and numbers in code Beta #295
base: master
Are you sure you want to change the base?
Conversation
And typo in static typed number literal
This commit modifies the source code generation grammars to allow the user to select whether capital letters and numbers should be added to a lesson while maintaining syntactically accurate generated code. It allows language-specific code conventions to be maintained such as only generating rust structs when capital letters are included, and allows for language-specific numeric literals.
This PR is a proof-of-concept just to start a conversation around the idea. It is not meant to be merged in this state. Personally I'm not overly happy with with how this refactor turned out. I was hoping that more of the grammar would be agnostic to capital letters and numbers, but it grew into what is basically 4 grammars per language. If this grammar approach ends up being used for optional capital letters and numbers it might be easier to separate the grammars into 4 files rather than have a single file for all versions. What I do like about this approach is that it maintains language idiocies in a way that I think would be hard or impossible if the capitalization and adding numbers were performed as a post-transformation. |
Omg, this feature is awesome! |
I am sorry for the late reply. I was having a really good streak while working on themes, did not want to interrupt myself. I was thinking about adding conditional grammar branches, similar to Rust conditional compilation. In Rust we can write
In Keybr we could write
Or, where this is not enough, we could mark a portion of grammar with a feature flag:
It is an experimental syntax straight out of my head, it does not exist yet:
(The underscore characters indicates optional whitespace.) Here the curly braces are used to wrap an optional list of rules. Each opening curly brace is followed by a feature flag name, then a list of rules, then a closing brace. The algorithm should scan all such feature flags in a grammar and present them to the user in the settings. If the user chooses to disable a feature, then the algorithm should just remove that fragment from the grammar. It should be as simple as removing a branch from a tree. The same syntax could be used for syntax highlighting:
or
Here we use curly braces with with different flags to mark a generated text fragment with color attributes. |
I am really eager to add more languages to keybr. That is a good PR! However, you mixed two different features in the same PR:
If you give me a PR with just new syntaxes, I will merge it right away. Then we could iterate on adding the remaining features. Thank you! |
0893185
to
2d468f8
Compare
0f2f968
to
97ece89
Compare
This commit modifies the source code generation grammars to allow the user to select whether capital letters and numbers should be added to a lesson while maintaining syntactically accurate generated code. It allows language-specific code conventions to be maintained such as only generating rust structs when capital letters are included, and allows for language-specific numeric literals.