Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Commit 279be8b

Browse files
committed
lang_lisp: poor's man identifier tagger
1 parent e0fb08f commit 279be8b

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

lang_lisp/analyze/highlight_lisp.ml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ let visit_toplevel ~tag_hook prefs (toplevel, toks) =
4747
Hashtbl.add already_tagged ii true
4848
)
4949
in
50-
5150
(* -------------------------------------------------------------------- *)
5251
(* ast phase 1 *)
5352
(* -------------------------------------------------------------------- *)
5453

5554
(* -------------------------------------------------------------------- *)
5655
(* toks phase 1 *)
5756
(* -------------------------------------------------------------------- *)
58-
5957
(*
6058
* note: all TCommentSpace are filtered in xs so easier to write
6159
* rules (but regular comments are kept as well as newlines).
@@ -93,6 +91,22 @@ let visit_toplevel ~tag_hook prefs (toplevel, toks) =
9391
);
9492
aux_toks (T.TComment ii3::T.TCommentNewline ii4::T.TComment ii5::xs)
9593

94+
(* Poor's man semantic tagger. Infer if ident is a func, or variable,
95+
* based on the few tokens around and the column information.
96+
*)
97+
| T.TOParen ii1::T.TIdent (s2, ii2)::T.TIdent (s3, ii3)::xs
98+
when PI.col_of_info ii1 = 0 ->
99+
(match s2 with
100+
| "setq" | "defvar" ->
101+
tag ii3 (Global (Def2 NoUse))
102+
| "defun" ->
103+
tag ii3 (Function (Def2 NoUse))
104+
| "defconst" ->
105+
tag ii3 (MacroVar (Def2 NoUse))
106+
| _ -> ()
107+
);
108+
aux_toks xs
109+
96110

97111
| x::xs ->
98112
aux_toks xs
@@ -136,16 +150,25 @@ let visit_toplevel ~tag_hook prefs (toplevel, toks) =
136150
(match s with
137151
| "defun"
138152
-> tag ii Keyword
139-
| "setq"
153+
154+
| "setq" | "defvar" | "let"
140155
-> tag ii KeywordObject (* hmm not really *)
141156

157+
| "defconst"
158+
-> tag ii KeywordObject
159+
160+
| "require" | "provide"
161+
-> tag ii KeywordModule
162+
142163
| "t" ->
143164
tag ii Boolean
144165
| "nil" ->
145166
tag ii Boolean (* or Null ? *)
146167

147168
| "cond" | "if" ->
148169
tag ii KeywordConditional
170+
| "while" | "do" ->
171+
tag ii KeywordLoop
149172

150173
| "concat"
151174
| "getenv"

0 commit comments

Comments
 (0)