Skip to content

Commit

Permalink
implemented MTH and TH parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hariseldon78 committed Dec 26, 2024
1 parent 022ffa7 commit 89281eb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions rmk-macro/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,54 @@ fn parse_key(key: String) -> TokenStream2 {
::rmk::df!(#layer)
}
}
"MTH(" => {
let keys: Vec<&str> = key
.trim_start_matches("MTH(")
.trim_end_matches(")")
.split_terminator(",")
.map(|w| w.trim())
.filter(|w| w.len() > 0)
.collect();
if keys.len() != 2 {
return quote! {
compile_error!("keyboard.toml: MTH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html");
};
}
let ident = format_ident!("{}", keys[0].to_string());

let (right, gui, alt, shift, ctrl) = parse_modifiers(keys[1]);

if (gui || alt || shift || ctrl) == false {
return quote! {
compile_error!("keyboard.toml: modifier in MTH(modifier, key) is not valid! Please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html");
};
}
quote! {
::rmk::mth!(#ident, ::rmk::keycode::ModifierCombination::new_from(#right, #gui, #alt, #shift, #ctrl))
}

}
"TH(" => {
let keys: Vec<&str> = key
.trim_start_matches("TH(")
.trim_end_matches(")")
.split_terminator(",")
.map(|w| w.trim())
.filter(|w| w.len() > 0)
.collect();
if keys.len() != 2 {
return quote! {
compile_error!("keyboard.toml: TH(modifiers, key) invalid, please check the documentation: https://haobogu.github.io/rmk/keyboard_configuration.html");
};
}
let ident1 = format_ident!("{}", keys[0].to_string());
let ident2 = format_ident!("{}", keys[1].to_string());

quote! {
::rmk::th!(#ident1, #ident2)
}

}
_ => {
let ident = format_ident!("{}", key);
quote! {::rmk::k!(#ident) }
Expand Down
4 changes: 2 additions & 2 deletions rmk/src/layout_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! lt {
/// Create a modifier-tap-hold action
#[macro_export]
macro_rules! mth {
($m: expr, $k: ident) => {
($k: ident, $m: expr) => {
$crate::action::KeyAction::ModifierTapHold(
$m,
$crate::action::Action::Key($crate::keycode::KeyCode::$k),
Expand All @@ -74,7 +74,7 @@ macro_rules! mth {
/// Create a tap-hold action
#[macro_export]
macro_rules! th {
($h: ident, $t: ident) => {
($t: ident, $h: ident) => {
$crate::action::KeyAction::TapHold(
$t,
$h,
Expand Down

0 comments on commit 89281eb

Please sign in to comment.