Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4303401
commit 98e5782
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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)))) |