LispBM
Loading...
Searching...
No Matches
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
78extern "C" {
79#endif
80#if 0
81}
82#endif
86typedef struct {
87 const char *str;
88 unsigned int pos;
89 unsigned int row;
90 unsigned int column;
92
93typedef struct {
94 uint32_t type;
95 uint64_t value;
97} token_int;
98
99typedef struct token_float {
100 uint32_t type;
101 double value;
104
111int tok_syntax(lbm_char_channel_t *chan, uint32_t *res);
123int tok_string(lbm_char_channel_t *chan, unsigned int *string_len);
129int tok_char(lbm_char_channel_t *chan, char *res);
135int tok_double(lbm_char_channel_t *chan, token_float *result);
141int tok_integer(lbm_char_channel_t *chan, token_int *result);
146
147#ifdef __cplusplus
148}
149#endif
150#endif
Definition lbm_channel.h:69
Definition tokpar.h:86
unsigned int pos
Definition tokpar.h:88
const char * str
Definition tokpar.h:87
unsigned int column
Definition tokpar.h:90
unsigned int row
Definition tokpar.h:89
Definition tokpar.h:99
uint32_t type
Definition tokpar.h:100
double value
Definition tokpar.h:101
bool negative
Definition tokpar.h:102
Definition tokpar.h:93
uint32_t type
Definition tokpar.h:94
bool negative
Definition tokpar.h:96
uint64_t value
Definition tokpar.h:95
int tok_char(lbm_char_channel_t *chan, char *res)
Definition tokpar.c:248
int tok_double(lbm_char_channel_t *chan, token_float *result)
Definition tokpar.c:291
#define TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH
Definition tokpar.h:71
char tokpar_sym_str[TOKENIZER_MAX_SYMBOL_AND_STRING_LENGTH+1]
Definition tokpar.c:32
int tok_string(lbm_char_channel_t *chan, unsigned int *string_len)
Definition tokpar.c:208
int tok_syntax(lbm_char_channel_t *chan, uint32_t *res)
Definition tokpar.c:128
int tok_symbol(lbm_char_channel_t *chan)
Definition tokpar.c:165
int tok_integer(lbm_char_channel_t *chan, token_int *result)
Definition tokpar.c:434
bool tok_clean_whitespace(lbm_char_channel_t *chan)
Definition tokpar.c:385