OSDN Git Service

コア部分を共通プロジェクト化した
[fooeditengine/FooEditEngine.git] / Core / IHilighter.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11 using System;
12
13 namespace FooEditEngine
14 {
15     /// <summary>
16     /// トークンのタイプを表す
17     /// </summary>
18     public enum TokenType
19     {
20         /// <summary>
21         /// どのカテゴリーにも属さないトークンを表す
22         /// </summary>
23         None = 0,
24         /// <summary>
25         /// キーワード1として表示するトークンを表す
26         /// </summary>
27         Keyword1,
28         /// <summary>
29         /// キーワード2として表示するトークンを表す
30         /// </summary>
31         Keyword2,
32         /// <summary>
33         /// コメントとして表示するトークンを表す
34         /// </summary>
35         Comment,
36         /// <summary>
37         /// 文字リテラルとして表示するトークンを表す
38         /// </summary>
39         Literal,
40         /// <summary>
41         /// コントロールとして表示するトークンを表す
42         /// </summary>
43         Control,
44     }
45
46     /// <summary>
47     /// イベントデータを表す
48     /// </summary>
49     public class TokenSpilitEventArgs
50     {
51         /// <summary>
52         /// 単語長
53         /// </summary>
54         public int length;
55         /// <summary>
56         /// トークンのタイプ
57         /// </summary>
58         public TokenType type;
59         /// <summary>
60         /// トークンの切り出しをやめるなら真をセットし、そうでないなら偽をセットする(規定値は偽)
61         /// </summary>
62         public bool breaked;
63         /// <summary>
64         /// トークンがあるインデックス
65         /// </summary>
66         public int index;
67
68         /// <summary>
69         /// コンストラクター
70         /// </summary>
71         public TokenSpilitEventArgs()
72         {
73         }
74
75         /// <summary>
76         /// コンストラクター
77         /// </summary>
78         /// <param name="index">開始インデックス</param>
79         /// <param name="length">長さ</param>
80         /// <param name="type">トークンタイプ</param>
81         public TokenSpilitEventArgs(int index,int length, TokenType type)
82         {
83             this.length = length;
84             this.type = type;
85             this.index = index;
86             this.breaked = false;
87         }
88     }
89
90     /// <summary>
91     /// トークンが切り出された時に呼ばれるイベント
92     /// </summary>
93     /// <param name="state">イベントデータ</param>
94     /// <returns></returns>
95     public delegate void TokenSpilitHandeler(TokenSpilitEventArgs state);
96
97     /// <summary>
98     /// シンタックスハイライトを行うためのインターフェイス
99     /// </summary>
100     public interface IHilighter
101     {
102         /// <summary>
103         /// 初期状態に戻す
104         /// </summary>
105         void Reset();
106
107         /// <summary>
108         /// ハイライト処理を実行します
109         /// </summary>
110         /// <param name="text">対象となる文字列</param>
111         /// <param name="length">文字列の長さ</param>
112         /// <param name="action">トークンが切り出されたときに呼び出されるデリゲート</param>
113         /// <returns>エンクロージャーレベル。開始エンクロージャーだけを検出した場合は1以上の値を返し、
114         /// 終了エンクロージャーだけを検出した場合を-1以下の値を返すようにします。
115         /// 何も検出しなかった場合、開始エンクロージャーと終了エンクロージャーが対になっている場合、
116         /// エンクロージャー内で開始エンクロージャーを検出した場合は0を返します
117         /// なお、開始エンクロージャーがすでに検出されている状態で検出したことを返した場合、その結果は無視されます
118         /// </returns>
119         /// <example>
120         /// int DoHilight(string text,int length, TokenSpilitHandeler action)
121         /// {
122         ///     if(length > 3 &amp;&amp; text == "foo")
123         ///         action(new TokenSpilitEventArgs(0,3,TokenType.Keyword1);
124         ///     return 0;
125         /// }
126         /// </example>
127         int DoHilight(string text,int length, TokenSpilitHandeler action);
128     }
129 }