7c64b252b52b880e656c7f9448c0e7c845e26f08
[m6w6/ext-psi] / src / parser.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PSI_PARSER_H
27 #define PSI_PARSER_H
28
29 #include <stdarg.h>
30
31 #define BSIZE 256
32
33 #include "token.h"
34 #include "types.h"
35 #include "data.h"
36
37 struct psi_parser {
38 PSI_DATA_MEMBERS;
39 FILE *fp;
40 token_t num;
41 void *proc;
42 unsigned line, col;
43 char *cur, *tok, *lim, *eof, *ctx, *mrk, buf[BSIZE];
44 };
45
46 struct psi_parser *psi_parser_init(struct psi_parser *P, const char *filename, psi_error_cb error, unsigned flags);
47 void psi_parser_syntax_error(struct psi_parser *P, const char *fn, size_t ln, const char *msg, ...);
48 ssize_t psi_parser_fill(struct psi_parser *P, size_t n);
49 token_t psi_parser_scan(struct psi_parser *P);
50 void psi_parser_parse(struct psi_parser *P, struct psi_token *src);
51 void psi_parser_dtor(struct psi_parser *P);
52 void psi_parser_free(struct psi_parser **P);
53
54 #endif