Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Clojure source code one token at a time

Tags:

clojure

In Clojure, it's possible to read a whole s-expression with (read). Is there some way to read just one token at a time? So calling (read-token "(read)") would return something like ["(", "read", ")"].

like image 447
Michael Dickens Avatar asked Feb 24 '26 02:02

Michael Dickens


1 Answers

"tokens" are not something that the clojure reader works with: it doesn't have distinct lex/parse phases like languages with more complicated grammars often do. Of course you can write your own grammar for clojure forms, call ( an OPEN_PAREN token and so on, but there's no built-in support for it.

like image 200
amalloy Avatar answered Feb 27 '26 03:02

amalloy