LispBM
tokpar.h
Go to the documentation of this file.
1 /*
2  Copyright 2019, 2022 Joel Svensson svenssonjoel@yahoo.se
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
19 #ifndef TOKPAR_H_
20 #define TOKPAR_H_
21 
22 #include "lbm_types.h"
23 #include "lbm_channel.h"
24 
25 #define TOKOPENPAR 1u // "("
26 #define TOKCLOSEPAR 2u // ")"
27 #define TOKOPENBRACK 3u // "["
28 #define TOKCLOSEBRACK 4u // "]"
29 #define TOKDOT 5u // "."
30 #define TOKDONTCARE 6u // "_"
31 #define TOKQUOTE 7u // "'"
32 #define TOKBACKQUOTE 8u // "`"
33 #define TOKCOMMAAT 9u // ",@"
34 #define TOKCOMMA 10u // ","
35 #define TOKMATCHANY 11u // "?"
36 #define TOKOPENCURL 12u // "{"
37 #define TOKCLOSECURL 13u // "}"
38 #define TOKCONSTSTART 14u // "@const-start"
39 #define TOKCONSTEND 15u // "@const-end"
40 #define TOKOPENARRAY 16u // "[|"
41 #define TOKCLOSEARRAY 17u // "|]"
42 
43 #define TOKTYPEBYTE 100u
44 #define TOKTYPEI 101u
45 #define TOKTYPEU 102u
46 #define TOKTYPEI32 103u
47 #define TOKTYPEU32 104u
48 #define TOKTYPEI64 105u
49 #define TOKTYPEU64 106u
50 #define TOKTYPEF32 107u
51 #define TOKTYPEF64 108u
52 
53 
54 #define TOKENIZER_ERROR 1024u
55 #define TOKENIZER_END 2048u
56 
57 // Tokenizer return values
58 // > 0 : Successfully found token
59 // = 0 : Tokenizer can definitely not create a token
60 // = -1 : Tokenizer does not know if it can or cannot create a token yet.
61 // = -2 : Tokenizer was reading a string but ran out of space (for example).
62 // This is an error!
63 // = -4 : Tokenizer was reading a symbol but ran out of space.
64 
65 #define TOKENIZER_NO_TOKEN 0
66 #define TOKENIZER_NEED_MORE -1
67 #define TOKENIZER_STRING_ERROR -2
68 #define TOKENIZER_CHAR_ERROR -3
69 #define TOKENIZER_SYMBOL_ERROR -4
70 
71 #define TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH 256
72 
73 // The contents of tokpar_sym_str is reset every time
74 // tok_symbol or tok_string is run.
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 #if 0
81 }
82 #endif
83 
86 typedef struct {
87  const char *str;
88  unsigned int pos;
89  unsigned int row;
90  unsigned int column;
92 
93 typedef struct {
94  uint32_t type;
95  uint64_t value;
96  bool negative;
97 } token_int;
98 
99 typedef struct token_float {
100  uint32_t type;
101  double value;
102  bool negative;
103 } token_float;
104 
111 int tok_syntax(lbm_char_channel_t *chan, uint32_t *res);
117 int tok_symbol(lbm_char_channel_t *chan);
123 int tok_string(lbm_char_channel_t *chan, unsigned int *string_len);
129 int tok_char(lbm_char_channel_t *chan, char *res);
135 int tok_double(lbm_char_channel_t *chan, token_float *result);
141 int tok_integer(lbm_char_channel_t *chan, token_int *result);
146 
147 #ifdef __cplusplus
148 }
149 #endif
150 #endif
token_int::value
uint64_t value
Definition: tokpar.h:95
tokpar_sym_str
char tokpar_sym_str[TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH+1]
Definition: tokpar.c:32
tok_string
int tok_string(lbm_char_channel_t *chan, unsigned int *string_len)
Definition: tokpar.c:208
token_int::type
uint32_t type
Definition: tokpar.h:94
token_float
Definition: tokpar.h:99
token_int::negative
bool negative
Definition: tokpar.h:96
TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH
#define TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH
Definition: tokpar.h:71
lbm_channel.h
token_float::type
uint32_t type
Definition: tokpar.h:100
lbm_tokenizer_string_state_t::column
unsigned int column
Definition: tokpar.h:90
lbm_tokenizer_string_state_t::row
unsigned int row
Definition: tokpar.h:89
tok_symbol
int tok_symbol(lbm_char_channel_t *chan)
Definition: tokpar.c:165
lbm_char_channel_s
Definition: lbm_channel.h:69
tok_integer
int tok_integer(lbm_char_channel_t *chan, token_int *result)
Definition: tokpar.c:434
token_float::value
double value
Definition: tokpar.h:101
token_float
struct token_float token_float
tok_double
int tok_double(lbm_char_channel_t *chan, token_float *result)
Definition: tokpar.c:291
tok_char
int tok_char(lbm_char_channel_t *chan, char *res)
Definition: tokpar.c:248
token_int
Definition: tokpar.h:93
tok_syntax
int tok_syntax(lbm_char_channel_t *chan, uint32_t *res)
Definition: tokpar.c:128
tok_clean_whitespace
bool tok_clean_whitespace(lbm_char_channel_t *chan)
Definition: tokpar.c:385
lbm_types.h
lbm_tokenizer_string_state_t::str
const char * str
Definition: tokpar.h:87
token_float::negative
bool negative
Definition: tokpar.h:102
lbm_tokenizer_string_state_t::pos
unsigned int pos
Definition: tokpar.h:88
lbm_tokenizer_string_state_t
Definition: tokpar.h:86