schala/src/schala_lang/builtin.rs

47 lines
797 B
Rust
Raw Normal View History

2018-02-23 19:06:37 -08:00
use std::rc::Rc;
#[derive(Debug, PartialEq, Clone)]
pub struct BinOp {
2018-02-24 14:39:45 -08:00
sigil: Rc<String>
2018-02-23 19:06:37 -08:00
}
#[derive(Debug, PartialEq, Clone)]
pub struct PrefixOp {
2018-02-24 14:39:45 -08:00
sigil: Rc<String>
2018-02-23 19:06:37 -08:00
}
impl BinOp {
pub fn from_sigil(sigil: Rc<String>) -> BinOp {
BinOp { sigil }
}
2018-02-24 14:39:45 -08:00
pub fn sigil(&self) -> &Rc<String> {
&self.sigil
}
2018-02-23 19:06:37 -08:00
pub fn min_precedence() -> i32 {
i32::min_value()
}
pub fn get_precedence(op: &str) -> i32 {
match op {
"+" | "-" => 10,
"*" | "/" | "%" => 20,
_ => 30,
}
}
}
impl PrefixOp {
pub fn from_sigil(sigil: Rc<String>) -> PrefixOp {
PrefixOp { sigil }
}
2018-02-24 14:39:45 -08:00
pub fn sigil(&self) -> &Rc<String> {
&self.sigil
}
2018-02-23 19:06:37 -08:00
pub fn is_prefix(op: &str) -> bool {
match op {
"+" | "-" | "!" | "~" => true,
_ => false,
}
}
}