Skip to content

Commit

Permalink
add current keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
PokeJofeJr4th committed Dec 1, 2023
1 parent f1cc4ae commit 54247fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ print next_score! // 6
print score! // 16
```

Finally, the `current` keyword lets you see into the present!

```c
const var score = 5!
print(current score)! //5
```
## Standard Library
> #### New for October 2023!
Expand Down
4 changes: 4 additions & 0 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ fn interpret_function(func: &Pointer, args: &[Syntax], state: RcMut<State>) -> S
None => Ok(state.borrow().undefined.clone())
}
}
Value::Keyword(Keyword::Current) => {
let [arg] = args else {return Err(String::from("`current` keyword requires one argument"))};
inner_interpret(arg, state)
}
Value::Keyword(Keyword::Next) => {
let [arg] = args else { return Err(String::from("`next` keyword requires one argument")) };
let evaluated = inner_interpret(arg, state)?;
Expand Down
1 change: 1 addition & 0 deletions src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl State {
kw!(current "class" => Keyword::Class);
kw!(current "className" => Keyword::Class);
kw!(current "const" => Keyword::Const);
kw!(current "current" => Keyword::Current);
kw!(current "delete" => Keyword::Delete);
kw!(current "eval" => Keyword::Eval);
kw!(current "false" => false);
Expand Down
2 changes: 2 additions & 0 deletions src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ impl From<Boolean> for Value {
pub enum Keyword {
Class,
Const,
Current,
Delete,
Eval,
Forget,
Expand All @@ -418,6 +419,7 @@ impl Display for Keyword {
match self {
Self::Class => write!(f, "class"),
Self::Const => write!(f, "const"),
Self::Current => write!(f, "current"),
Self::Eval => write!(f, "eval"),
Self::Delete => write!(f, "delete"),
Self::Forget => write!(f, "forget"),
Expand Down

0 comments on commit 54247fd

Please sign in to comment.