-
Notifications
You must be signed in to change notification settings - Fork 131
keysyms: Check clashes between keysyms names and keywords #598
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
keysyms: Check clashes between keysyms names and keywords #598
Conversation
076fbf2
to
177cf71
Compare
177cf71
to
cc68776
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Perhaps also add a comment on this line? |
Due to how our parser is implemented, keysyms names that are also valid keywords require special handling. Added a check for these clashes in the keysym generator. The only current clash, `section`, is already handled. Note that it means that e.g. `section`, `Section` and `sEcTiOn` all parse to the same keysym. This side effect is fine here, because *currently* there is no other keysym that clashes with any possible of the case variation of `section`. But in order to be extra cautious, we now test thoses clashes too. Hopefully we will never have a clash again, but while it is unlikely that we modify the keywords, the keysyms are not a frozen set.
cc68776
to
d5e3386
Compare
@bluetech Good point, added. As a general note, if I had to rewrite the parser, I would opt for the “parse, don’t validate” approach. I wonder if it would make sense to switch to using Tree-sitter someday. I would love to get as a bonus correct syntax highlighting for XKB files. |
The article is really good. But a yacc grammar is pretty much "parse" no? I'm curious which part you consider the "validate". |
Maybe these days there is an AI clever enough to translate a yacc grammar to a tree-sitter grammar. In my experience they are quite good with translations like this. |
@bluetech My point is that we use a bunch of xkb_keymap { };
xkb_keycodes { };
xkb_types {
type "XXX" {
modifiers[1234] = Shift;
map[Shift] = Level2;
level_name[Level1] = "Base";
level_name[Level2] = "Number";
};
};
xkb_compat { };
xkb_symbols { };
}; You would just get the following warning, without any reference to the erroneous line:
Imagine now having this in an included key type file: really not ideal for debugging. But at this stage we do not have parser context anymore! On the other hand, the following file will fail with a better (but still incomplete1) error2:
That said, I guess that fully parsing a section is slower than the current approach so any include would get slower with the parse, don’t validate approach applied strictly. Footnotes |
Due to how our parser is implemented, keysyms names that are also valid keywords require special handling.
Added a check for these clashes in the keysym generator. The only current clash,
section
, is already handled. Note that it means thatsection
,Section
,sEcTiOn
all parse to the same keysym.Hopefully we will never have a clash again, but the keysyms are not a frozen set.
I got puzzled by the following excerpt in
parser.y
and decided to investigate.