Skip to content

Commit

Permalink
Add boolean type.
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Dec 13, 2023
1 parent 0871549 commit 4378c35
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ opt-level = 3

[lints]
clippy.useless_format = "allow"
rust.missing_docs = "warn"
rust.missing_docs = "warn"
5 changes: 5 additions & 0 deletions src/builtin_parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ pub enum Token {
#[token(",")]
Comma,

#[token("true")]
True,
#[token("false")]
False,

#[regex(r#""(\\[\\"]|[^"])*""#)]
String,

Expand Down
3 changes: 3 additions & 0 deletions src/builtin_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum Expression {
arguments: Vec<Spanned<Expression>>,
},
Object(HashMap<String, Spanned<Expression>>),
Boolean(bool),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -293,6 +294,8 @@ fn parse_primary(
Some(Ok(Token::Number)) => {
Ok(tokens.wrap_span(Expression::Number(tokens.slice().parse().unwrap())))
}
Some(Ok(Token::True)) => Ok(tokens.wrap_span(Expression::Boolean(true))),
Some(Ok(Token::False)) => Ok(tokens.wrap_span(Expression::Boolean(false))),
Some(Ok(token)) => Err(ParseError::UnexpectedToken(tokens.wrap_span(token))),
Some(Err(FailedToLexCharacter)) => Err(ParseError::FailedToLexCharacter(tokens.span())),
None => unreachable!("oh fuck what have i done to cause this to happen"),
Expand Down
4 changes: 3 additions & 1 deletion src/builtin_parser/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ fn eval_expression(
}
}
Expression::None => Ok(Value::None),
Expression::Boolean(bool) => Ok(Value::Boolean(bool)),
Expression::Function { name, arguments } => {
environment.function_scope(&name, move |environment, function| {
(function.body)(
Expand Down Expand Up @@ -463,7 +464,8 @@ fn set_resource(
let mut dyn_struct = DynamicStruct::default();
for (key, value) in map.into_iter() {
match Rc::try_unwrap(value).unwrap().into_inner() {
Value::None => {}
Value::None => dyn_struct.insert(&key, ()),
Value::Boolean(boolean) => dyn_struct.insert(&key, boolean),
Value::Number(number) => dyn_struct.insert(&key, number),
Value::String(string) => dyn_struct.insert(&key, string.clone()),
Value::Reference(..) => todo!("todo reference"),
Expand Down
3 changes: 3 additions & 0 deletions src/builtin_parser/runner/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum Value {
None,
/// A number, for simplicity only f64s are used. (However this will probably change in the future)
Number(f64),
/// `true` or `false`. Thats it...
Boolean(bool),
/// A string... there isn't much to say about this one.
String(String),
/// A reference.
Expand Down Expand Up @@ -51,6 +53,7 @@ impl Value {
match self {
Value::None => Ok(format!("()")),
Value::Number(number) => Ok(format!("{number}")),
Value::Boolean(bool) => Ok(format!("{bool}")),
Value::String(string) => Ok(format!("\"{string}\"")),
Value::Reference(reference) => {
if let Some(rc) = reference.upgrade() {
Expand Down

0 comments on commit 4378c35

Please sign in to comment.