1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* General Public License, with the special exception on linking *)
|
|
|
|
(* described in file ../../../LICENSE. *)
|
1999-12-16 04:25:11 -08:00
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
2001-09-06 01:52:32 -07:00
|
|
|
open StdLabels
|
1999-11-30 06:59:39 -08:00
|
|
|
open Tk
|
|
|
|
open Jg_tk
|
|
|
|
open Parser
|
|
|
|
|
|
|
|
let tags =
|
|
|
|
["control"; "define"; "structure"; "char";
|
|
|
|
"infix"; "label"; "uident"]
|
|
|
|
and colors =
|
|
|
|
["blue"; "forestgreen"; "purple"; "gray40";
|
2000-03-17 01:17:45 -08:00
|
|
|
"indianred4"; "saddlebrown"; "midnightblue"]
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
let init_tags tw =
|
2000-04-11 20:43:25 -07:00
|
|
|
List.iter2 tags colors ~f:
|
1999-11-30 06:59:39 -08:00
|
|
|
begin fun tag col ->
|
2000-04-11 20:43:25 -07:00
|
|
|
Text.tag_configure tw ~tag ~foreground:(`Color col)
|
1999-11-30 06:59:39 -08:00
|
|
|
end;
|
2000-04-11 20:43:25 -07:00
|
|
|
Text.tag_configure tw ~tag:"error" ~foreground:`Red;
|
|
|
|
Text.tag_configure tw ~tag:"error" ~relief:`Raised;
|
|
|
|
Text.tag_raise tw ~tag:"error"
|
1999-11-30 06:59:39 -08:00
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let tag ?(start=tstart) ?(stop=tend) tw =
|
|
|
|
let tpos c = (Text.index tw ~index:start, [`Char c]) in
|
|
|
|
let text = Text.get tw ~start ~stop in
|
1999-11-30 06:59:39 -08:00
|
|
|
let buffer = Lexing.from_string text in
|
|
|
|
List.iter tags
|
2000-04-11 20:43:25 -07:00
|
|
|
~f:(fun tag -> Text.tag_remove tw ~start ~stop ~tag);
|
|
|
|
let last = ref (EOF, 0, 0) in
|
1999-11-30 06:59:39 -08:00
|
|
|
try
|
|
|
|
while true do
|
2000-04-11 20:43:25 -07:00
|
|
|
let token = Lexer.token buffer
|
|
|
|
and start = Lexing.lexeme_start buffer
|
|
|
|
and stop = Lexing.lexeme_end buffer in
|
1999-11-30 06:59:39 -08:00
|
|
|
let tag =
|
2000-04-11 20:43:25 -07:00
|
|
|
match token with
|
1999-11-30 06:59:39 -08:00
|
|
|
AMPERAMPER
|
|
|
|
| AMPERSAND
|
|
|
|
| BARBAR
|
|
|
|
| DO | DONE
|
|
|
|
| DOWNTO
|
|
|
|
| ELSE
|
|
|
|
| FOR
|
|
|
|
| IF
|
|
|
|
| LAZY
|
|
|
|
| MATCH
|
|
|
|
| OR
|
|
|
|
| THEN
|
|
|
|
| TO
|
|
|
|
| TRY
|
|
|
|
| WHEN
|
|
|
|
| WHILE
|
|
|
|
| WITH
|
|
|
|
-> "control"
|
|
|
|
| AND
|
|
|
|
| AS
|
|
|
|
| BAR
|
|
|
|
| CLASS
|
|
|
|
| CONSTRAINT
|
|
|
|
| EXCEPTION
|
|
|
|
| EXTERNAL
|
|
|
|
| FUN
|
|
|
|
| FUNCTION
|
|
|
|
| FUNCTOR
|
|
|
|
| IN
|
|
|
|
| INHERIT
|
|
|
|
| INITIALIZER
|
|
|
|
| LET
|
|
|
|
| METHOD
|
|
|
|
| MODULE
|
|
|
|
| MUTABLE
|
|
|
|
| NEW
|
|
|
|
| OF
|
|
|
|
| PRIVATE
|
|
|
|
| REC
|
|
|
|
| TYPE
|
|
|
|
| VAL
|
|
|
|
| VIRTUAL
|
|
|
|
-> "define"
|
|
|
|
| BEGIN
|
|
|
|
| END
|
|
|
|
| INCLUDE
|
|
|
|
| OBJECT
|
|
|
|
| OPEN
|
|
|
|
| SIG
|
|
|
|
| STRUCT
|
|
|
|
-> "structure"
|
|
|
|
| CHAR _
|
|
|
|
| STRING _
|
|
|
|
-> "char"
|
|
|
|
| BACKQUOTE
|
|
|
|
| INFIXOP1 _
|
|
|
|
| INFIXOP2 _
|
|
|
|
| INFIXOP3 _
|
|
|
|
| INFIXOP4 _
|
|
|
|
| PREFIXOP _
|
2000-03-17 01:17:45 -08:00
|
|
|
| SHARP
|
1999-11-30 06:59:39 -08:00
|
|
|
-> "infix"
|
|
|
|
| LABEL _
|
2000-04-11 20:43:25 -07:00
|
|
|
| OPTLABEL _
|
1999-11-30 06:59:39 -08:00
|
|
|
| QUESTION
|
2000-04-11 20:43:25 -07:00
|
|
|
| TILDE
|
1999-11-30 06:59:39 -08:00
|
|
|
-> "label"
|
|
|
|
| UIDENT _ -> "uident"
|
2000-04-11 20:43:25 -07:00
|
|
|
| LIDENT _ ->
|
|
|
|
begin match !last with
|
|
|
|
(QUESTION | TILDE), _, _ -> "label"
|
|
|
|
| _ -> ""
|
|
|
|
end
|
|
|
|
| COLON ->
|
|
|
|
begin match !last with
|
|
|
|
LIDENT _, lstart, lstop ->
|
|
|
|
if lstop = start then
|
|
|
|
Text.tag_add tw ~tag:"label"
|
|
|
|
~start:(tpos lstart) ~stop:(tpos stop);
|
|
|
|
""
|
|
|
|
| _ -> ""
|
|
|
|
end
|
1999-11-30 06:59:39 -08:00
|
|
|
| EOF -> raise End_of_file
|
|
|
|
| _ -> ""
|
|
|
|
in
|
|
|
|
if tag <> "" then
|
2000-04-11 20:43:25 -07:00
|
|
|
Text.tag_add tw ~tag ~start:(tpos start) ~stop:(tpos stop);
|
|
|
|
last := (token, start, stop)
|
1999-11-30 06:59:39 -08:00
|
|
|
done
|
|
|
|
with
|
|
|
|
End_of_file -> ()
|
|
|
|
| Lexer.Error (err, s, e) -> ()
|