-
Notifications
You must be signed in to change notification settings - Fork 57
/
scanner.h
81 lines (61 loc) · 1.81 KB
/
scanner.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*! @file scanner.h
* @brief
*
* @version 1.0.0
*
* (C) Copyright 2017 GoPro Inc (http://gopro.com/).
*
* Licensed under either:
* - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
* - MIT license, http://opensource.org/licenses/MIT
* at your option.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#pragma once
typedef enum error
{
SCANNER_ERROR_OKAY = 0,
SCANNER_ERROR_EOF,
SCANNER_ERROR_OVERFLOW,
SCANNER_ERROR_QUOTE,
SCANNER_ERROR_KEYWORD,
} SCANNER_ERROR;
// Scanner state
typedef struct scanner
{
FILE *file;
char c; // Last character read from the file
int error; // Error code from the last operation
int line; // Line number where the error occurred
} SCANNER;
// Token table entry
typedef struct token
{
char *string; // The token keyword
int value; // The opcode for the token
} TOKEN;
#ifdef __cplusplus
extern "C" {
#endif
int InitScanner(SCANNER *scanner, FILE *file);
int SkipBlanks(SCANNER *scanner);
int SkipLine(SCANNER *scanner);
int ScanKeyword(SCANNER *scanner, char *keyword, int keyword_length);
int CopyQuotedString(SCANNER *scanner, char *result_string, int result_length);
int CopyTrimmedString(SCANNER *scanner, char *result_string, int result_length);
int Lookup(const char *keyword,
TOKEN *token_table,
int token_table_length);
const char *Keyword(int opcode,
TOKEN *token_table,
int token_table_length);
const char *Message(int error);
#ifdef __cplusplus
}
#endif