libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_scanner.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblScanner, generic text tokenizer and lexer
3 * \ingroup utils
4 *
5 * The main operation is to set the delimeter pattern (regex, powered by the
6 * TinyCRegex submodule), and then use GblScanner_peekToken() (and friends)
7 * to "view" the upcoming token without actually advancing the stream or do
8 * GblScanner_scanToken() (and friends) to take the next token and advance the
9 * buffer.
10 *
11 * This basically lets GblScanner operate with a one-token lookahead at all time.
12 * If you need to inspect more tokens than just that without modifying the buffer
13 * state, that's when you would use GblScanner_pushCursor() to save your state,
14 * then peek/scan, and when you need to back up and restore an old state,
15 * use GblScanner_popCursor().
16 *
17 * The main two operations are peek and scan, with their results being immediately
18 * stored in the public GblStringView variables GblScanner::next and GblScanner::token
19 * respectively. The variations of peek/scan are simply using GblStringView to handle
20 * type conversions for you, like GblScanner_scanUint32() for example, scans into
21 * GblScanner::token and then calls GblStringView_toUint32() on the token for you
22 * automatically.
23 *
24 * \todo
25 * - continue testing type-specific peek/scan functions
26 * - write own scanf() implementation that knows how
27 * many characters have been read
28 * - store GblPattern now instead of GblStringRef
29 * - peekPattern(), scanPattern()
30 *
31 * \author 2023 Falco Girgis
32 * \copyright MIT License
33 */
34#ifndef GIMBAL_SCANNER_H
35#define GIMBAL_SCANNER_H
36
37#include "../meta/instances/gimbal_object.h"
38#include "../strings/gimbal_pattern.h"
39#include "../meta/signals/gimbal_signal.h"
40
41/*! \name Type System
42 * \brief Type UUID and cast operators
43 * @{
44 */
45#define GBL_SCANNER_TYPE (GBL_TYPEID(GblScanner)) //!< Type UUID for GblScanner
46#define GBL_SCANNER(self) (GBL_CAST(GblScanner, self)) //!< Function-style cast for GblInstance
47#define GBL_SCANNER_CLASS(klass) (GBL_CLASS_CAST(GblScanner, klass)) //!< Function-style cast for GblClass
48#define GBL_SCANNER_GET_CLASS(self) (GBL_CLASSOF(GblScanner, self)) //!< Get a GblScannerClass from GblInstance
49//! @}
50
51//! Default delimeters used with GblScanner for tokenizing the input stream
52#define GBL_SCANNER_DELIMETERS_DEFAULT "[ \t\n\r]"
53
54#define GBL_SELF_TYPE GblScanner
55
57
59
60/*! \enum GBL_SCANNER_FLAGS
61 * \brief Extensible enum of flags used for GblScanner::status.
62 */
64 // Builtin Non-error state flags (bit 0)
65 GBL_SCANNER_OK = 0x00000000, //!< No errors present
66 GBL_SCANNER_EOF = 0x00000001, //!< End-of-file
67 // Builtin Error flags (bits 29-31)
68 GBL_SCANNER_SCAN_ERROR = 0x20000000, //!< Failed to scan the previous token
69 GBL_SCANNER_PEEK_ERROR = 0x40000000, //!< Failed to peek the previous token
70 GBL_SCANNER_SKIP_ERROR = 0x80000000, //!< Failed previous skip call
71 // User masks (bits 1-28)
72 GBL_SCANNER_USER_STATE = 0x00fffff2, //!< Mask of non-error user flags
73 GBL_SCANNER_USER_ERROR = 0x1f000000, //!< Mask of error user flags
74 // Masks for combined state and error flags
75 GBL_SCANNER_STATE = 0x00ffffff, //!< Mask of all scanner state flags
76 GBL_SCANNER_ERROR = 0xff000000, //!< Mask of all scanner error flags
77};
78
79//! Represents the current region of interest for a GblScanner
80typedef struct GblScannerCursor {
81 size_t position; //!< Current character position
82 size_t line; //!< Current line number
83 size_t column; //!< Current column number
84 size_t length; //!< Length of current region of interest
85} GblScannerCursor;
86
87/*! \struct GblScannerClass
88 * \extends GblObjectClass
89 * \brief GblClass VTable structure for GblScanner
90 *
91 * GblScannerClass provides a virtual function table for
92 * polymorphically overriding the tokenization logic.
93 *
94 * \sa GblScanner
95 */
96GBL_CLASS_DERIVE(GblScanner, GblObject)
97 //! Called every time the next token is to be extracted from the stream
98 GBL_RESULT (*pFnNextToken)(GBL_SELF, GblStringView* pToken);
100
101/*! \struct GblScanner
102 * \extends GblObject
103 * \ingroup utils
104 * \brief Generic text stream scanner object
105 *
106 * GblScanner offers a generic way to scan through a stream
107 * of text, parsing its contents into variables of any type
108 * supported by the type system.
109 *
110 * \sa GblScannerClass
111 */
113 GblStringView token; //!< Current token in the stream
114 GblStringView next; //!< Peeked-at next token in the stream
115 GblStringRef* pError; //!< Pending error message
116 GBL_SCANNER_FLAGS status; //!< Status after the last operation
118
119//! \cond
120GBL_PROPERTIES(GblScanner,
121 (input, GBL_GENERIC, (READ, WRITE, CONSTRUCT), GBL_STRING_TYPE),
122 (delimeters, GBL_GENERIC, (READ, WRITE, CONSTRUCT), GBL_STRING_TYPE),
123 (token, GBL_GENERIC, (READ), GBL_STRING_TYPE),
124 (next, GBL_GENERIC, (READ), GBL_STRING_TYPE),
125 (status, GBL_GENERIC, (READ), GBL_FLAGS_TYPE),
126 (error, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE)
127)
128
129GBL_SIGNALS(GblScanner,
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))
135)
136//! \endcond
137
138/*! \name Default Delimeters
139 * \brief Accessor methods for the default delimeter pattern
140 * \relatesalso GblScannerClass
141 * @{
142 */
143//! Returns a string reference to the current default delimeter pattern on the given class
145//! Sets the default delimeter pattern on the given class to a copy of \p pStr
147//! Moves the given string reference to be owned by the given class as its delimeter pattern
149//! @}
150
151//! Returns the GblType UUID associated with GblScanner
153
154/*! \name Lifetime Management
155 * \brief Methods for managing GblScanner creation/destruction
156 * @{
157 */
158//! Creates and returns a new GblScanner, setting its input to the given string with optional length
159GBL_EXPORT GblScanner* GblScanner_create (const char* pStr,
160 size_t len/*=0*/) GBL_NOEXCEPT;
161//! Acquires a reference to the given scanner, incrementing its reference count and returning its address
163//! Releases a reference to the given scanner, returning the remaining count, and destroying the scanner when it hits 0
165//! @}
166
167/*! \name Input and Delimeters
168 * \brief Methods for setting input and delimeter pattern
169 * \relatesalso GblScanner
170 * @{
171 */
172//! Returns a string reference to the string current being used as the input stream
174//! Sets the input stream to the given string, optionally taking its size, and resetting the stream
176 const char* pStr,
177 size_t count/*=0*/) GBL_NOEXCEPT;
178//! Sets the input stream to given string reference, taking ownership of it, and resetting the sream
180//! Returns a reference to the string used as the delimeter regular expression pattern
182//! Sets the stream's delimeter regular expression pattern to \p pPattern
184//! @}
185
186/*! \name Errors
187 * \brief Methods for managing errors
188 * \relatesalso GblScanner
189 */
190//! Clears the pending error message string and any error flags which are set on the given scanner
192//! Raises an error, setting the given flags and message for the given scanner
194 GblFlags flags,
195 const char* pFmt,
196 ...) GBL_NOEXCEPT;
197//! @}
198
199/*! \name Stream
200 * \brief Methods for controlling the input stream
201 * \relatesalso GblScanner
202 * @{
203 */
204//! Resets the state of the input stream, moving the cursor back to the beginning
206//! Fetches the current position of the cursor into the input stream
208//! Moves the cursor's current stream position by the given positive or negative offset
210 int whence) GBL_NOEXCEPT;
211//! @}
212
213/*! \name Cursor
214 * \brief Methods for managing the stream cursor
215 * \relatesalso GblScanner
216 * @{
217 */
218//! Returns the top cursor on the stack, which maintains the current position into the input stream
219GBL_EXPORT const GblScannerCursor*
221//! Returns the depth of the cursor stack for the given scanner object
223//! Pushes the value of the current cursor onto the stack, saving its state
225//! Pops the value of the current cursor from the top of the stack, reloading its state
227//! @}
228
229/*! \name Scanning
230 * \brief Methods for scanning the next token
231 * \relatesalso GblScanner
232 * @{
233 */
234//! Scans the next token, storing it to GblScanner::token or returning GBL_FALSE upon failure
236//! Scans the next token to GblScanner::token if it matches the given pattern or returning GBL_FALSE upon failure
238//! \todo implement me: GblScanner_scanMatch() overload
240//! Scans the given number of lines to GblScanner::token or returns GBL_FALSE upon failure
242//! Scans the given number of bytes to GblScanner::token or returns GBL_FALSE upon failure
244//! Scans the next token as a boolean to GblScanner::token, returning GBL_TRUE and setting \p pBool to the scanned value upon success
246//! Scans the next token as a character to GblScanner::token, returning GBL_TRUE and setting \p pChar to the scanned value upon success
248//! Scans the next token as an 8-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
250//! Scans the next token as a 16-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
252//! Scans the next token as a 16-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
254//! Scans the next token as a 32-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
256//! Scans the next token as a 32-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
258//! Scans the next token as a 64-bit integer to GblScanner::token, returning GBL_TRUE and setting \p pInt to the scanned value upon success
260//! Scans the next token as a 64-bit unsigned integer to GblScanner::token, returning GBL_TRUE and setting \p pUint to the scanned value upon success
262//! Scans the next token as a float to GblScanner::token, returning GBL_TRUE and setting \p pFloat to the scanned value upon success
264//! Scans the next token as a double to GblScanner::token, returning GBL_TRUE and setting \p pDouble to the scanned value upon success
266//! Scans the next token and attempts to convert it from a string to the given type, \p t, moving its value through the variadic argument list
268//! Same as GblScanner_scanType(), except taking a va_list* rather than (a) variadic argument(s)
270//! Generic overload macro which automatically calls the respective scan function for the type of \p ptr
271#define GblScanner_scan(self, ptr)
272 GBL_META_GENERIC_MACRO_GENERATE(GBL_SCANNER_SCAN_TABLE_, ptr)(self, ptr)
273//! @}
274
275/*! \name Peeking
276 * \brief Methods for peeking at the next token
277 * \relatesalso GblScanner
278 * @{
279 */
280//! Peeks at the next token, without advancing the stream, storing it to GblScanner::next or returning GBL_FALSE upon failure
282//! Peeks at the next token, storing it to GblScanner::next if it exactly matches the given pattern or returning GBL_FALSE upon failure
284//! \todo implement me: GblScanner_peekMatch() overload
286//! Peeks at the next \p count lines, storing them to GblScanner::next or returning GBL_FALSE upon encountering EOF
288//! Peeks at the next \p count bytes, storing them to GblScanner::next or returning GBL_FALSE upon encountering EOF
290//! Peeks at the next token, without advancing, setting \p pBool and returning GBL_TRUE if it's boolean-convertible, or returning GBL_FALSE otherwise
292//! Peeks at the next token, without advancing, setting \p pChar and returning GBL_TRUE if it's character-convertible, or returning GBL_FALSE otherwise
294//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint8-convertible, or returning GBL_FALSE otherwise
296//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint16-convertible, or returning GBL_FALSE otherwise
298//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int16-convertible, or returning GBL_FALSE otherwise
300//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int32-convertible, or returning GBL_FALSE otherwise
302//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint32-convertible, or returning GBL_FALSE otherwise
304//! Peeks at the next token, without advancing, setting \p pInt and returning GBL_TRUE if it's int64-convertible, or returning GBL_FALSE otherwise
306//! Peeks at the next token, without advancing, setting \p pUint and returning GBL_TRUE if it's uint64-convertible, or returning GBL_FALSE otherwise
308//! Peeks at the next token, without advancing, setting \p pFloat and returning GBL_TRUE if it's float-convertible, or returning GBL_FALSE otherwise
310//! Peeks at the next token, without advancing, setting \p pDouble and returning GBL_TRUE if it's double-convertible, or returning GBL_FALSE otherwise
312//! Peeks at the next token, without advancing, attempting to convert it to the given variant type, moving its value to the variadic argument, returning GBL_TRUE upon success
314//! Same as GblScanner_peekType(), except taking a va_list* rather than (a) variadic argument(s)
316//! Generic overload macro which automatically calls the respective peek function for the type of \p ptr
317#define GblScanner_peek(self, ptr)
318 GBL_META_GENERIC_MACRO_GENERATE(GBL_SCANNER_PEEK_TABLE_, ptr)(self, ptr)
319//! @}
320
321/*! \name Skipping
322 * \brief Methods for skipping over the input steram
323 * \relatesalso GblScanner
324 * @{
325 */
326//! Attempts to skip the next \p count tokens from the stream, returning GBL_TRUE upon success or GBL_FALSE upon EOF
328//! Attempts to skip to just past the given regex \p pPattern, returning GBL_TRUE upon success or GBL_FALSE if not found or upon EOF
330//! \todo implement me: GblScanner_skipMatch() overload
332//! Attemps to skip to the matching regex \p pPattern, returning GBL_TRUE upon success or GBL_FALSE if not found or upon EOF
334//! \todo implement me: GblScanner_skipToMatch() overload
336//! Attempts to skip \p count lines, returning GBL_TRUE upon success or GBL_FALSE upon EOF
338//! Attempts to skip \p count bytes, returning GBL_TRUE upon success or GBL_FALSE upon EOF
340//! @}
341
342/*! \name Utilities
343 * \brief Methods providing other utilities
344 * \relatesalso GblScanner
345 * @{
346 */
347//! Invokes the C stdlib routine, sscanf(), at the current position of the input stream
349//! Invokes the C stdlib routine, vscanf(), at the current position of the input stream
350GBL_EXPORT int GblScanner_vscanf (GBL_SELF, const char* pFmt, va_list* pList) GBL_NOEXCEPT;
351//! @}
352
354
355///\cond
356#define GBL_SCANNER_PEEK_TABLE_ (
358 (
359 (char*, GblScanner_peekChar),
360 (uint8_t*, GblScanner_peekUint8),
361 (uint16_t*, GblScanner_peekUint16),
362 (int16_t*, GblScanner_peekInt16),
363 (uint32_t*, GblScanner_peekUint32),
364 (int32_t*, GblScanner_peekInt32),
365 (uint64_t*, GblScanner_peekUint64),
366 (int64_t*, GblScanner_peekInt64),
367 (float*, GblScanner_peekFloat),
368 (double*, GblScanner_peekDouble)
369 ) \
370)
371
372#define GBL_SCANNER_SCAN_TABLE_ (
374 (
375 (char*, GblScanner_scanChar),
376 (uint8_t*, GblScanner_scanUint8),
377 (uint16_t*, GblScanner_scanUint16),
378 (int16_t*, GblScanner_scanInt16),
379 (uint32_t*, GblScanner_scanUint32),
380 (int32_t*, GblScanner_scanInt32),
381 (uint64_t*, GblScanner_scanUint64),
382 (int64_t*, GblScanner_scanInt64),
383 (float*, GblScanner_scanFloat),
384 (double*, GblScanner_scanDouble)
385 ) \
386)
387
388#define GblScanner_create(...)
389 GblScanner_createDefault_(__VA_ARGS__)
390#define GblScanner_createDefault_(...)
391 GblScanner_createDefault__(__VA_ARGS__, 0)
392#define GblScanner_createDefault__(string, count, ...)
393 (GblScanner_create)(string, count)
394
395#define GblScanner_cursor(...)
396 GblScanner_cursorDefault_(__VA_ARGS__)
397#define GblScanner_cursorDefault_(...)
398 GblScanner_cursorDefault__(__VA_ARGS__, 0)
399#define GblScanner_cursorDefault__(self, depth, ...)
400 (GblScanner_cursor)(self, depth)
401
402#define GblScanner_setInput(...)
403 GblScanner_setInputDefault_(__VA_ARGS__)
404#define GblScanner_setInputDefault_(...)
405 GblScanner_setInputDefault__(__VA_ARGS__, 0)
406#define GblScanner_setInputDefault__(self, string, count, ...)
407 (GblScanner_setInput)(self, string, count)
408///\endcond
409
410#undef GBL_SELF_TYPE
411
412#endif // GIMBAL_SCANNER_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#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_INSTANCE_END
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_FLAGS_TYPE
GblType UUID for flags.
#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.
GblType GblScanner_type(void)
Returns the GblType UUID associated with GblScanner.
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,...)
Declares a list of signals to be associated with the given 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.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:52
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.
void GblScannerClass_setDefaultDelimetersRef(GblScannerClass *pSelf, 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_setInputRef(GblScanner *pSelf, GblStringRef *pRef)
Sets the input stream to given string reference, taking ownership of it, and resetting the sream.
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.
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.
GblStringRef * pError
Pending error message.
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...