forked from wilhelmtell/inspext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscan.h
64 lines (56 loc) · 1.8 KB
/
scan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/******************************************************************************
* Copyright (C) 2010 Matan Nassau
*
* This file is part of INSPext.
*
* 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 the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef SCAN_H_
#define SCAN_H_
#include <stdio.h>
typedef struct stream_buf_t {
int ch;
struct stream_buf_t* next;
} stream_buf_t;
typedef struct token {
enum token_type {
HEADING_TOKEN,
CHARACTER_TOKEN,
PARAGRAPH_TOKEN,
INDENT_TOKEN,
END_TOKEN,
UNDEFINED_TOKEN
} type;
char ch;
int heading_level;
} token;
typedef struct token_buf_t {
token* tok;
struct token_buf_t* next;
} token_buf_t;
typedef struct lex_state {
int beginning_of_line;
int delimited; /* two newlines consumed; ready for paragraph or heading */
int lineno;
int heading_level;
char* filename;
enum token_type previous_token;
stream_buf_t* stream_buf;
token_buf_t* token_buf;
} lex_state;
char* token_s(enum token_type t);
token* peek(FILE* is, lex_state* state);
void putback(token* tok, lex_state* lstate);
token* scan(FILE* is, lex_state* lstate);
#endif /* SCAN_H_ */