summaryrefslogtreecommitdiff
path: root/include/lexer/char_info.h
blob: 5987bbff9d02eb13ea958efcea421dc1de614c05 (plain)
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
/*
 * Character info table.
 * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team.
 * Provided under the BSD 3-Clause license.
 */

#ifndef _LEXER_CHAR_INFO_H
#define _LEXER_CHAR_INFO_H

#include <stdint.h>
#include "lexer/token.h"

#define CHAR_HORZ_WS (1 << 0)
#define CHAR_VERT_WS (1 << 1)
#define CHAR_DIGIT   (1 << 2)
#define CHAR_XDIGIT  (1 << 3)
#define CHAR_UPPER   (1 << 4)
#define CHAR_LOWER   (1 << 5)
#define CHAR_OPER    (1 << 6)
#define CHAR_SINGLE  (1 << 7)

#define CHAR_HEX        (CHAR_DIGIT | CHAR_XDIGIT)
#define CHAR_XUPPER     (CHAR_XDIGIT | CHAR_UPPER)
#define CHAR_XLOWER     (CHAR_XDIGIT | CHAR_LOWER)
#define CHAR_WHITESPACE (CHAR_HORZ_WS | CHAR_VERT_WS)
#define CHAR_ALPHA      (CHAR_UPPER | CHAR_LOWER)
#define CHAR_ALNUM      (CHAR_ALPHA | CHAR_DIGIT)

#define CHAR_SINGLE_SHIFT 8
#define MAKE_SINGLE(kind) ((kind << CHAR_SINGLE_SHIFT) | CHAR_SINGLE)
#define CHAR_COMMA   MAKE_SINGLE(TK_COMMA)
#define CHAR_DOT     MAKE_SINGLE(TK_DOT)
#define CHAR_COLON   MAKE_SINGLE(TK_COLON)
#define CHAR_SEMI    MAKE_SINGLE(TK_SEMICOLON)
#define CHAR_LPAREN  MAKE_SINGLE(TK_LPAREN)
#define CHAR_RPAREN  MAKE_SINGLE(TK_RPAREN)
#define CHAR_LBRACE  MAKE_SINGLE(TK_LBRACE)
#define CHAR_RBRACE  MAKE_SINGLE(TK_RBRACE)
#define CHAR_LBRACK  MAKE_SINGLE(TK_LBRACK)
#define CHAR_RBRACK  MAKE_SINGLE(TK_RBRACK)
#define CHAR_TILDE   MAKE_SINGLE(TK_TILDE)
#define CHAR_EQUALS  MAKE_SINGLE(TK_EQUALS)

#define CHAR_OPER_SHIFT 8
#define MAKE_OPER(kind) ((kind << CHAR_OPER_SHIFT) | CHAR_OPER)
#define CHAR_PLUS    MAKE_OPER(TK_PLUS)
#define CHAR_MINUS   MAKE_OPER(TK_MINUS)
#define CHAR_STAR    MAKE_OPER(TK_STAR)
#define CHAR_SLASH   MAKE_OPER(TK_SLASH)
#define CHAR_PERCENT MAKE_OPER(TK_PERCENT)
#define CHAR_EXCLAIM MAKE_OPER(TK_EXCLAMATION)
#define CHAR_LESS    MAKE_OPER(TK_LESS_THAN)
#define CHAR_GREATER MAKE_OPER(TK_GREATER_THAN)
#define CHAR_CARET   MAKE_OPER(TK_CARET)
#define CHAR_AMPER   MAKE_OPER(TK_AMPERSAND)
#define CHAR_PIPE    MAKE_OPER(TK_PIPE)

extern uint16_t char_info[256];

#endif /* !_LEXER_CHAR_INFO_H */