Skip to content

Commit

Permalink
Clojure: skip metadata in namespace definition
Browse files Browse the repository at this point in the history
Close universal-ctags#1657.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Apr 20, 2018
1 parent 43faa71 commit 9342384
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions Units/parser-clojure.r/broken-ns.d/input-0.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns ^abc
1 change: 1 addition & 0 deletions Units/parser-clojure.r/broken-ns.d/input-1.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns ^abc
1 change: 1 addition & 0 deletions Units/parser-clojure.r/broken-ns.d/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns ^{:doc "Document"}
1 change: 1 addition & 0 deletions Units/parser-clojure.r/clojure-metadata-in-ns.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
24 changes: 24 additions & 0 deletions Units/parser-clojure.r/clojure-metadata-in-ns.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ns0 input.clj /^(ns ^{:doc "Utility functions."} ns0)$/;" n
debug0? input.clj /^(defn debug0? ^boolean$/;" f namespace:ns0
ns1 input-0.clj /^(ns ^:dynamic ns1)$/;" n
debug1? input-0.clj /^(defn debug1? ^boolean$/;" f namespace:ns1
ns2 input-0.clj /^(ns ^String ns2)$/;" n
debug2? input-0.clj /^(defn debug2? ^boolean$/;" f namespace:ns2
ns00 input-0.clj /^(ns ^{:doc "Utility functions."} ^{:doc1 "something"} ns00)$/;" n
debug00? input-0.clj /^(defn debug00? ^boolean$/;" f namespace:ns00
ns01 input-0.clj /^(ns ^{:doc "Utility functions."} ^:dynamic ns01)$/;" n
debug01? input-0.clj /^(defn debug01? ^boolean$/;" f namespace:ns01
ns02 input-0.clj /^(ns ^{:doc "Utility functions."} ^String ns02)$/;" n
debug02? input-0.clj /^(defn debug02? ^boolean$/;" f namespace:ns02
ns10 input-0.clj /^(ns ^:dynamic ^{:doc "Utility functions."} ns10)$/;" n
debug10? input-0.clj /^(defn debug10? ^boolean$/;" f namespace:ns10
ns11 input-0.clj /^(ns ^:dynamic ^:dynamic-something ns11)$/;" n
debug11? input-0.clj /^(defn debug11? ^boolean$/;" f namespace:ns11
ns12 input-0.clj /^(ns ^:dynamic ^String ns12)$/;" n
debug12? input-0.clj /^(defn debug12? ^boolean$/;" f namespace:ns12
ns20 input-0.clj /^(ns ^String ^{:doc "Utility functions."} ns20)$/;" n
debug20? input-0.clj /^(defn debug20? ^boolean$/;" f namespace:ns20
ns21 input-0.clj /^(ns ^String ^:dynamic ns21)$/;" n
debug21? input-0.clj /^(defn debug21? ^boolean$/;" f namespace:ns21
ns22 input-0.clj /^(ns ^String ^String-something ns22)$/;" n
debug22? input-0.clj /^(defn debug22? ^boolean$/;" f namespace:ns22
55 changes: 55 additions & 0 deletions Units/parser-clojure.r/clojure-metadata-in-ns.d/input-0.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
(ns ^:dynamic ns1)
(defn debug1? ^boolean
[]
goog.DEBUG)

(ns ^String ns2)
(defn debug2? ^boolean
[]
goog.DEBUG)

(ns ^{:doc "Utility functions."} ^{:doc1 "something"} ns00)
(defn debug00? ^boolean
[]
goog.DEBUG)

(ns ^{:doc "Utility functions."} ^:dynamic ns01)
(defn debug01? ^boolean
[]
goog.DEBUG)

(ns ^{:doc "Utility functions."} ^String ns02)
(defn debug02? ^boolean
[]
goog.DEBUG)


(ns ^:dynamic ^{:doc "Utility functions."} ns10)
(defn debug10? ^boolean
[]
goog.DEBUG)

(ns ^:dynamic ^:dynamic-something ns11)
(defn debug11? ^boolean
[]
goog.DEBUG)

(ns ^:dynamic ^String ns12)
(defn debug12? ^boolean
[]
goog.DEBUG)

(ns ^String ^{:doc "Utility functions."} ns20)
(defn debug20? ^boolean
[]
goog.DEBUG)

(ns ^String ^:dynamic ns21)
(defn debug21? ^boolean
[]
goog.DEBUG)

(ns ^String ^String-something ns22)
(defn debug22? ^boolean
[]
goog.DEBUG)
5 changes: 5 additions & 0 deletions Units/parser-clojure.r/clojure-metadata-in-ns.d/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;; Taken from #1657 opened by @arichiardi
(ns ^{:doc "Utility functions."} ns0)
(defn debug0? ^boolean
[]
goog.DEBUG)
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions parsers/clojure.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,43 @@ static void functionName (vString * const name, const char *dbp)
vStringPut (name, *p);
}

const char* skipMetadata (const char *dbp)
{
while (1)
{
if (*dbp == '^')
{
dbp++;
if (*dbp == '{')
{
/* skipping an arraymap */
for (; *dbp != '\0' && *dbp != '}'; dbp++)
;
}
else
{
/* skip a keyword or a symbol */
for (; *dbp != '\0' && !isspace((unsigned char)*dbp); dbp++)
;
}

if (*dbp == '\0')
break;

dbp++;
while (isspace ((unsigned char)*dbp))
dbp++;
}
else
break;
}

return dbp;
}

static int makeNamespaceTag (vString * const name, const char *dbp)
{
dbp = skipMetadata (dbp);
functionName (name, dbp);
if (vStringLength (name) > 0 && ClojureKinds[K_NAMESPACE].enabled)
{
Expand Down

0 comments on commit 9342384

Please sign in to comment.