revert: using code blocks makes simple calculations more annoying to write
This commit is contained in:
@@ -1,10 +1,29 @@
|
|||||||
use crate::common::{self, Context, Error};
|
use crate::common::{self, Context, Error};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
/// Evaluate a program written in the Lamm programming language
|
/// Evaluates a Lamm program
|
||||||
#[poise::command(prefix_command, aliases("lamm"))]
|
#[poise::command(slash_command, prefix_command, aliases("lamm"))]
|
||||||
pub async fn eval(ctx: Context<'_>, expr: poise::CodeBlock) -> Result<(), Error> {
|
pub async fn eval(ctx: Context<'_>,
|
||||||
let runtime = lamm::Runtime::new(Cursor::new(expr.code), "<eval>");
|
#[rest]
|
||||||
|
expr: String) -> Result<(), Error>
|
||||||
|
{
|
||||||
|
let expr = if expr.starts_with("```\n") {
|
||||||
|
expr.strip_prefix("```\n")
|
||||||
|
.and_then(|s| s.strip_suffix("```"))
|
||||||
|
.unwrap_or(&expr)
|
||||||
|
} else if expr.starts_with("```") {
|
||||||
|
expr.strip_prefix("```")
|
||||||
|
.and_then(|s| s.strip_suffix("```"))
|
||||||
|
.unwrap_or(&expr)
|
||||||
|
} else if expr.starts_with('`') {
|
||||||
|
expr.strip_prefix("`")
|
||||||
|
.and_then(|s| s.strip_suffix("`"))
|
||||||
|
.unwrap_or(&expr)
|
||||||
|
} else {
|
||||||
|
&expr
|
||||||
|
};
|
||||||
|
|
||||||
|
let runtime = lamm::Runtime::new(Cursor::new(expr), "<eval>");
|
||||||
|
|
||||||
let values = runtime.values()
|
let values = runtime.values()
|
||||||
.map(|res| res.map(|value| value.to_string()))
|
.map(|res| res.map(|value| value.to_string()))
|
||||||
|
|||||||
Reference in New Issue
Block a user