OSDN Git Service

add tokenchecker_endinput.
[bbk/bchan.git] / src / parselib.h
1 /*
2  * parselib.h
3  *
4  * Copyright (c) 2009-2011 project bchan
5  *
6  * This software is provided 'as-is', without any express or implied
7  * warranty. In no event will the authors be held liable for any damages
8  * arising from the use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software. If you use this software
16  *    in a product, an acknowledgment in the product documentation would be
17  *    appreciated but is not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  *    misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source
23  *    distribution.
24  *
25  */
26
27 #include        <basic.h>
28
29 #ifndef __PARSELIB_H__
30 #define __PARSELIB_H__
31
32 typedef struct tokenchecker_valuetuple_t_ tokenchecker_valuetuple_t;
33 struct tokenchecker_valuetuple_t_ {
34         B *name;
35         W val;
36 };
37
38 typedef struct  tokenchecker_t_ tokenchecker_t;
39 struct  tokenchecker_t_ {
40         tokenchecker_valuetuple_t *namelist;
41         W namelistnum;
42         B *endtokens;
43         W stringindex;
44         W listindex_start;
45         W listindex_end;
46         W flag;
47 };
48
49 enum {
50         TOKENCHECKER_CONTINUE,
51         TOKENCHECKER_CONTINUE_NOMATCH,
52         TOKENCHECKER_DETERMINE,
53         TOKENCHECKER_NOMATCH,
54         TOKENCHECKER_AFTER_END
55 };
56
57 IMPORT VOID tokenchecker_initialize(tokenchecker_t *checker, tokenchecker_valuetuple_t *namelist, W namelistnum, B *endchars);
58 IMPORT VOID tokenchecker_finalize(tokenchecker_t *checker);
59 IMPORT VOID tokenchecker_clear(tokenchecker_t *checker);
60 IMPORT W tokenchecker_inputchar(tokenchecker_t *checker, UB c, W *val);
61 IMPORT W tokenchecker_endinput(tokenchecker_t *checker, W *val);
62 IMPORT VOID tokenchecker_getlastmatchedstring(tokenchecker_t *checker, UB **str, W *len);
63
64 typedef struct charreferparser_t_ charreferparser_t;
65 struct charreferparser_t_ {
66         enum {
67                 START,
68                 RECIEVE_AMP,
69                 RECIEVE_NUMBER,
70                 NUMERIC_DECIMAL,
71                 NUMERIC_HEXADECIMAL,
72                 NAMED,
73                 INVALID,
74                 DETERMINED
75         } state;
76         tokenchecker_t named;
77         W charnumber;
78 };
79
80 typedef enum {
81         CHARREFERPARSER_RESULT_CONTINUE,
82         CHARREFERPARSER_RESULT_DETERMINE,
83         CHARREFERPARSER_RESULT_INVALID
84 } charreferparser_result_t;
85
86 IMPORT W charreferparser_initialize(charreferparser_t *parser);
87 IMPORT VOID charreferparser_finalize(charreferparser_t *parser);
88 IMPORT charreferparser_result_t charreferparser_parsechar(charreferparser_t *parser, UB ch);
89 IMPORT W charreferparser_getcharnumber(charreferparser_t *parser);
90 IMPORT VOID charreferparser_getlastmatchedstring(charreferparser_t *parser, UB **str, W *len);
91 IMPORT W charreferparser_parsestr(charreferparser_t *parser, UB *str, W len);
92 IMPORT VOID charreferparser_resetstate(charreferparser_t *parser);
93
94 #endif