Skip to content

Commit

Permalink
add token ns
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostandthemachine committed Aug 30, 2012
1 parent 4303401 commit 98e5782
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/sketchpad/buffer/token.clj
@@ -0,0 +1,52 @@
(ns sketchpad.buffer.token
(:require [sketchpad.util.tab :as tab]
[seesaw.core :as seesaw])
(:import (org.fife.ui.rsyntaxtextarea.RSyntaxUtilities)))

(defn token-list-for-line
"Returns the token list for a given line."
([] (token-list-for-line (tab/current-text-area)))
([text-area]
(let [doc (.getDocument text-area)
line (.getCaretLine text-area)
token (.getTokenListForLine doc line)]
token)))

(defn current-token
"Returns the Token object for the current token."
([] (current-token (tab/current-text-area)))
([text-area]
(let [doc (.getDocument text-area)
line (.getCaretLine text-area)
token (.getTokenListForLine doc line)
dot (.getCaretPosition text-area)
cur-token (org.fife.ui.rsyntaxtextarea.RSyntaxUtilities/getTokenAtOffset token dot)]
cur-token)))

(defn line-token
([] (line-token (tab/current-text-area)))
([text-area]
(let [list-from-line (token-list-for-line text-area)
token-list (atom [(.getLexeme list-from-line)])]
(loop [t list-from-line]
(when-not (nil? (.getNextToken t))
(swap! token-list (fn [tl] (conj tl (.getLexeme t))))
(recur (.getNextToken t))))
@token-list)))

(defn- file-exists?
[possible-path]
(let [f (clojure.java.io/file possible-path)]
(.exists f)))

(defn- is-number?
[possible-number]
(=
(type (load-string possible-number))
java.lang.Long))

(defn- can-be-opened?
[line-tokens]
(and
(file-exists? (first line-tokens))
(is-number? (second line-tokens))))

0 comments on commit 98e5782

Please sign in to comment.