diff --git a/schala-lang/language/src/builtin.rs b/schala-lang/language/src/builtin.rs index 6093fc9..afca3f7 100644 --- a/schala-lang/language/src/builtin.rs +++ b/schala-lang/language/src/builtin.rs @@ -110,6 +110,20 @@ pub struct BinOp { pub builtin: Option, } +fn token_kind_to_sigil<'a>(tok: &'a TokenKind) -> Option<&'a str> { + use self::TokenKind::*; + Some(match tok { + Operator(op) => op.as_str(), + Period => ".", + Pipe => "|", + Slash => "/", + LAngleBracket => "<", + RAngleBracket => ">", + Equals => "=", + _ => return None + }) +} + impl BinOp { pub fn from_sigil(sigil: &str) -> BinOp { let builtin = Builtin::from_str(sigil).ok(); @@ -119,35 +133,15 @@ impl BinOp { &self.sigil } pub fn from_sigil_token(tok: &TokenKind) -> Option { - use self::TokenKind::*; - let s = match tok { - Operator(op) => op, - Period => ".", - Pipe => "|", - Slash => "/", - LAngleBracket => "<", - RAngleBracket => ">", - Equals => "=", - _ => return None - }; + let s = token_kind_to_sigil(tok)?; Some(BinOp::from_sigil(s)) } pub fn min_precedence() -> i32 { i32::min_value() } - pub fn get_precedence_from_token(op: &TokenKind) -> Option { - use self::TokenKind::*; - let s = match op { - Operator(op) => op, - Period => ".", - Pipe => "|", - Slash => "/", - LAngleBracket => "<", - RAngleBracket => ">", - Equals => "=", - _ => return None - }; + pub fn get_precedence_from_token(op_tok: &TokenKind) -> Option { + let s = token_kind_to_sigil(op_tok)?; let default = 10_000_000; Some(BINOPS.get(s).map(|x| x.2.clone()).unwrap_or_else(|| { default