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#ifndef GIMBAL_SCANNER_H
35#define GIMBAL_SCANNER_H
37#include "../meta/instances/gimbal_object.h"
38#include "../strings/gimbal_pattern.h"
39#include "../meta/signals/gimbal_signal.h"
42
43
44
46#define GBL_SCANNER(self) (GBL_CAST(GblScanner, self))
48#define GBL_SCANNER_GET_CLASS(self) (GBL_CLASSOF(GblScanner, self))
52#define GBL_SCANNER_DELIMETERS_DEFAULT "[ \t\n\r]"
54#define GBL_SELF_TYPE GblScanner
61
62
88
89
90
91
92
93
94
95
98 GBL_RESULT (*pFnNextToken)(
GBL_SELF, GblStringView* pToken);
102
103
104
105
106
107
108
109
110
111
130 (reset, (GBL_INSTANCE_TYPE, pReceiver)),
131 (eof, (GBL_INSTANCE_TYPE, pReceiver)),
132 (peeked, (GBL_INSTANCE_TYPE, pReceiver)),
133 (scanned, (GBL_INSTANCE_TYPE, pReceiver)),
134 (raised, (GBL_INSTANCE_TYPE, pReceiver))
139
140
141
142
161
162
163
174
175
176
177
197
198
199
210
211
212
213
224
225
226
227
240
241
242
243
281#define GblScanner_scan(self, ptr)
286
287
288
289
327#define GblScanner_peek(self, ptr)
332
333
334
335
353
354
355
356
366#define GBL_SCANNER_PEEK_TABLE_ (
369 (char*, GblScanner_peekChar),
370 (uint8_t*, GblScanner_peekUint8),
371 (uint16_t*, GblScanner_peekUint16),
372 (int16_t*, GblScanner_peekInt16),
373 (uint32_t*, GblScanner_peekUint32),
374 (int32_t*, GblScanner_peekInt32),
375 (uint64_t*, GblScanner_peekUint64),
376 (int64_t*, GblScanner_peekInt64),
377 (float*, GblScanner_peekFloat),
378 (double*, GblScanner_peekDouble)
380)
382#define GBL_SCANNER_SCAN_TABLE_ (
385 (char*, GblScanner_scanChar),
386 (uint8_t*, GblScanner_scanUint8),
387 (uint16_t*, GblScanner_scanUint16),
388 (int16_t*, GblScanner_scanInt16),
389 (uint32_t*, GblScanner_scanUint32),
390 (int32_t*, GblScanner_scanInt32),
391 (uint64_t*, GblScanner_scanUint64),
392 (int64_t*, GblScanner_scanInt64),
393 (float*, GblScanner_scanFloat),
394 (double*, GblScanner_scanDouble)
396)
398#define GblScanner_create(...)
399 GblScanner_createDefault_
(__VA_ARGS__)
400#define GblScanner_createDefault_(...)
401 GblScanner_createDefault__
(__VA_ARGS__, 0
)
402#define GblScanner_createDefault__(string, count, ...)
403 (GblScanner_create
)(string, count)
405#define GblScanner_cursor(...)
406 GblScanner_cursorDefault_
(__VA_ARGS__)
407#define GblScanner_cursorDefault_(...)
408 GblScanner_cursorDefault__
(__VA_ARGS__, 0
)
409#define GblScanner_cursorDefault__(self, depth, ...)
410 (GblScanner_cursor
)(self, depth)
412#define GblScanner_setInput(...)
413 GblScanner_setInputDefault_
(__VA_ARGS__)
414#define GblScanner_setInputDefault_(...)
415 GblScanner_setInputDefault__
(__VA_ARGS__, 0
)
416#define GblScanner_setInputDefault__(self, string, count, ...)
417 (GblScanner_setInput
)(self, string, count)
#define GBL_CLASS_CAST(cType, klass)
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_DECLARE_ENUM(E)
#define GBL_CLASS_DERIVE(...)
#define GBL_FLAGS_TYPE
GblType UUID for flags.
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
#define GBL_META_GENERIC_MACRO_NO_DEFAULT
#define GBL_META_GENERIC_MACRO_GENERATE(traits, X)
#define GBL_STRING_TYPE
Builtin ID for string GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
GblScanner * GblScanner_create(const char *pStr, size_t len)
Creates and returns a new GblScanner, setting its input to the given string with optional length.
GblScanner * GblScanner_ref(GblScanner *pSelf)
Acquires a reference to the given scanner, incrementing its reference count and returning its address...
GBL_SCANNER_FLAGS
Extensible enum of flags used for GblScanner::status.
@ GBL_SCANNER_ERROR
Mask of all scanner error flags.
@ GBL_SCANNER_STATE
Mask of all scanner state flags.
@ GBL_SCANNER_EOF
End-of-file.
@ GBL_SCANNER_OK
No errors present.
@ GBL_SCANNER_SKIP_ERROR
Failed previous skip call.
@ GBL_SCANNER_SCAN_ERROR
Failed to scan the previous token.
@ GBL_SCANNER_PEEK_ERROR
Failed to peek the previous token.
@ GBL_SCANNER_USER_ERROR
Mask of error user flags.
@ GBL_SCANNER_USER_STATE
Mask of non-error user flags.
GblRefCount GblScanner_unref(GblScanner *pSelf)
Releases a reference to the given scanner, returning the remaining count, and destroying the scanner ...
#define GBL_SIGNALS(instanceStruct,...)
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
const char GblStringRef
Reference-counted, const char*-compatible string type.
GblStringRef * GblScannerClass_defaultDelimeters(const GblScannerClass *pSelf)
Returns a string reference to the current default delimeter pattern on the given class.
GblType GblScanner_type(void)
Returns the GblType UUID associated with GblScanner.
void GblScannerClass_setDefaultDelimetersRef(GblScannerClass *pSelf, const GblStringRef *pPattern)
Moves the given string reference to be owned by the given class as its delimeter pattern.
void GblScannerClass_setDefaultDelimeters(GblScannerClass *pSelf, const char *pPattern)
Sets the default delimeter pattern on the given class to a copy of pStr.
Represents the current region of interest for a GblScanner.
size_t column
Current column number.
size_t length
Length of current region of interest.
size_t position
Current character position.
size_t line
Current line number.
Generic text stream scanner object.
GblBool GblScanner_scanInt64(GblScanner *pSelf, int64_t *pInt)
Scans the next token as a 64-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
GblBool GblScanner_peekBool(GblScanner *pSelf, GblBool *pBool)
Peeks at the next token, without advancing, setting pBool and returning GBL_TRUE if it's boolean-conv...
GblBool GblScanner_scanUint16(GblScanner *pSelf, uint16_t *pUint)
Scans the next token as a 16-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_peekInt16(GblScanner *pSelf, int16_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int16-convert...
GblBool GblScanner_skipMatch(GblScanner *pSelf, const char *pPattern)
Attempts to skip to just past the given regex pPattern, returning GBL_TRUE upon success or GBL_FALSE ...
GblBool GblScanner_peekTypeVa(GblScanner *pSelf, GblType t, va_list *pVa)
Same as GblScanner_peekType(), except taking a va_list* rather than (a) variadic argument(s)
void GblScanner_raiseError(GblScanner *pSelf, GblFlags flags, const char *pFmt,...)
Raises an error, setting the given flags and message for the given scanner.
GblBool GblScanner_skipTokens(GblScanner *pSelf, size_t count)
Attempts to skip the next count tokens from the stream, returning GBL_TRUE upon success or GBL_FALSE ...
GblBool GblScanner_peekDouble(GblScanner *pSelf, double *pDouble)
Peeks at the next token, without advancing, setting pDouble and returning GBL_TRUE if it's double-con...
GblBool GblScanner_skipPattern(GblScanner *pSelf, const GblPattern *pPat)
size_t GblScanner_tell(const GblScanner *pSelf)
Fetches the current position of the cursor into the input stream.
GblBool GblScanner_peekType(GblScanner *pSelf, GblType t,...)
Peeks at the next token, without advancing, attempting to convert it to the given variant type,...
void GblScanner_clearError(GblScanner *pSelf)
Clears the pending error message string and any error flags which are set on the given scanner.
GblBool GblScanner_peekLines(GblScanner *pSelf, size_t count)
Peeks at the next count lines, storing them to GblScanner::next or returning GBL_FALSE upon encounter...
GblBool GblScanner_peekUint32(GblScanner *pSelf, uint32_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint32-conve...
GblBool GblScanner_peekInt64(GblScanner *pSelf, int64_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int64-convert...
GblBool GblScanner_skipLines(GblScanner *pSelf, size_t count)
Attempts to skip count lines, returning GBL_TRUE upon success or GBL_FALSE upon EOF.
const GblScannerCursor * GblScanner_cursor(const GblScanner *pSelf, size_t depth)
Returns the top cursor on the stack, which maintains the current position into the input stream.
GblBool GblScanner_peekFloat(GblScanner *pSelf, float *pFloat)
Peeks at the next token, without advancing, setting pFloat and returning GBL_TRUE if it's float-conve...
GblBool GblScanner_scanToken(GblScanner *pSelf)
Scans the next token, storing it to GblScanner::token or returning GBL_FALSE upon failure.
GblBool GblScanner_scanMatch(GblScanner *pSelf, const char *pPat)
Scans the next token to GblScanner::token if it matches the given pattern or returning GBL_FALSE upon...
GblBool GblScanner_scanUint64(GblScanner *pSelf, uint64_t *pUint)
Scans the next token as a 64-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanUint32(GblScanner *pSelf, uint32_t *pUint)
Scans the next token as a 32-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanBytes(GblScanner *pSelf, size_t bytes)
Scans the given number of bytes to GblScanner::token or returns GBL_FALSE upon failure.
const GblStringRef * pError
Pending error message.
int GblScanner_vscanf(GblScanner *pSelf, const char *pFmt, va_list *pList)
Invokes the C stdlib routine, vscanf(), at the current position of the input stream.
GblStringView token
Current token in the stream.
GblStringView next
Peeked-at next token in the stream.
GblBool GblScanner_peekPattern(GblScanner *pSelf, const GblPattern *pPat)
void GblScanner_setDelimeters(GblScanner *pSelf, const char *pPattern)
Sets the stream's delimeter regular expression pattern to pPattern.
GblBool GblScanner_seek(GblScanner *pSelf, int whence)
Moves the cursor's current stream position by the given positive or negative offset.
GblBool GblScanner_scanTypeVa(GblScanner *pSelf, GblType t, va_list *pVa)
Same as GblScanner_scanType(), except taking a va_list* rather than (a) variadic argument(s)
GBL_RESULT GblScanner_popCursor(GblScanner *pSelf)
Pops the value of the current cursor from the top of the stack, reloading its state.
GblBool GblScanner_scanPattern(GblScanner *pSelf, const GblPattern *pPat)
GblBool GblScanner_skipToMatch(GblScanner *pSelf, const char *pPattern)
Attemps to skip to the matching regex pPattern, returning GBL_TRUE upon success or GBL_FALSE if not f...
GblStringRef * GblScanner_delimeters(const GblScanner *pSelf)
Returns a reference to the string used as the delimeter regular expression pattern.
size_t GblScanner_cursorDepth(const GblScanner *pSelf)
Returns the depth of the cursor stack for the given scanner object.
GblBool GblScanner_peekUint8(GblScanner *pSelf, uint8_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint8-conver...
void GblScanner_reset(GblScanner *pSelf)
Resets the state of the input stream, moving the cursor back to the beginning.
GblBool GblScanner_peekUint16(GblScanner *pSelf, uint16_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint16-conve...
int GblScanner_scanf(GblScanner *pSelf, const char *pFmt,...)
Invokes the C stdlib routine, sscanf(), at the current position of the input stream.
GblStringRef * GblScanner_input(const GblScanner *pSelf)
Returns a string reference to the string current being used as the input stream.
GblBool GblScanner_peekInt32(GblScanner *pSelf, int32_t *pInt)
Peeks at the next token, without advancing, setting pInt and returning GBL_TRUE if it's int32-convert...
GblBool GblScanner_peekBytes(GblScanner *pSelf, size_t count)
Peeks at the next count bytes, storing them to GblScanner::next or returning GBL_FALSE upon encounter...
GblBool GblScanner_peekMatch(GblScanner *pSelf, const char *pMatch)
Peeks at the next token, storing it to GblScanner::next if it exactly matches the given pattern or re...
void GblScanner_setInput(GblScanner *pSelf, const char *pStr, size_t count)
Sets the input stream to the given string, optionally taking its size, and resetting the stream.
GblBool GblScanner_scanInt32(GblScanner *pSelf, int32_t *pInt)
Scans the next token as a 32-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
GblBool GblScanner_scanLines(GblScanner *pSelf, size_t lines)
Scans the given number of lines to GblScanner::token or returns GBL_FALSE upon failure.
GblBool GblScanner_skipBytes(GblScanner *pSelf, size_t count)
Attempts to skip count bytes, returning GBL_TRUE upon success or GBL_FALSE upon EOF.
GblBool GblScanner_peekToken(GblScanner *pSelf)
Peeks at the next token, without advancing the stream, storing it to GblScanner::next or returning GB...
GblBool GblScanner_scanType(GblScanner *pSelf, GblType t,...)
Scans the next token and attempts to convert it from a string to the given type, t,...
GblBool GblScanner_peekUint64(GblScanner *pSelf, uint64_t *pUint)
Peeks at the next token, without advancing, setting pUint and returning GBL_TRUE if it's uint64-conve...
GblBool GblScanner_scanBool(GblScanner *pSelf, GblBool *pBool)
Scans the next token as a boolean to GblScanner::token, returning GBL_TRUE and setting pBool to the s...
GBL_SCANNER_FLAGS status
Status after the last operation.
GblBool GblScanner_scanDouble(GblScanner *pSelf, double *pDouble)
Scans the next token as a double to GblScanner::token, returning GBL_TRUE and setting pDouble to the ...
GBL_RESULT GblScanner_pushCursor(GblScanner *pSelf)
Pushes the value of the current cursor onto the stack, saving its state.
GblBool GblScanner_skipToPattern(GblScanner *pSelf, const GblPattern *pPat)
GblBool GblScanner_peekChar(GblScanner *pSelf, char *pChar)
Peeks at the next token, without advancing, setting pChar and returning GBL_TRUE if it's character-co...
GblBool GblScanner_scanFloat(GblScanner *pSelf, float *pFloat)
Scans the next token as a float to GblScanner::token, returning GBL_TRUE and setting pFloat to the sc...
GblBool GblScanner_scanUint8(GblScanner *pSelf, uint8_t *pUint)
Scans the next token as an 8-bit unsigned integer to GblScanner::token, returning GBL_TRUE and settin...
GblBool GblScanner_scanChar(GblScanner *pSelf, char *pChar)
Scans the next token as a character to GblScanner::token, returning GBL_TRUE and setting pChar to the...
GblBool GblScanner_scanInt16(GblScanner *pSelf, int16_t *pInt)
Scans the next token as a 16-bit integer to GblScanner::token, returning GBL_TRUE and setting pInt to...
void GblScanner_setInputRef(GblScanner *pSelf, const GblStringRef *pRef)
Sets the input stream to given string reference, taking ownership of it, and resetting the sream.