Packages

A simple Lisp interpreter implemented in Gleam. Features a REPL, basic Lisp functionality including arithmetic operations, list manipulation, conditionals, and variable definitions.

Current section

Files

Jump to
glisp src glisp tokenizer.gleam
Raw

src/glisp/tokenizer.gleam

import gleam/list
import gleam/string
/// Tokenize a string into a list of tokens.
///
/// This function splits the input string into tokens, ensuring that parentheses
/// are treated as separate tokens.
///
/// ## Examples
///
/// ```gleam
/// tokenize("(add 1 2)") // -> ["(", "add", "1", "2", ")"]
/// ```
pub fn tokenize(source: String) -> List(String) {
let spaced = string.replace(source, "(", " ( ")
let spaced = string.replace(spaced, ")", " ) ")
string.split(spaced, " ")
|> list.filter(fn(s) { s != "" })
}