Mapping names to builtins

This commit is contained in:
greg 2019-08-12 13:49:39 -07:00
parent bfb36b90e4
commit 24089da788
1 changed files with 40 additions and 3 deletions

View File

@ -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<Self, Self::Err> {
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)]