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 TOKCONSTSYMSTR 16u // "@const-symbol-strings"
41 
42 #define TOKTYPEBYTE 100u
43 #define TOKTYPEI 101u
44 #define TOKTYPEU 102u
45 #define TOKTYPEI32 103u
46 #define TOKTYPEU32 104u
47 #define TOKTYPEI64 105u
48 #define TOKTYPEU64 106u
49 #define TOKTYPEF32 107u
50 #define TOKTYPEF64 108u
51 
52 
53 #define TOKENIZER_ERROR 1024u
54 #define TOKENIZER_END 2048u
55 
56 // Tokenizer return values
57 // > 0 : Successfully found token
58 // = 0 : Tokenizer can definitely not create a token
59 // = -1 : Tokenizer does not know if it can or cannot create a token yet.
60 // = -2 : Tokenizer was reading a string but ran out of space (for example).
61 // This is an error!
62 
63 #define TOKENIZER_NO_TOKEN 0
64 #define TOKENIZER_NEED_MORE -1
65 #define TOKENIZER_STRING_ERROR -2
66 #define TOKENIZER_CHAR_ERROR -3
67 
68 #define TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH 256
69 
70 // This is shared state between all ongoing read tasks. Maybe risky?
71 // Need to take care when dealing with this array in the reader.
72 extern char tokpar_sym_str[TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH];
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 #if 0
78 }
79 #endif
83 typedef struct {
84  const char *str;
85  unsigned int pos;
86  unsigned int row;
87  unsigned int column;
89 
90 typedef struct {
91  uint32_t type;
92  uint64_t value;
93  bool negative;
94 } token_int;
95 
96 typedef struct token_float {
97  uint32_t type;
98  double value;
99  bool negative;
100 } token_float;
101 
108 int tok_syntax(lbm_char_channel_t *chan, uint32_t *res);
120 int tok_string(lbm_char_channel_t *chan, unsigned int *string_len);
126 int tok_char(lbm_char_channel_t *chan, char *res);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 #endif
Definition: lbm_channel.h:68
Definition: tokpar.h:83
Definition: tokpar.h:96
Definition: tokpar.h:90
int tok_char(lbm_char_channel_t *chan, char *res)
int tok_double(lbm_char_channel_t *chan, token_float *result)
int tok_string(lbm_char_channel_t *chan, unsigned int *string_len)
int tok_syntax(lbm_char_channel_t *chan, uint32_t *res)
int tok_symbol(lbm_char_channel_t *chan)
int tok_integer(lbm_char_channel_t *chan, token_int *result)
bool tok_clean_whitespace(lbm_char_channel_t *chan)