From 24089da788c62b2ee710144f9a038b7af096c178 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 12 Aug 2019 13:49:39 -0700 Subject: [PATCH] Mapping names to builtins --- schala-lang/language/src/builtin.rs | 43 +++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/builtin.rs b/schala-lang/language/src/builtin.rs index 7eea68f..3927d99 100644 --- a/schala-lang/language/src/builtin.rs +++ b/schala-lang/language/src/builtin.rs @@ -1,5 +1,6 @@ use std::rc::Rc; use std::collections::HashMap; +use std::str::FromStr; use crate::tokenizing::TokenKind; use crate::typechecking::{TypeConst, Type}; @@ -8,7 +9,6 @@ use crate::typechecking::{TypeConst, Type}; enum Builtin { Add, Subtract, - Negate, Multiply, Divide, Quotient, @@ -21,14 +21,51 @@ enum Builtin { BooleanNot, Equality, LessThan, - LessThanEquals, + LessThanOrEqual, GreaterThan, - GreaterThanEquals, + GreaterThanOrEqual, Comparison, FieldAccess, IOPrint, IOPrintLn, IOGetLine, + Assignment, + Concatenate, +} + +impl FromStr for Builtin { + type Err = (); + + fn from_str(s: &str) -> Result { + use Builtin::*; + Ok(match s { + "+" => Add, + "-" => Subtract, + "*" => Multiply, + "/" => Divide, + "quot" => Quotient, + "%" => Modulo, + "++" => Concatenate, + "^" => Exponentiation, + "&" => BitwiseAnd, + "&&" => BooleanAnd, + "|" => BitwiseOr, + "||" => BooleanOr, + "!" => BooleanNot, + ">" => GreaterThan, + ">=" => GreaterThanOrEqual, + "<" => LessThan, + "<=" => LessThanOrEqual, + "==" => Equality, + "=" => Assignment, + "<=>" => Comparison, + "." => FieldAccess, + "print" => IOPrint, + "println" => IOPrintLn, + "getline" => IOGetLine, + _ => return Err(()) + }) + } } #[derive(Debug, PartialEq, Clone)]