Blex3.h
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2| 1. <<< 基本字句解析 ver.3 (BLex3) >>>
3|***************************************************************************/
4|
5|#ifndef __BLEX3_H
6|#define __BLEX3_H
7|
8|
9|/*************************************************************************
10| 2. <<< 優先ヘッダ・ヘッダ設定 >>>
11|**************************************************************************/
12|#ifndef USES_PRIORITY_HEADER
13|/*[START_OF_PRIORITY_HEADER]*/
14|
15|#ifndef USES_BLEX3
16|#define USES_BLEX3
17|
18|typedef struct _BLex3 BLex3;
19|typedef struct _BLex3_Pos BLex3_Pos;
20|typedef struct _BLex3_Engine BLex3_Engine;
21|typedef struct _BLex3_EngineU BLex3_EngineU;
22|typedef enum _BLex3_BackMsgFlag BLex3_BackMsgFlag;
23|typedef enum _BLex3_BackMsg BLex3_BackMsg;
24|typedef enum _BLex3_Code BLex3_Code;
25|INF_TYPEDEF( _BLex3_Parser, BLex3_Parser );
26|
27|#endif
28|
29|/*[END_OF_PRIORITY_HEADER]*/
30|#endif
31|
32|
33|/*************************************************************************
34| 3. <<< エラーコード, リターンコード [BLex3_ByteCode] >>>
35|**************************************************************************/
36|
37|#define BLex3_Err_Some 0
38|#define BLex3_Err_InfinityLoop 9999
39|
40|/* ファイルポインタの位置 */
41|#define BLex3_EOF (-1)
42|#define BLex3_OutOfToken (-2)
43|#define BLex3_MiddleOfToken (-3)
44|#define BLex3_PosForNoEvent 0x7FFFFFFF
45|
46|/* Shift Jis 判定コード、バイト文字のタイプ */
47|#define BLex3_Ascii 0
48|#define BLex3_SJisFirst 1
49|#define BLex3_SJisSecond 2
50|#define BLex3_SJisUnknown 3
51|
52|enum _BLex3_Code {
53| BLex3_OK, /* 正常 */
54|};
55|
56|/*--------------------------------------------------------------*/
57|/*4. <<< Interface Area -------------------------------------- >>> */
58|/*--------------------------------------------------------------*/
59|
60|#ifdef __cplusplus
61|extern "C" {
62|#endif
63|
64|
65|/**************************************************************************
66| 5. <<< [BLex3_Pos] ファイル・アドレス >>>
67|【補足】
68|・BLex3_Engine_setPos 関数を使わないのであれば、ファイルアドレスの変数を
69| long 型にすることができます。その際 BLex3_Engine_getPos0 関数を使って
70| 現在のファイルポインタの位置を取得できます。そこからの相対値は、long 型の
71| 加減算で取得することができます。
72|***************************************************************************/
73|struct _BLex3_Pos {
74| long pos; /* ファイルアドレス */
75| int sjis_type; /* BLex3_ByteCode */
76|};
77|
78|extern BLex3_Pos BLex3_nullPos; /* 無効な位置 */
79|
80|void BLex3_Pos_init( BLex3_Pos* );
81|void BLex3_Pos_copy( BLex3_Pos* dst, BLex3_Pos* src );
82|
83|void BLex3_Pos_print( BLex3_Pos*, const char* );
84|
85|/**************************************************************************
86| 6. <<< [BLex3_Engine] 字句解析エンジン >>>
87|***************************************************************************/
88|struct _BLex3_Engine {
89| FILE* f;
90|
91| /* 内部バッファ領域 */
92| char* buf;
93| char* buf_over;
94| char* eof_first; /* buf_over と異なるとき、ファイルの末尾(EOF)の次のアドレス */
95| char* offset_over;
96| int sec_size; /* セクタサイズ, 2 の n 乗 */
97| int sec_sft; /* セクタサイズの lon2 */
98|
99| /* Shift Jis 判定用バッファ領域 */
100| char* sjis_buf; /* NULL: 使わない */
101|
102| /* ファイルポインタ */
103| BLex3_Pos pos; /* 通常のファイルポインタ(buf の先頭) */
104| char* fp; /* ファイルポインタに相当する内部バッファ内のアドレス */
105|};
106|
107|void BLex3_Engine_init( BLex3_Engine*, const char* path,
108| void* buf, int buf_size, int sec_size );
109|void BLex3_Engine_finish( BLex3_Engine* );
110|void BLex3_Engine_print( BLex3_Engine*, const char* title );
111|void BLex3_Engine_setSJisBuf( BLex3_Engine*, void* buf,
112| int buf_size );
113|
114|char* BLex3_Engine_getFilePtr( BLex3_Engine*, int offsetMax );
115|char* BLex3_Engine_getFilePtrByPos( BLex3_Engine*, long pos );
116|char* BLex3_Engine_getFilePtrByPos2( BLex3_Engine*, long pos );
117|char* BLex3_Engine_getOverPtr( BLex3_Engine* );
118|bool BLex3_Engine_isPtrEOF( BLex3_Engine*, char* fp );
119|char* BLex3_Engine_getSJisPtr( BLex3_Engine* );
120|
121|void BLex3_Engine_next( BLex3_Engine*, int n );
122|void BLex3_Engine_nextBuf( BLex3_Engine* );
123|void BLex3_Engine_nextByPtr( BLex3_Engine*, char* next_fp );
124|void BLex3_Engine_getPos( BLex3_Engine*, BLex3_Pos* );
125|int BLex3_Engine_getPos0( BLex3_Engine* );
126|void BLex3_Engine_getPos2( BLex3_Engine*, char* fp, BLex3_Pos* );
127|void BLex3_Engine_getPos3( BLex3_Engine*, int n, BLex3_Pos* );
128|void BLex3_Engine_getEndPos( BLex3_Engine*, BLex3_Pos* );
129|void BLex3_Engine_setPos( BLex3_Engine*, BLex3_Pos* );
130|void BLex3_Engine_setPos2( BLex3_Engine*, BLex3_Pos*, int n );
131|
132|void BLex3_Engine_copy( BLex3_Engine*, FILE* out,
133| BLex3_Pos* start, BLex3_Pos* over );
134|void BLex3_Engine_copyToHtml( BLex3_Engine*, FILE* out,
135| BLex3_Pos* start, BLex3_Pos* over );
136|
137|
138|/**************************************************************************
139| 7. <<< [BLex3_EngineU] 字句解析エンジン・ユーティリティ >>>
140|***************************************************************************/
141|struct _BLex3_EngineU {
142| BLex3_Engine inherit_BLex3_Engine;
143|};
144|void BLex3_EngineU_readWord( BLex3_EngineU*,
145| char* s, int s_size, const char* terms, bool bDQ );
146|void BLex3_EngineU_getStr( BLex3_EngineU*, BLex3_Pos* firstPos,
147| BLex3_Pos* overPos, char* s, int s_size );
148|void BLex3_EngineU_skip( BLex3_EngineU*, const char* skipChars );
149|void BLex3_EngineU_skipTo( BLex3_EngineU*, const char* terms, int plus );
150|void BLex3_EngineU_skipToStr( BLex3_EngineU*, const char* term, int plus,
151| bool bCase );
152|void BLex3_EngineU_skipTag( BLex3_EngineU* );
153|void BLex3_EngineU_write( BLex3_EngineU*, BLex3_Pos* firstPos,
154| BLex3_Pos* overPos, FILE* out );
155|void BLex3_EngineU_writeHTML( BLex3_EngineU*, BLex3_Pos* firstPos,
156| BLex3_Pos* overPos, int iLine, FILE* out );
157|void BLex3_EngineU_writeNoTag( BLex3_EngineU*, BLex3_Pos* firstPos,
158| BLex3_Pos* overPos, FILE* out );
159|
160|/**************************************************************************
161| 8. <<< (BLex3) 基本字句解析 ver.3 >>>
162|【補足】
163|・現在開発中です
164|***************************************************************************/
165|struct _BLex3 {
166| BLex3_EngineU engine;
167| ListX parsers;
168| ListX actors;
169| ListX conuters;
170|
171|/*
172| Progre progre;
173| VPrinter vprinter;
174|*/
175| bool bAssembling;
176| bool bCanceling;
177|
178| FILE* in;
179| FILE* out;
180| char in_path[_MAX_PATH];
181| char out_path[_MAX_PATH];
182|};
183|
184|/*type* BLex3_getParser( BLex3*, const char* symbol, type );*/
185|void BLex3_outHtmlText( BLex3*, const char* text );
186|
187|/**************************************************************************
188| 9. <<< [BLex3_BackMsgFlag, BLex3_BackMsg] バックメッセージ >>>
189|【補足】
190|・現在開発中です
191|***************************************************************************/
192|enum _BLex3_BackMsgFlag {
193| BLex3_BreakActLoop = 0x0001,
194| BLex3_BreakTokenLoop = 0x0002,
195| BLex3_BreakFileLoop = 0x0004,
196| BLex3_ReActor = 0x0100,
197|};
198|
199|enum _BLex3_BackMsg {
200| BLex3_BackToken /* 前方のトークンに戻る(ファイルポインタはアクターが戻す) */
201| = BLex3_BreakActLoop,
202| BLex3_ReParse /* もう一度字句解析する(アクターはファイルポインタを進めない) */
203| = BLex3_BreakActLoop,
204| BLex3_FirstActor /* 最初のアクターへ */
205| = BLex3_BreakActLoop | BLex3_ReActor,
206| BLex3_NextActor /* 次のアクターへ */
207| = 0,
208| BLex3_NextToken /* 次のトークンを字句解析する */
209| = BLex3_BreakActLoop,
210| BLex3_NextFile /* 編集をやめて次のファイルへ */
211| = BLex3_BreakActLoop | BLex3_BreakTokenLoop,
212| BLex3_Exit /* 編集をやめて次のファイルへ */
213| = BLex3_BreakActLoop | BLex3_BreakTokenLoop | BLex3_BreakFileLoop,
214|};
215|
216|/**************************************************************************
217| 10. <<< [BLex3_Parser] パーサ >>>
218|【補足】
219|・現在開発中です
220|・たとえば、HtmlPars がこのインターフェイスを持っています。
221|***************************************************************************/
222|void BLex3_Parser_finish( BLex3_Parser );
223|void BLex3_Parser_linkEngine( BLex3_Parser, BLex3_Engine* );
224|void BLex3_Parser_parse( BLex3_Parser );
225|int BLex3_Parser_getTokenType( BLex3_Parser );
226|void BLex3_Parser_getNextParsePos( BLex3_Parser, BLex3_Pos* pos );
227|void BLex3_Parser_printLastMsg( BLex3_Parser );
228|
229|struct _BLex3_Parser_Sc {
230| void (*finish)( void* );
231| int (*linkEngine)( void*, BLex3_Engine* );
232| void (*parse)( void* );
233| int (*getTokenType)( void* );
234| void (*getNextParsePos)( void*, BLex3_Pos* );
235| void (*printLastMsg)( void* );
236|};
237|
238|#ifdef __cplusplus
239|}
240|#endif
241|
242|/*--------------------------------------------------------------*/
243|/*11. <<< Mapping Area ---------------------------------------- >>> */
244|/*--------------------------------------------------------------*/
245|
246|
247|/**************************************************************************
248| 12. <<< [BLex3_Pos_init] ファイルの先頭に初期化する >>>
249|***************************************************************************/
250|#define BLex3_Pos_init( this ) \
251| ( (this)->pos = 0L, (this)->sjis_type = BLex3_Ascii)
252|
253|/**************************************************************************
254| 13. <<< [BLex3_Pos_copy] コピーする >>>
255|***************************************************************************/
256|#define BLex3_Pos_copy( dst, src ) \
257| *(dst) = *(src)
258|
259|/***********************************************************************
260| 14. <<< BLex3_Parser インターフェイス・マクロ定義 >>>
261|************************************************************************/
262|#ifdef NDEBUG
263|#define BLex3_Parser_finish(t) INF_MACRO_0( BLex3_Parser, finish, void, BLex3_Parser_finish, BLex3_Parser, t );
264|#define BLex3_Parser_linkEngine(t,a) INF_MACRO_1( BLex3_Parser, linkEngine, void, BLex3_Parser_linkEngine, BLex3_Parser, BLex3*, t,a );
265|#define BLex3_Parser_parse(t) INF_MACRO_0( BLex3_Parser, parse, void, BLex3_Parser_parse, BLex3_Parser, t );
266|#define BLex3_Parser_getTokenType(t) INF_MACRO_R0( BLex3_Parser, parse, int, BLex3_Parser_getTokenType, BLex3_Parser, t );
267|#define BLex3_Parser_getNextParsePos(t,a) INF_MACRO_1( BLex3_Parser, getNextParsePos, void, BLex3_Parser_getNextParsePos, BLex3_Parser, BLex3_Pos*, t,a );
268|#define BLex3_Parser_printLastMsg(t) INF_MACRO_1( BLex3_Parser, printLastMsg, void, BLex3_Parser_printLastMsg, BLex3_Parser, t );
269|#endif
270|
271|#endif
272|
273|