aboutsummaryrefslogtreecommitdiff
path: root/src/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lisp')
-rw-r--r--src/lisp/eval.rs28
-rw-r--r--src/lisp/lex.rs1
2 files changed, 29 insertions, 0 deletions
diff --git a/src/lisp/eval.rs b/src/lisp/eval.rs
index b39730b..784cba0 100644
--- a/src/lisp/eval.rs
+++ b/src/lisp/eval.rs
@@ -20,6 +20,15 @@ pub struct Evaluator<'ctx, 'global> {
20 pub context: Context, 20 pub context: Context,
21} 21}
22 22
23impl<'ctx, 'global> Evaluator<'ctx, 'global> {
24 pub fn new(app: &'global mut AppState<'ctx>) -> Self {
25 Self {
26 app,
27 context: Vec::new(),
28 }
29 }
30}
31
23impl<'ctx, 'global> Evaluator<'ctx, 'global> 32impl<'ctx, 'global> Evaluator<'ctx, 'global>
24where 33where
25 'ctx: 'global, 34 'ctx: 'global,
@@ -337,6 +346,25 @@ pub fn lookup(env_list: &[Environment], key: &str) -> Result<LispExpr, LispError
337 } 346 }
338} 347}
339 348
349pub fn completions<'a>(env_list: &'a [Environment], prefix: &str) -> Vec<&'a str> {
350 fn helper<'h>(env_list: &'h [Environment], prefix: &str, completions: &mut Vec<Vec<&'h str>>) {
351 if !env_list.is_empty() {
352 let nearest_env = env_list.last().unwrap();
353 completions.push(
354 nearest_env
355 .keys()
356 .filter(|k| k.starts_with(prefix))
357 .map(|s| &s[prefix.len()..])
358 .collect::<Vec<_>>(),
359 );
360 helper(&env_list[..env_list.len() - 1], prefix, completions);
361 }
362 }
363 let mut completions = Vec::new();
364 helper(env_list, prefix, &mut completions);
365 completions.into_iter().flatten().collect()
366}
367
340#[cfg(test)] 368#[cfg(test)]
341mod tests { 369mod tests {
342 use super::*; 370 use super::*;
diff --git a/src/lisp/lex.rs b/src/lisp/lex.rs
index 754a23f..6e59469 100644
--- a/src/lisp/lex.rs
+++ b/src/lisp/lex.rs
@@ -235,6 +235,7 @@ fn parse_string(input: &str) -> Result<(usize, Token<'_>), ParseErrorKind> {
235 235
236fn is_ident(ch: char) -> bool { 236fn is_ident(ch: char) -> bool {
237 match ch { 237 match ch {
238 // "!$%&*+-./<=>?^_|#"
238 '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | '<' | '=' | '>' | '?' | '^' | '_' 239 '!' | '$' | '%' | '&' | '*' | '+' | '-' | '.' | '/' | '<' | '=' | '>' | '?' | '^' | '_'
239 | '|' | '#' => true, 240 | '|' | '#' => true,
240 _ if ch.is_alphanumeric() => true, 241 _ if ch.is_alphanumeric() => true,